showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import common |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 4 | import unittest |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 5 | from autotest_lib.frontend import setup_django_environment |
| 6 | from autotest_lib.frontend import setup_test_environment |
| 7 | from django.test import client |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 8 | from autotest_lib.frontend.shared import resource_test_utils |
| 9 | from autotest_lib.frontend.afe import control_file, models, model_attributes |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 10 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 11 | class AfeResourceTestCase(resource_test_utils.ResourceTestCase): |
showard | f46ad4c | 2010-02-03 20:28:59 +0000 | [diff] [blame] | 12 | URI_PREFIX = 'http://testserver/afe/server/resources' |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 13 | |
| 14 | CONTROL_FILE_CONTENTS = 'my control file contents' |
| 15 | |
| 16 | def setUp(self): |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 17 | super(AfeResourceTestCase, self).setUp() |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 18 | self._add_additional_data() |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 19 | |
| 20 | |
| 21 | def _add_additional_data(self): |
| 22 | models.Test.objects.create(name='mytest', |
jamesren | dd85524 | 2010-03-02 22:23:44 +0000 | [diff] [blame] | 23 | test_type=model_attributes.TestTypes.SERVER, |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 24 | path='/path/to/mytest') |
| 25 | |
| 26 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 27 | class FilteringPagingTest(AfeResourceTestCase): |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 28 | # we'll arbitarily choose to use hosts for this |
| 29 | |
| 30 | def setUp(self): |
| 31 | super(FilteringPagingTest, self).setUp() |
| 32 | |
| 33 | self.labels[0].host_set = [self.hosts[0], self.hosts[1]] |
| 34 | for host in self.hosts[:3]: |
| 35 | host.locked = True |
| 36 | host.save() |
| 37 | |
| 38 | def test_simple_filtering(self): |
| 39 | response = self.request('get', 'hosts?locked=true&has_label=label1') |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 40 | self.check_collection(response, 'hostname', ['host1', 'host2']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 41 | |
| 42 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 43 | def test_in_filtering(self): |
| 44 | response = self.request('get', 'hosts?hostname:in=host1,host2') |
| 45 | self.check_collection(response, 'hostname', ['host1', 'host2']) |
| 46 | |
| 47 | |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 48 | def test_paging(self): |
| 49 | response = self.request('get', 'hosts?start_index=1&items_per_page=2') |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 50 | self.check_collection(response, 'hostname', ['host2', 'host3']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 51 | self.assertEquals(response['total_results'], 9) |
| 52 | self.assertEquals(response['items_per_page'], 2) |
| 53 | self.assertEquals(response['start_index'], 1) |
| 54 | |
| 55 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 56 | def test_full_representations(self): |
| 57 | response = self.request( |
| 58 | 'get', 'hosts?hostname=host1&full_representations=true') |
| 59 | self.check_collection(response, 'hostname', ['host1']) |
| 60 | host = response['members'][0] |
| 61 | # invalid only included in full representation |
| 62 | self.assertEquals(host['invalid'], False) |
| 63 | |
| 64 | |
| 65 | class MiscellaneousTest(AfeResourceTestCase): |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 66 | def test_trailing_slash(self): |
| 67 | response = self.request('get', 'hosts/host1/') |
| 68 | self.assertEquals(response['hostname'], 'host1') |
| 69 | |
| 70 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 71 | class AtomicGroupClassTest(AfeResourceTestCase): |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 72 | def test_collection(self): |
| 73 | response = self.request('get', 'atomic_group_classes') |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 74 | self.check_collection(response, 'name', ['atomic1', 'atomic2'], |
| 75 | length=2) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | def test_entry(self): |
| 79 | response = self.request('get', 'atomic_group_classes/atomic1') |
| 80 | self.assertEquals(response['name'], 'atomic1') |
| 81 | self.assertEquals(response['max_number_of_machines'], 2) |
| 82 | |
| 83 | |
| 84 | def test_labels(self): |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 85 | self.check_relationship('atomic_group_classes/atomic1', 'labels', |
| 86 | 'label', 'name', ['label4', 'label5']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 87 | |
| 88 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 89 | class LabelTest(AfeResourceTestCase): |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 90 | def test_collection(self): |
| 91 | response = self.request('get', 'labels') |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 92 | self.check_collection(response, 'name', ['label1', 'label2'], length=9, |
| 93 | check_number=2) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 94 | label1 = self.sorted_by(response['members'], 'name')[0] |
| 95 | self.assertEquals(label1['is_platform'], False) |
| 96 | |
| 97 | |
| 98 | def test_entry(self): |
| 99 | response = self.request('get', 'labels/label1') |
| 100 | self.assertEquals(response['name'], 'label1') |
| 101 | self.assertEquals(response['is_platform'], False) |
| 102 | self.assertEquals(response['atomic_group_class'], None) |
| 103 | |
| 104 | |
| 105 | def test_hosts(self): |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 106 | self.check_relationship('labels/label1', 'hosts', 'host', 'hostname', |
| 107 | ['host1']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 108 | |
| 109 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 110 | class UserTest(AfeResourceTestCase): |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 111 | def test_collection(self): |
| 112 | response = self.request('get', 'users') |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 113 | self.check_collection(response, 'username', |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 114 | ['autotest_system', 'debug_user']) |
| 115 | |
| 116 | |
| 117 | def test_entry(self): |
| 118 | response = self.request('get', 'users/debug_user') |
| 119 | self.assertEquals(response['username'], 'debug_user') |
| 120 | |
| 121 | me_response = self.request('get', 'users/@me') |
| 122 | self.assertEquals(response, me_response) |
| 123 | |
| 124 | |
| 125 | def test_acls(self): |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 126 | self.check_relationship('users/debug_user', 'acls', 'acl', 'name', |
| 127 | ['Everyone', 'my_acl']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 128 | |
| 129 | |
| 130 | def test_accessible_hosts(self): |
| 131 | group = models.AclGroup.objects.create(name='mygroup') |
| 132 | models.User.objects.get(login='debug_user').aclgroup_set = [group] |
| 133 | self.hosts[0].aclgroup_set = [group] |
| 134 | |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 135 | user = self.request('get', 'users/debug_user') |
| 136 | response = self.request('get', user['accessible_hosts']['href']) |
| 137 | self.check_collection(response, 'hostname', ['host1']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 138 | |
| 139 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 140 | class AclTest(AfeResourceTestCase): |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 141 | def test_collection(self): |
| 142 | response = self.request('get', 'acls') |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 143 | self.check_collection(response, 'name', ['Everyone', 'my_acl']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 144 | |
| 145 | |
| 146 | def test_entry(self): |
| 147 | response = self.request('get', 'acls/my_acl') |
| 148 | self.assertEquals(response['name'], 'my_acl') |
| 149 | |
| 150 | |
| 151 | def test_users(self): |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 152 | self.check_relationship('acls/my_acl', 'users', 'user', 'username', |
| 153 | ['autotest_system', 'debug_user']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 154 | |
| 155 | |
| 156 | def test_hosts(self): |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 157 | self.check_relationship('acls/my_acl', 'hosts', 'host', 'hostname', |
| 158 | ['host1', 'host2'], length=9, check_number=2) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 159 | |
| 160 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 161 | class HostTest(AfeResourceTestCase): |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 162 | def test_collection(self): |
| 163 | response = self.request('get', 'hosts') |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 164 | self.check_collection(response, 'hostname', ['host1', 'host2'], |
| 165 | length=9, check_number=2) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 166 | host1 = self.sorted_by(response['members'], 'hostname')[0] |
| 167 | self.assertEquals(host1['platform']['name'], 'myplatform') |
| 168 | self.assertEquals(host1['locked'], False) |
| 169 | self.assertEquals(host1['status'], 'Ready') |
| 170 | |
| 171 | |
| 172 | def test_entry(self): |
| 173 | response = self.request('get', 'hosts/host1') |
| 174 | self.assertEquals(response['protection_level'], 'No protection') |
| 175 | |
| 176 | |
| 177 | def test_labels(self): |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 178 | self.check_relationship('hosts/host1', 'labels', 'label', 'name', |
| 179 | ['label1', 'myplatform']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 180 | |
| 181 | |
| 182 | def test_acls(self): |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 183 | self.check_relationship('hosts/host1', 'acls', 'acl', 'name', |
| 184 | ['my_acl']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 185 | |
| 186 | |
| 187 | def test_queue_entries(self): |
| 188 | self._create_job(hosts=[1]) |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 189 | host = self.request('get', 'hosts/host1') |
| 190 | entries = self.request('get', host['queue_entries']['href']) |
| 191 | self.check_collection(entries, ['job', 'id'], [1]) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 192 | |
| 193 | |
| 194 | def test_health_tasks(self): |
| 195 | models.SpecialTask.schedule_special_task( |
| 196 | host=self.hosts[0], task=models.SpecialTask.Task.VERIFY) |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 197 | host = self.request('get', 'hosts/host1') |
| 198 | tasks = self.request('get', host['health_tasks']['href']) |
| 199 | self.check_collection(tasks, 'task_type', ['Verify']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 200 | |
| 201 | |
| 202 | def test_put(self): |
| 203 | response = self.request('put', 'hosts/host1', data={'locked': True}) |
| 204 | self.assertEquals(response['locked'], True) |
| 205 | response = self.request('get', 'hosts/host1') |
| 206 | self.assertEquals(response['locked'], True) |
| 207 | self.assertEquals(response['locked_by']['username'], 'debug_user') |
| 208 | |
| 209 | |
| 210 | def test_post(self): |
| 211 | data = {'hostname': 'newhost', |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 212 | 'platform': {'href': self.URI_PREFIX + '/labels/myplatform'}, |
| 213 | 'protection_level': 'Do not verify'} |
| 214 | response = self.request('post', 'hosts', data=data) |
| 215 | self.assertEquals(response, self.URI_PREFIX + '/hosts/newhost') |
| 216 | |
| 217 | host = models.Host.objects.get(hostname='newhost') |
| 218 | self.assertEquals(host.platform().name, 'myplatform') |
| 219 | self.assertEquals(host.protection, models.Host.Protection.DO_NOT_VERIFY) |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 220 | |
| 221 | |
| 222 | def _check_labels(self, host, expected_labels): |
| 223 | label_names = sorted(label.name for label in host.labels.all()) |
| 224 | self.assertEquals(label_names, sorted(expected_labels)) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 225 | |
| 226 | |
| 227 | def test_add_label(self): |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 228 | labels_href = self.request('get', 'hosts/host1')['labels']['href'] |
| 229 | data = {'label': self.URI_PREFIX + '/labels/label2'} |
| 230 | response = self.request('post', labels_href, data=data) |
| 231 | self._check_labels(self.hosts[0], ['label1', 'label2', 'myplatform']) |
| 232 | |
| 233 | |
| 234 | def test_remove_label(self): |
| 235 | labels_href = self.request('get', 'hosts/host1')['labels']['href'] |
| 236 | labels_href += '&label=label1' |
| 237 | labelings = self.request('get', labels_href)['members'] |
| 238 | self.assertEquals(len(labelings), 1) |
| 239 | self.request('delete', labelings[0]['href']) |
| 240 | self._check_labels(self.hosts[0], ['myplatform']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 241 | |
| 242 | |
| 243 | def test_delete(self): |
| 244 | self.request('delete', 'hosts/host1') |
| 245 | hosts = models.Host.valid_objects.filter(hostname='host1') |
| 246 | self.assertEquals(len(hosts), 0) |
| 247 | |
| 248 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 249 | class TestTest(AfeResourceTestCase): # yes, we're testing the "tests" resource |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 250 | def test_collection(self): |
| 251 | response = self.request('get', 'tests') |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 252 | self.check_collection(response, 'name', ['mytest']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 253 | |
| 254 | |
| 255 | def test_entry(self): |
| 256 | response = self.request('get', 'tests/mytest') |
| 257 | self.assertEquals(response['name'], 'mytest') |
| 258 | self.assertEquals(response['control_file_type'], 'Server') |
| 259 | self.assertEquals(response['control_file_path'], '/path/to/mytest') |
| 260 | |
| 261 | |
| 262 | def test_dependencies(self): |
| 263 | models.Test.objects.get(name='mytest').dependency_labels = [self.label3] |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 264 | self.check_relationship('tests/mytest', 'dependencies', 'label', 'name', |
| 265 | ['label3']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 266 | |
| 267 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 268 | class ExecutionInfoTest(AfeResourceTestCase): |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 269 | def setUp(self): |
| 270 | super(ExecutionInfoTest, self).setUp() |
| 271 | |
| 272 | def mock_read_control_file(test): |
| 273 | return self.CONTROL_FILE_CONTENTS |
| 274 | self.god.stub_with(control_file, 'read_control_file', |
| 275 | mock_read_control_file) |
| 276 | def test_get(self): |
| 277 | response = self.request('get', 'execution_info?tests=mytest') |
| 278 | info = response['execution_info'] |
| 279 | self.assert_(self.CONTROL_FILE_CONTENTS in info['control_file']) |
| 280 | self.assertEquals(info['is_server'], True) |
| 281 | self.assertEquals(info['machines_per_execution'], 1) |
| 282 | |
| 283 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 284 | class QueueEntriesRequestTest(AfeResourceTestCase): |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 285 | def test_get(self): |
| 286 | response = self.request( |
| 287 | 'get', |
| 288 | 'queue_entries_request?hosts=host1,host2&meta_hosts=label1') |
| 289 | |
| 290 | # choose an arbitrary but consistent ordering to ease checking |
| 291 | def entry_href(entry): |
| 292 | if 'host' in entry: |
| 293 | return entry['host']['href'] |
| 294 | return entry['meta_host']['href'] |
| 295 | entries = sorted(response['queue_entries'], key=entry_href) |
| 296 | |
| 297 | expected = [ |
| 298 | {'host': {'href': self.URI_PREFIX + '/hosts/host1'}}, |
| 299 | {'host': {'href': self.URI_PREFIX + '/hosts/host2'}}, |
| 300 | {'meta_host': {'href': self.URI_PREFIX + '/labels/label1'}}] |
| 301 | self.assertEquals(entries, expected) |
| 302 | |
| 303 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 304 | class JobTest(AfeResourceTestCase): |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 305 | def setUp(self): |
| 306 | super(JobTest, self).setUp() |
| 307 | |
| 308 | for _ in xrange(2): |
| 309 | self._create_job(hosts=[1, 2]) |
| 310 | |
| 311 | job = models.Job.objects.get(id=1) |
| 312 | job.control_file = self.CONTROL_FILE_CONTENTS |
| 313 | job.save() |
| 314 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 315 | models.JobKeyval.objects.create(job=job, key='mykey', value='myvalue') |
| 316 | |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 317 | |
| 318 | def test_collection(self): |
| 319 | response = self.request('get', 'jobs') |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 320 | self.check_collection(response, 'id', [1, 2]) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 321 | |
| 322 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 323 | def test_keyval_filtering(self): |
| 324 | response = self.request('get', 'jobs?has_keyval=mykey=myvalue') |
| 325 | self.check_collection(response, 'id', [1]) |
| 326 | |
| 327 | |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 328 | def test_entry(self): |
| 329 | response = self.request('get', 'jobs/1') |
| 330 | self.assertEquals(response['id'], 1) |
| 331 | self.assertEquals(response['name'], 'test') |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 332 | self.assertEquals(response['keyvals'], {'mykey': 'myvalue'}) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 333 | info = response['execution_info'] |
| 334 | self.assertEquals(info['control_file'], self.CONTROL_FILE_CONTENTS) |
| 335 | self.assertEquals(info['is_server'], False) |
| 336 | self.assertEquals(info['cleanup_before_job'], 'Never') |
| 337 | self.assertEquals(info['cleanup_after_job'], 'Always') |
| 338 | self.assertEquals(info['machines_per_execution'], 1) |
| 339 | self.assertEquals(info['run_verify'], True) |
| 340 | |
| 341 | |
| 342 | def test_queue_entries(self): |
jamesren | 3981f44 | 2010-02-16 19:27:59 +0000 | [diff] [blame] | 343 | job = self.request('get', 'jobs/1') |
| 344 | entries = self.request('get', job['queue_entries']['href']) |
| 345 | self.check_collection(entries, ['host', 'hostname'], ['host1', 'host2']) |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 346 | |
| 347 | |
jamesren | e38a0a7 | 2010-04-19 18:05:31 +0000 | [diff] [blame] | 348 | def _test_post_helper(self, owner): |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 349 | data = {'name': 'myjob', |
| 350 | 'execution_info': {'control_file': self.CONTROL_FILE_CONTENTS, |
| 351 | 'is_server': True}, |
jamesren | e38a0a7 | 2010-04-19 18:05:31 +0000 | [diff] [blame] | 352 | 'owner': owner, |
jamesren | 76fcf19 | 2010-04-21 20:39:50 +0000 | [diff] [blame] | 353 | 'drone_set': models.DroneSet.default_drone_set_name(), |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 354 | 'queue_entries': |
| 355 | [{'host': {'href': self.URI_PREFIX + '/hosts/host1'}}, |
| 356 | {'host': {'href': self.URI_PREFIX + '/hosts/host2'}}]} |
| 357 | response = self.request('post', 'jobs', data=data) |
| 358 | self.assertEquals(response, self.URI_PREFIX + '/jobs/3') |
| 359 | job = models.Job.objects.get(id=3) |
| 360 | self.assertEquals(job.name, 'myjob') |
| 361 | self.assertEquals(job.control_file, self.CONTROL_FILE_CONTENTS) |
| 362 | self.assertEquals(job.control_type, models.Job.ControlType.SERVER) |
| 363 | entries = job.hostqueueentry_set.order_by('host__hostname') |
| 364 | self.assertEquals(entries[0].host.hostname, 'host1') |
| 365 | self.assertEquals(entries[1].host.hostname, 'host2') |
| 366 | |
jamesren | e38a0a7 | 2010-04-19 18:05:31 +0000 | [diff] [blame] | 367 | owner_test = owner |
| 368 | if not owner_test: |
| 369 | owner_test = models.User.current_user().login |
| 370 | self.assertEquals(job.owner, owner_test) |
| 371 | |
| 372 | |
| 373 | def test_post_no_owner(self): |
| 374 | self._test_post_helper(None) |
| 375 | |
| 376 | |
| 377 | def test_post_with_owner(self): |
| 378 | self._test_post_helper('job_owner') |
| 379 | |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 380 | |
jamesren | cd7a81a | 2010-04-21 20:39:08 +0000 | [diff] [blame] | 381 | class DirectoryTest(AfeResourceTestCase): |
showard | f828c77 | 2010-01-25 21:49:42 +0000 | [diff] [blame] | 382 | def test_get(self): |
| 383 | response = self.request('get', '') |
| 384 | for key in ('atomic_group_classes', 'labels', 'users', 'acl_groups', |
| 385 | 'hosts', 'tests', 'jobs', 'execution_info', |
| 386 | 'queue_entries_request'): |
| 387 | self.assert_(key in response) |
| 388 | |
| 389 | |
| 390 | if __name__ == '__main__': |
| 391 | unittest.main() |