| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2016 The LUCI Authors. All rights reserved. | 2 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """Unit tests for instance_templates.py.""" | 6 """Unit tests for instance_templates.py.""" |
| 7 | 7 |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 import test_env | 10 import test_env |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 ] | 356 ] |
| 357 | 357 |
| 358 actual = instance_templates.get_drained_instance_template_revisions() | 358 actual = instance_templates.get_drained_instance_template_revisions() |
| 359 self.assertItemsEqual(actual, expected) | 359 self.assertItemsEqual(actual, expected) |
| 360 | 360 |
| 361 | 361 |
| 362 class ScheduleCreationTest(test_case.TestCase): | 362 class ScheduleCreationTest(test_case.TestCase): |
| 363 """Tests for instance_templates.schedule_creation.""" | 363 """Tests for instance_templates.schedule_creation.""" |
| 364 | 364 |
| 365 def setUp(self, *args, **kwargs): | 365 def setUp(self, *args, **kwargs): |
| 366 def enqueue_task(*args, **kwargs): | 366 def enqueue_task(taskqueue, key): |
| 367 self.failUnless(kwargs.get('params', {}).get('key')) | 367 entity = key.get() |
| 368 entity = ndb.Key(urlsafe=kwargs['params']['key']).get() | 368 entity.url = key.urlsafe() |
| 369 entity.url = kwargs['params']['key'] | |
| 370 entity.put() | 369 entity.put() |
| 371 return True | 370 return True |
| 372 | 371 |
| 373 super(ScheduleCreationTest, self).setUp(*args, **kwargs) | 372 super(ScheduleCreationTest, self).setUp(*args, **kwargs) |
| 374 self.mock(instance_templates.utils, 'enqueue_task', enqueue_task) | 373 self.mock(instance_templates.utilities, 'enqueue_task', enqueue_task) |
| 375 | 374 |
| 376 def test_enqueues_task(self): | 375 def test_enqueues_task(self): |
| 377 """Ensures a task is enqueued.""" | 376 """Ensures a task is enqueued.""" |
| 378 key = instance_templates.get_instance_template_revision_key( | 377 key = instance_templates.get_instance_template_revision_key( |
| 379 'base-name', 'revision') | 378 'base-name', 'revision') |
| 380 models.InstanceTemplate(key=key.parent(), active=key).put() | 379 models.InstanceTemplate(key=key.parent(), active=key).put() |
| 381 models.InstanceTemplateRevision(key=key).put() | 380 models.InstanceTemplateRevision(key=key).put() |
| 382 expected_url = key.urlsafe() | 381 expected_url = key.urlsafe() |
| 383 | 382 |
| 384 instance_templates.schedule_creation() | 383 instance_templates.schedule_creation() |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 'revision', | 468 'revision', |
| 470 ), | 469 ), |
| 471 ).put() | 470 ).put() |
| 472 | 471 |
| 473 instance_templates.update_url(key, 'url') | 472 instance_templates.update_url(key, 'url') |
| 474 | 473 |
| 475 self.assertEqual(key.get().url, 'url') | 474 self.assertEqual(key.get().url, 'url') |
| 476 | 475 |
| 477 if __name__ == '__main__': | 476 if __name__ == '__main__': |
| 478 unittest.main() | 477 unittest.main() |
| OLD | NEW |