Best Python code snippet using tempest_python
test_clients.py
Source:test_clients.py
...75 super(TestRegistryClient, self).tearDown()76 self.destroy_fixtures()77 def create_fixtures(self):78 for fixture in self.FIXTURES:79 db_api.image_create(self.context, fixture)80 def destroy_fixtures(self):81 # Easiest to just drop the models and re-create them...82 db_models.unregister_models(db_api._ENGINE)83 db_models.register_models(db_api._ENGINE)84 def test_get_image_index(self):85 """Test correct set of public image returned"""86 fixture = {87 'id': UUID2,88 'name': 'fake image #2'89 }90 images = self.client.get_images()91 self.assertEquals(len(images), 1)92 for k, v in fixture.items():93 self.assertEquals(v, images[0][k])94 def test_create_image_with_null_min_disk_min_ram(self):95 UUID3 = _gen_uuid()96 extra_fixture = {97 'id': UUID3,98 'status': 'active',99 'is_public': True,100 'disk_format': 'vhd',101 'container_format': 'ovf',102 'name': 'asdf',103 'size': 19,104 'checksum': None,105 'min_disk': None,106 'min_ram': None,107 }108 db_api.image_create(self.context, extra_fixture)109 image = self.client.get_image(UUID3)110 self.assertEqual(0, image["min_ram"])111 self.assertEqual(0, image["min_disk"])112 def test_get_index_sort_name_asc(self):113 """114 Tests that the /images registry API returns list of115 public images sorted alphabetically by name in116 ascending order.117 """118 UUID3 = _gen_uuid()119 extra_fixture = {'id': UUID3,120 'status': 'active',121 'is_public': True,122 'disk_format': 'vhd',123 'container_format': 'ovf',124 'name': 'asdf',125 'size': 19,126 'checksum': None}127 db_api.image_create(self.context, extra_fixture)128 UUID4 = _gen_uuid()129 extra_fixture = {'id': UUID4,130 'status': 'active',131 'is_public': True,132 'disk_format': 'vhd',133 'container_format': 'ovf',134 'name': 'xyz',135 'size': 20,136 'checksum': None}137 db_api.image_create(self.context, extra_fixture)138 images = self.client.get_images(sort_key='name', sort_dir='asc')139 self.assertEquals(len(images), 3)140 self.assertEquals(images[0]['id'], UUID3)141 self.assertEquals(images[1]['id'], UUID2)142 self.assertEquals(images[2]['id'], UUID4)143 def test_get_index_sort_status_desc(self):144 """145 Tests that the /images registry API returns list of146 public images sorted alphabetically by status in147 descending order.148 """149 UUID3 = _gen_uuid()150 extra_fixture = {'id': UUID3,151 'status': 'queued',152 'is_public': True,153 'disk_format': 'vhd',154 'container_format': 'ovf',155 'name': 'asdf',156 'size': 19,157 'checksum': None}158 db_api.image_create(self.context, extra_fixture)159 UUID4 = _gen_uuid()160 extra_fixture = {'id': UUID4,161 'status': 'active',162 'is_public': True,163 'disk_format': 'vhd',164 'container_format': 'ovf',165 'name': 'xyz',166 'size': 20,167 'checksum': None}168 db_api.image_create(self.context, extra_fixture)169 images = self.client.get_images(sort_key='status', sort_dir='desc')170 self.assertEquals(len(images), 3)171 self.assertEquals(images[0]['id'], UUID3)172 self.assertEquals(images[1]['id'], UUID4)173 self.assertEquals(images[2]['id'], UUID2)174 def test_get_index_sort_disk_format_asc(self):175 """176 Tests that the /images registry API returns list of177 public images sorted alphabetically by disk_format in178 ascending order.179 """180 UUID3 = _gen_uuid()181 extra_fixture = {'id': UUID3,182 'status': 'active',183 'is_public': True,184 'disk_format': 'ami',185 'container_format': 'ami',186 'name': 'asdf',187 'size': 19,188 'checksum': None}189 db_api.image_create(self.context, extra_fixture)190 UUID4 = _gen_uuid()191 extra_fixture = {'id': UUID4,192 'status': 'active',193 'is_public': True,194 'disk_format': 'vdi',195 'container_format': 'ovf',196 'name': 'xyz',197 'size': 20,198 'checksum': None}199 db_api.image_create(self.context, extra_fixture)200 images = self.client.get_images(sort_key='disk_format',201 sort_dir='asc')202 self.assertEquals(len(images), 3)203 self.assertEquals(images[0]['id'], UUID3)204 self.assertEquals(images[1]['id'], UUID4)205 self.assertEquals(images[2]['id'], UUID2)206 def test_get_index_sort_container_format_desc(self):207 """208 Tests that the /images registry API returns list of209 public images sorted alphabetically by container_format in210 descending order.211 """212 UUID3 = _gen_uuid()213 extra_fixture = {'id': UUID3,214 'status': 'active',215 'is_public': True,216 'disk_format': 'ami',217 'container_format': 'ami',218 'name': 'asdf',219 'size': 19,220 'checksum': None}221 db_api.image_create(self.context, extra_fixture)222 UUID4 = _gen_uuid()223 extra_fixture = {'id': UUID4,224 'status': 'active',225 'is_public': True,226 'disk_format': 'iso',227 'container_format': 'bare',228 'name': 'xyz',229 'size': 20,230 'checksum': None}231 db_api.image_create(self.context, extra_fixture)232 images = self.client.get_images(sort_key='container_format',233 sort_dir='desc')234 self.assertEquals(len(images), 3)235 self.assertEquals(images[0]['id'], UUID2)236 self.assertEquals(images[1]['id'], UUID4)237 self.assertEquals(images[2]['id'], UUID3)238 def test_get_index_sort_size_asc(self):239 """240 Tests that the /images registry API returns list of241 public images sorted by size in ascending order.242 """243 UUID3 = _gen_uuid()244 extra_fixture = {'id': UUID3,245 'status': 'active',246 'is_public': True,247 'disk_format': 'ami',248 'container_format': 'ami',249 'name': 'asdf',250 'size': 100,251 'checksum': None}252 db_api.image_create(self.context, extra_fixture)253 UUID4 = _gen_uuid()254 extra_fixture = {'id': UUID4,255 'status': 'active',256 'is_public': True,257 'disk_format': 'iso',258 'container_format': 'bare',259 'name': 'xyz',260 'size': 2,261 'checksum': None}262 db_api.image_create(self.context, extra_fixture)263 images = self.client.get_images(sort_key='size', sort_dir='asc')264 self.assertEquals(len(images), 3)265 self.assertEquals(images[0]['id'], UUID4)266 self.assertEquals(images[1]['id'], UUID2)267 self.assertEquals(images[2]['id'], UUID3)268 def test_get_index_sort_created_at_asc(self):269 """270 Tests that the /images registry API returns list of271 public images sorted by created_at in ascending order.272 """273 now = timeutils.utcnow()274 time1 = now + datetime.timedelta(seconds=5)275 time2 = now276 UUID3 = _gen_uuid()277 extra_fixture = {'id': UUID3,278 'status': 'active',279 'is_public': True,280 'disk_format': 'vhd',281 'container_format': 'ovf',282 'name': 'new name! #123',283 'size': 19,284 'checksum': None,285 'created_at': time1}286 db_api.image_create(self.context, extra_fixture)287 UUID4 = _gen_uuid()288 extra_fixture = {'id': UUID4,289 'status': 'active',290 'is_public': True,291 'disk_format': 'vhd',292 'container_format': 'ovf',293 'name': 'new name! #123',294 'size': 20,295 'checksum': None,296 'created_at': time2}297 db_api.image_create(self.context, extra_fixture)298 images = self.client.get_images(sort_key='created_at', sort_dir='asc')299 self.assertEquals(len(images), 3)300 self.assertEquals(images[0]['id'], UUID2)301 self.assertEquals(images[1]['id'], UUID4)302 self.assertEquals(images[2]['id'], UUID3)303 def test_get_index_sort_updated_at_desc(self):304 """305 Tests that the /images registry API returns list of306 public images sorted by updated_at in descending order.307 """308 now = timeutils.utcnow()309 time1 = now + datetime.timedelta(seconds=5)310 time2 = now311 UUID3 = _gen_uuid()312 extra_fixture = {'id': UUID3,313 'status': 'active',314 'is_public': True,315 'disk_format': 'vhd',316 'container_format': 'ovf',317 'name': 'new name! #123',318 'size': 19,319 'checksum': None,320 'created_at': None,321 'updated_at': time1}322 db_api.image_create(self.context, extra_fixture)323 UUID4 = _gen_uuid()324 extra_fixture = {'id': UUID4,325 'status': 'active',326 'is_public': True,327 'disk_format': 'vhd',328 'container_format': 'ovf',329 'name': 'new name! #123',330 'size': 20,331 'checksum': None,332 'created_at': None,333 'updated_at': time2}334 db_api.image_create(self.context, extra_fixture)335 images = self.client.get_images(sort_key='updated_at', sort_dir='desc')336 self.assertEquals(len(images), 3)337 self.assertEquals(images[0]['id'], UUID3)338 self.assertEquals(images[1]['id'], UUID4)339 self.assertEquals(images[2]['id'], UUID2)340 def test_get_image_index_marker(self):341 """Test correct set of images returned with marker param."""342 UUID3 = _gen_uuid()343 extra_fixture = {'id': UUID3,344 'status': 'saving',345 'is_public': True,346 'disk_format': 'vhd',347 'container_format': 'ovf',348 'name': 'new name! #123',349 'size': 19,350 'checksum': None}351 db_api.image_create(self.context, extra_fixture)352 UUID4 = _gen_uuid()353 extra_fixture = {'id': UUID4,354 'status': 'saving',355 'is_public': True,356 'disk_format': 'vhd',357 'container_format': 'ovf',358 'name': 'new name! #125',359 'size': 19,360 'checksum': None}361 db_api.image_create(self.context, extra_fixture)362 images = self.client.get_images(marker=UUID4)363 self.assertEquals(len(images), 2)364 self.assertEquals(images[0]['id'], UUID3)365 self.assertEquals(images[1]['id'], UUID2)366 def test_get_image_index_invalid_marker(self):367 """Test exception is raised when marker is invalid"""368 self.assertRaises(exception.Invalid,369 self.client.get_images,370 marker=_gen_uuid())371 def test_get_image_index_limit(self):372 """Test correct number of images returned with limit param."""373 extra_fixture = {'id': _gen_uuid(),374 'status': 'saving',375 'is_public': True,376 'disk_format': 'vhd',377 'container_format': 'ovf',378 'name': 'new name! #123',379 'size': 19,380 'checksum': None}381 db_api.image_create(self.context, extra_fixture)382 extra_fixture = {'id': _gen_uuid(),383 'status': 'saving',384 'is_public': True,385 'disk_format': 'vhd',386 'container_format': 'ovf',387 'name': 'new name! #125',388 'size': 19,389 'checksum': None}390 db_api.image_create(self.context, extra_fixture)391 images = self.client.get_images(limit=2)392 self.assertEquals(len(images), 2)393 def test_get_image_index_marker_limit(self):394 """Test correct set of images returned with marker/limit params."""395 UUID3 = _gen_uuid()396 extra_fixture = {'id': UUID3,397 'status': 'saving',398 'is_public': True,399 'disk_format': 'vhd',400 'container_format': 'ovf',401 'name': 'new name! #123',402 'size': 19,403 'checksum': None}404 db_api.image_create(self.context, extra_fixture)405 UUID4 = _gen_uuid()406 extra_fixture = {'id': UUID4,407 'status': 'saving',408 'is_public': True,409 'disk_format': 'vhd',410 'container_format': 'ovf',411 'name': 'new name! #125',412 'size': 19,413 'checksum': None}414 db_api.image_create(self.context, extra_fixture)415 images = self.client.get_images(marker=UUID3, limit=1)416 self.assertEquals(len(images), 1)417 self.assertEquals(images[0]['id'], UUID2)418 def test_get_image_index_limit_None(self):419 """Test correct set of images returned with limit param == None."""420 extra_fixture = {'id': _gen_uuid(),421 'status': 'saving',422 'is_public': True,423 'disk_format': 'vhd',424 'container_format': 'ovf',425 'name': 'new name! #123',426 'size': 19,427 'checksum': None}428 db_api.image_create(self.context, extra_fixture)429 extra_fixture = {'id': _gen_uuid(),430 'status': 'saving',431 'is_public': True,432 'disk_format': 'vhd',433 'container_format': 'ovf',434 'name': 'new name! #125',435 'size': 19,436 'checksum': None}437 db_api.image_create(self.context, extra_fixture)438 images = self.client.get_images(limit=None)439 self.assertEquals(len(images), 3)440 def test_get_image_index_by_name(self):441 """442 Test correct set of public, name-filtered image returned. This443 is just a sanity check, we test the details call more in-depth.444 """445 extra_fixture = {'id': _gen_uuid(),446 'status': 'active',447 'is_public': True,448 'disk_format': 'vhd',449 'container_format': 'ovf',450 'name': 'new name! #123',451 'size': 19,452 'checksum': None}453 db_api.image_create(self.context, extra_fixture)454 images = self.client.get_images(filters={'name': 'new name! #123'})455 self.assertEquals(len(images), 1)456 for image in images:457 self.assertEquals('new name! #123', image['name'])458 def test_get_image_details(self):459 """Tests that the detailed info about public images returned"""460 fixture = {'id': UUID2,461 'name': 'fake image #2',462 'is_public': True,463 'disk_format': 'vhd',464 'container_format': 'ovf',465 'status': 'active',466 'size': 19,467 'properties': {}}468 images = self.client.get_images_detailed()469 self.assertEquals(len(images), 1)470 for k, v in fixture.items():471 self.assertEquals(v, images[0][k])472 def test_get_image_details_marker_limit(self):473 """Test correct set of images returned with marker/limit params."""474 UUID3 = _gen_uuid()475 extra_fixture = {'id': UUID3,476 'status': 'saving',477 'is_public': True,478 'disk_format': 'vhd',479 'container_format': 'ovf',480 'name': 'new name! #123',481 'size': 19,482 'checksum': None}483 db_api.image_create(self.context, extra_fixture)484 extra_fixture = {'id': _gen_uuid(),485 'status': 'saving',486 'is_public': True,487 'disk_format': 'vhd',488 'container_format': 'ovf',489 'name': 'new name! #125',490 'size': 19,491 'checksum': None}492 db_api.image_create(self.context, extra_fixture)493 images = self.client.get_images_detailed(marker=UUID3, limit=1)494 self.assertEquals(len(images), 1)495 self.assertEquals(images[0]['id'], UUID2)496 def test_get_image_details_invalid_marker(self):497 """Test exception is raised when marker is invalid"""498 self.assertRaises(exception.Invalid,499 self.client.get_images_detailed,500 marker=_gen_uuid())501 def test_get_image_details_by_name(self):502 """Tests that a detailed call can be filtered by name"""503 extra_fixture = {'id': _gen_uuid(),504 'status': 'active',505 'is_public': True,506 'disk_format': 'vhd',507 'container_format': 'ovf',508 'name': 'new name! #123',509 'size': 19,510 'checksum': None}511 db_api.image_create(self.context, extra_fixture)512 filters = {'name': 'new name! #123'}513 images = self.client.get_images_detailed(filters=filters)514 self.assertEquals(len(images), 1)515 for image in images:516 self.assertEquals('new name! #123', image['name'])517 def test_get_image_details_by_status(self):518 """Tests that a detailed call can be filtered by status"""519 extra_fixture = {'id': _gen_uuid(),520 'status': 'saving',521 'is_public': True,522 'disk_format': 'vhd',523 'container_format': 'ovf',524 'name': 'new name! #123',525 'size': 19,526 'checksum': None}527 db_api.image_create(self.context, extra_fixture)528 images = self.client.get_images_detailed(filters={'status': 'saving'})529 self.assertEquals(len(images), 1)530 for image in images:531 self.assertEquals('saving', image['status'])532 def test_get_image_details_by_container_format(self):533 """Tests that a detailed call can be filtered by container_format"""534 extra_fixture = {'id': _gen_uuid(),535 'status': 'saving',536 'is_public': True,537 'disk_format': 'vhd',538 'container_format': 'ovf',539 'name': 'new name! #123',540 'size': 19,541 'checksum': None}542 db_api.image_create(self.context, extra_fixture)543 filters = {'container_format': 'ovf'}544 images = self.client.get_images_detailed(filters=filters)545 self.assertEquals(len(images), 2)546 for image in images:547 self.assertEquals('ovf', image['container_format'])548 def test_get_image_details_by_disk_format(self):549 """Tests that a detailed call can be filtered by disk_format"""550 extra_fixture = {'id': _gen_uuid(),551 'status': 'saving',552 'is_public': True,553 'disk_format': 'vhd',554 'container_format': 'ovf',555 'name': 'new name! #123',556 'size': 19,557 'checksum': None}558 db_api.image_create(self.context, extra_fixture)559 filters = {'disk_format': 'vhd'}560 images = self.client.get_images_detailed(filters=filters)561 self.assertEquals(len(images), 2)562 for image in images:563 self.assertEquals('vhd', image['disk_format'])564 def test_get_image_details_with_maximum_size(self):565 """Tests that a detailed call can be filtered by size_max"""566 extra_fixture = {'id': _gen_uuid(),567 'status': 'saving',568 'is_public': True,569 'disk_format': 'vhd',570 'container_format': 'ovf',571 'name': 'new name! #123',572 'size': 21,573 'checksum': None}574 db_api.image_create(self.context, extra_fixture)575 images = self.client.get_images_detailed(filters={'size_max': 20})576 self.assertEquals(len(images), 1)577 for image in images:578 self.assertTrue(image['size'] <= 20)579 def test_get_image_details_with_minimum_size(self):580 """Tests that a detailed call can be filtered by size_min"""581 extra_fixture = {'id': _gen_uuid(),582 'status': 'saving',583 'is_public': True,584 'disk_format': 'vhd',585 'container_format': 'ovf',586 'name': 'new name! #123',587 'size': 20,588 'checksum': None}589 db_api.image_create(self.context, extra_fixture)590 images = self.client.get_images_detailed(filters={'size_min': 20})591 self.assertEquals(len(images), 1)592 for image in images:593 self.assertTrue(image['size'] >= 20)594 def test_get_image_details_with_changes_since(self):595 """Tests that a detailed call can be filtered by size_min"""596 dt1 = timeutils.utcnow() - datetime.timedelta(1)597 iso1 = timeutils.isotime(dt1)598 dt2 = timeutils.utcnow() + datetime.timedelta(1)599 iso2 = timeutils.isotime(dt2)600 dt3 = timeutils.utcnow() + datetime.timedelta(2)601 iso3 = timeutils.isotime(dt3)602 dt4 = timeutils.utcnow() + datetime.timedelta(3)603 iso4 = timeutils.isotime(dt4)604 UUID3 = _gen_uuid()605 extra_fixture = {'id': UUID3,606 'status': 'active',607 'is_public': True,608 'disk_format': 'vhd',609 'container_format': 'ovf',610 'name': 'fake image #3',611 'size': 18,612 'checksum': None}613 db_api.image_create(self.context, extra_fixture)614 db_api.image_destroy(self.context, 3)615 UUID4 = _gen_uuid()616 extra_fixture = {'id': UUID4,617 'status': 'active',618 'is_public': True,619 'disk_format': 'ami',620 'container_format': 'ami',621 'name': 'fake image #4',622 'size': 20,623 'checksum': None,624 'created_at': dt3,625 'updated_at': dt3}626 db_api.image_create(self.context, extra_fixture)627 # Check a standard list, 4 images in db (2 deleted)628 images = self.client.get_images_detailed(filters={})629 self.assertEqual(images[0]['id'], UUID4)630 self.assertEqual(images[1]['id'], UUID2)631 # Expect 3 images (1 deleted)632 filters = {'changes-since': iso1}633 images = self.client.get_images(filters=filters)634 self.assertEquals(len(images), 3)635 self.assertEqual(images[0]['id'], UUID4)636 self.assertEqual(images[1]['id'], UUID3) # deleted637 self.assertEqual(images[2]['id'], UUID2)638 # Expect 1 images (0 deleted)639 filters = {'changes-since': iso2}640 images = self.client.get_images_detailed(filters=filters)641 self.assertEquals(len(images), 1)642 self.assertEqual(images[0]['id'], UUID4)643 # Expect 0 images (0 deleted)644 filters = {'changes-since': iso4}645 images = self.client.get_images(filters=filters)646 self.assertEquals(len(images), 0)647 def test_get_image_details_with_changes_since(self):648 """Tests that a detailed call can be filtered by changes-since"""649 extra_fixture = {'id': _gen_uuid(),650 'status': 'saving',651 'is_public': True,652 'disk_format': 'vhd',653 'container_format': 'ovf',654 'name': 'new name! #123',655 'size': 20,656 'checksum': None}657 db_api.image_create(self.context, extra_fixture)658 images = self.client.get_images_detailed(filters={'size_min': 20})659 self.assertEquals(len(images), 1)660 for image in images:661 self.assertTrue(image['size'] >= 20)662 def test_get_image_details_by_property(self):663 """Tests that a detailed call can be filtered by a property"""664 extra_fixture = {'id': _gen_uuid(),665 'status': 'saving',666 'is_public': True,667 'disk_format': 'vhd',668 'container_format': 'ovf',669 'name': 'new name! #123',670 'size': 19,671 'checksum': None,672 'properties': {'p a': 'v a'}}673 db_api.image_create(self.context, extra_fixture)674 filters = {'property-p a': 'v a'}675 images = self.client.get_images_detailed(filters=filters)676 self.assertEquals(len(images), 1)677 for image in images:678 self.assertEquals('v a', image['properties']['p a'])679 def test_get_image_details_sort_disk_format_asc(self):680 """681 Tests that a detailed call returns list of682 public images sorted alphabetically by disk_format in683 ascending order.684 """685 UUID3 = _gen_uuid()686 extra_fixture = {'id': UUID3,687 'status': 'active',688 'is_public': True,689 'disk_format': 'ami',690 'container_format': 'ami',691 'name': 'asdf',692 'size': 19,693 'checksum': None}694 db_api.image_create(self.context, extra_fixture)695 UUID4 = _gen_uuid()696 extra_fixture = {'id': UUID4,697 'status': 'active',698 'is_public': True,699 'disk_format': 'vdi',700 'container_format': 'ovf',701 'name': 'xyz',702 'size': 20,703 'checksum': None}704 db_api.image_create(self.context, extra_fixture)705 images = self.client.get_images_detailed(sort_key='disk_format',706 sort_dir='asc')707 self.assertEquals(len(images), 3)708 self.assertEquals(images[0]['id'], UUID3)709 self.assertEquals(images[1]['id'], UUID4)710 self.assertEquals(images[2]['id'], UUID2)711 def test_get_image(self):712 """Tests that the detailed info about an image returned"""713 fixture = {'id': UUID1,714 'name': 'fake image #1',715 'is_public': False,716 'disk_format': 'ami',717 'container_format': 'ami',718 'status': 'active',...
test_registry_client.py
Source:test_registry_client.py
...75 self.assertEqual(v, images[0][k])76 def test_create_image_with_null_min_disk_min_ram(self):77 UUID3 = _gen_uuid()78 extra_fixture = self.get_fixture(id=UUID3, min_disk=None, min_ram=None)79 db_api.image_create(self.context, extra_fixture)80 image = self.client.get_image(UUID3)81 self.assertEqual(0, image["min_ram"])82 self.assertEqual(0, image["min_disk"])83 def test_get_index_sort_name_asc(self):84 """85 Tests that the /images registry API returns list of86 public images sorted alphabetically by name in87 ascending order.88 """89 UUID3 = _gen_uuid()90 extra_fixture = self.get_fixture(id=UUID3, name='asdf')91 db_api.image_create(self.context, extra_fixture)92 UUID4 = _gen_uuid()93 extra_fixture = self.get_fixture(id=UUID4, name='xyz')94 db_api.image_create(self.context, extra_fixture)95 images = self.client.get_images(sort_key='name', sort_dir='asc')96 self.assertEqualImages(images, (UUID3, UUID2, UUID4), unjsonify=False)97 def test_get_index_sort_status_desc(self):98 """99 Tests that the /images registry API returns list of100 public images sorted alphabetically by status in101 descending order.102 """103 UUID3 = _gen_uuid()104 extra_fixture = self.get_fixture(id=UUID3, name='asdf',105 status='queued')106 db_api.image_create(self.context, extra_fixture)107 UUID4 = _gen_uuid()108 extra_fixture = self.get_fixture(id=UUID4, name='xyz')109 db_api.image_create(self.context, extra_fixture)110 images = self.client.get_images(sort_key='status', sort_dir='desc')111 self.assertEqualImages(images, (UUID3, UUID4, UUID2), unjsonify=False)112 def test_get_index_sort_disk_format_asc(self):113 """114 Tests that the /images registry API returns list of115 public images sorted alphabetically by disk_format in116 ascending order.117 """118 UUID3 = _gen_uuid()119 extra_fixture = self.get_fixture(id=UUID3, name='asdf',120 disk_format='ami',121 container_format='ami')122 db_api.image_create(self.context, extra_fixture)123 UUID4 = _gen_uuid()124 extra_fixture = self.get_fixture(id=UUID4, name='xyz',125 disk_format='vdi')126 db_api.image_create(self.context, extra_fixture)127 images = self.client.get_images(sort_key='disk_format',128 sort_dir='asc')129 self.assertEqualImages(images, (UUID3, UUID4, UUID2), unjsonify=False)130 def test_get_index_sort_container_format_desc(self):131 """132 Tests that the /images registry API returns list of133 public images sorted alphabetically by container_format in134 descending order.135 """136 UUID3 = _gen_uuid()137 extra_fixture = self.get_fixture(id=UUID3, name='asdf',138 disk_format='ami',139 container_format='ami')140 db_api.image_create(self.context, extra_fixture)141 UUID4 = _gen_uuid()142 extra_fixture = self.get_fixture(id=UUID4, name='xyz',143 disk_format='iso',144 container_format='bare')145 db_api.image_create(self.context, extra_fixture)146 images = self.client.get_images(sort_key='container_format',147 sort_dir='desc')148 self.assertEqualImages(images, (UUID2, UUID4, UUID3), unjsonify=False)149 def test_get_index_sort_size_asc(self):150 """151 Tests that the /images registry API returns list of152 public images sorted by size in ascending order.153 """154 UUID3 = _gen_uuid()155 extra_fixture = self.get_fixture(id=UUID3, name='asdf',156 disk_format='ami',157 container_format='ami', size=100)158 db_api.image_create(self.context, extra_fixture)159 UUID4 = _gen_uuid()160 extra_fixture = self.get_fixture(id=UUID4, name='asdf',161 disk_format='iso',162 container_format='bare', size=2)163 db_api.image_create(self.context, extra_fixture)164 images = self.client.get_images(sort_key='size', sort_dir='asc')165 self.assertEqualImages(images, (UUID4, UUID2, UUID3), unjsonify=False)166 def test_get_index_sort_created_at_asc(self):167 """168 Tests that the /images registry API returns list of169 public images sorted by created_at in ascending order.170 """171 now = timeutils.utcnow()172 time1 = now + datetime.timedelta(seconds=5)173 time2 = now174 UUID3 = _gen_uuid()175 extra_fixture = self.get_fixture(id=UUID3, created_at=time1)176 db_api.image_create(self.context, extra_fixture)177 UUID4 = _gen_uuid()178 extra_fixture = self.get_fixture(id=UUID4, created_at=time2)179 db_api.image_create(self.context, extra_fixture)180 images = self.client.get_images(sort_key='created_at', sort_dir='asc')181 self.assertEqualImages(images, (UUID2, UUID4, UUID3), unjsonify=False)182 def test_get_index_sort_updated_at_desc(self):183 """184 Tests that the /images registry API returns list of185 public images sorted by updated_at in descending order.186 """187 now = timeutils.utcnow()188 time1 = now + datetime.timedelta(seconds=5)189 time2 = now190 UUID3 = _gen_uuid()191 extra_fixture = self.get_fixture(id=UUID3, created_at=None,192 updated_at=time1)193 db_api.image_create(self.context, extra_fixture)194 UUID4 = _gen_uuid()195 extra_fixture = self.get_fixture(id=UUID4, created_at=None,196 updated_at=time2)197 db_api.image_create(self.context, extra_fixture)198 images = self.client.get_images(sort_key='updated_at', sort_dir='desc')199 self.assertEqualImages(images, (UUID3, UUID4, UUID2), unjsonify=False)200 def test_get_image_index_marker(self):201 """Test correct set of images returned with marker param."""202 UUID3 = _gen_uuid()203 extra_fixture = self.get_fixture(id=UUID3, name='new name! #123',204 status='saving')205 db_api.image_create(self.context, extra_fixture)206 UUID4 = _gen_uuid()207 extra_fixture = self.get_fixture(id=UUID4, name='new name! #125',208 status='saving')209 db_api.image_create(self.context, extra_fixture)210 images = self.client.get_images(marker=UUID4)211 self.assertEqualImages(images, (UUID3, UUID2), unjsonify=False)212 def test_get_image_index_invalid_marker(self):213 """Test exception is raised when marker is invalid"""214 self.assertRaises(exception.Invalid,215 self.client.get_images,216 marker=_gen_uuid())217 def test_get_image_index_forbidden_marker(self):218 """Test exception is raised when marker is forbidden"""219 UUID5 = _gen_uuid()220 extra_fixture = self.get_fixture(id=UUID5, owner='0123',221 status='saving', is_public=False)222 db_api.image_create(self.context, extra_fixture)223 def non_admin_get_images(self, context, *args, **kwargs):224 """Convert to non-admin context"""225 context.is_admin = False226 rcontroller.__get_images(self, context, *args, **kwargs)227 rcontroller.__get_images = rcontroller._get_images228 self.stubs.Set(rcontroller, '_get_images', non_admin_get_images)229 self.assertRaises(exception.Invalid,230 self.client.get_images,231 marker=UUID5)232 def test_get_image_index_private_marker(self):233 """Test exception is not raised if private non-owned marker is used"""234 UUID4 = _gen_uuid()235 extra_fixture = self.get_fixture(id=UUID4, owner='1234',236 status='saving', is_public=False)237 db_api.image_create(self.context, extra_fixture)238 try:239 self.client.get_images(marker=UUID4)240 except Exception as e:241 self.fail("Unexpected exception '%s'" % e)242 def test_get_image_index_limit(self):243 """Test correct number of images returned with limit param."""244 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving')245 db_api.image_create(self.context, extra_fixture)246 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving')247 db_api.image_create(self.context, extra_fixture)248 images = self.client.get_images(limit=2)249 self.assertEqual(2, len(images))250 def test_get_image_index_marker_limit(self):251 """Test correct set of images returned with marker/limit params."""252 UUID3 = _gen_uuid()253 extra_fixture = self.get_fixture(id=UUID3, name='new name! #123',254 status='saving')255 db_api.image_create(self.context, extra_fixture)256 UUID4 = _gen_uuid()257 extra_fixture = self.get_fixture(id=UUID4, name='new name! #125',258 status='saving')259 db_api.image_create(self.context, extra_fixture)260 images = self.client.get_images(marker=UUID3, limit=1)261 self.assertEqualImages(images, (UUID2,), unjsonify=False)262 def test_get_image_index_limit_None(self):263 """Test correct set of images returned with limit param == None."""264 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving')265 db_api.image_create(self.context, extra_fixture)266 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving')267 db_api.image_create(self.context, extra_fixture)268 images = self.client.get_images(limit=None)269 self.assertEqual(3, len(images))270 def test_get_image_index_by_name(self):271 """272 Test correct set of public, name-filtered image returned. This273 is just a sanity check, we test the details call more in-depth.274 """275 extra_fixture = self.get_fixture(id=_gen_uuid(), name='new name! #123')276 db_api.image_create(self.context, extra_fixture)277 images = self.client.get_images(filters={'name': 'new name! #123'})278 self.assertEqual(1, len(images))279 for image in images:280 self.assertEqual('new name! #123', image['name'])281 def test_get_image_details(self):282 """Tests that the detailed info about public images returned"""283 fixture = self.get_fixture(id=UUID2, name='fake image #2',284 properties={}, size=19, is_public=True)285 images = self.client.get_images_detailed()286 self.assertEqual(1, len(images))287 for k, v in fixture.items():288 self.assertEqual(v, images[0][k])289 def test_get_image_details_marker_limit(self):290 """Test correct set of images returned with marker/limit params."""291 UUID3 = _gen_uuid()292 extra_fixture = self.get_fixture(id=UUID3, status='saving')293 db_api.image_create(self.context, extra_fixture)294 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving')295 db_api.image_create(self.context, extra_fixture)296 images = self.client.get_images_detailed(marker=UUID3, limit=1)297 self.assertEqualImages(images, (UUID2,), unjsonify=False)298 def test_get_image_details_invalid_marker(self):299 """Test exception is raised when marker is invalid"""300 self.assertRaises(exception.Invalid,301 self.client.get_images_detailed,302 marker=_gen_uuid())303 def test_get_image_details_forbidden_marker(self):304 """Test exception is raised when marker is forbidden"""305 UUID5 = _gen_uuid()306 extra_fixture = self.get_fixture(id=UUID5, is_public=False,307 owner='0123', status='saving')308 db_api.image_create(self.context, extra_fixture)309 def non_admin_get_images(self, context, *args, **kwargs):310 """Convert to non-admin context"""311 context.is_admin = False312 rcontroller.__get_images(self, context, *args, **kwargs)313 rcontroller.__get_images = rcontroller._get_images314 self.stubs.Set(rcontroller, '_get_images', non_admin_get_images)315 self.assertRaises(exception.Invalid,316 self.client.get_images_detailed,317 marker=UUID5)318 def test_get_image_details_private_marker(self):319 """Test exception is not raised if private non-owned marker is used"""320 UUID4 = _gen_uuid()321 extra_fixture = self.get_fixture(id=UUID4, is_public=False,322 owner='1234', status='saving')323 db_api.image_create(self.context, extra_fixture)324 try:325 self.client.get_images_detailed(marker=UUID4)326 except Exception as e:327 self.fail("Unexpected exception '%s'" % e)328 def test_get_image_details_by_name(self):329 """Tests that a detailed call can be filtered by name"""330 extra_fixture = self.get_fixture(id=_gen_uuid(), name='new name! #123')331 db_api.image_create(self.context, extra_fixture)332 filters = {'name': 'new name! #123'}333 images = self.client.get_images_detailed(filters=filters)334 self.assertEqual(1, len(images))335 for image in images:336 self.assertEqual('new name! #123', image['name'])337 def test_get_image_details_by_status(self):338 """Tests that a detailed call can be filtered by status"""339 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving')340 db_api.image_create(self.context, extra_fixture)341 images = self.client.get_images_detailed(filters={'status': 'saving'})342 self.assertEqual(1, len(images))343 for image in images:344 self.assertEqual('saving', image['status'])345 def test_get_image_details_by_container_format(self):346 """Tests that a detailed call can be filtered by container_format"""347 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving')348 db_api.image_create(self.context, extra_fixture)349 filters = {'container_format': 'ovf'}350 images = self.client.get_images_detailed(filters=filters)351 self.assertEqual(2, len(images))352 for image in images:353 self.assertEqual('ovf', image['container_format'])354 def test_get_image_details_by_disk_format(self):355 """Tests that a detailed call can be filtered by disk_format"""356 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving')357 db_api.image_create(self.context, extra_fixture)358 filters = {'disk_format': 'vhd'}359 images = self.client.get_images_detailed(filters=filters)360 self.assertEqual(2, len(images))361 for image in images:362 self.assertEqual('vhd', image['disk_format'])363 def test_get_image_details_with_maximum_size(self):364 """Tests that a detailed call can be filtered by size_max"""365 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving',366 size=21)367 db_api.image_create(self.context, extra_fixture)368 images = self.client.get_images_detailed(filters={'size_max': 20})369 self.assertEqual(1, len(images))370 for image in images:371 self.assertLessEqual(image['size'], 20)372 def test_get_image_details_with_minimum_size(self):373 """Tests that a detailed call can be filtered by size_min"""374 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving')375 db_api.image_create(self.context, extra_fixture)376 images = self.client.get_images_detailed(filters={'size_min': 20})377 self.assertEqual(1, len(images))378 for image in images:379 self.assertGreaterEqual(image['size'], 20)380 def test_get_image_details_with_changes_since(self):381 """Tests that a detailed call can be filtered by changes-since"""382 dt1 = timeutils.utcnow() - datetime.timedelta(1)383 iso1 = timeutils.isotime(dt1)384 dt2 = timeutils.utcnow() + datetime.timedelta(1)385 iso2 = timeutils.isotime(dt2)386 dt3 = timeutils.utcnow() + datetime.timedelta(2)387 dt4 = timeutils.utcnow() + datetime.timedelta(3)388 iso4 = timeutils.isotime(dt4)389 UUID3 = _gen_uuid()390 extra_fixture = self.get_fixture(id=UUID3, name='fake image #3')391 db_api.image_create(self.context, extra_fixture)392 db_api.image_destroy(self.context, UUID3)393 UUID4 = _gen_uuid()394 extra_fixture = self.get_fixture(id=UUID4, name='fake image #4',395 created_at=dt3, updated_at=dt3)396 db_api.image_create(self.context, extra_fixture)397 # Check a standard list, 4 images in db (2 deleted)398 images = self.client.get_images_detailed(filters={})399 self.assertEqualImages(images, (UUID4, UUID2), unjsonify=False)400 # Expect 3 images (1 deleted)401 filters = {'changes-since': iso1}402 images = self.client.get_images(filters=filters)403 self.assertEqualImages(images, (UUID4, UUID3, UUID2), unjsonify=False)404 # Expect 1 images (0 deleted)405 filters = {'changes-since': iso2}406 images = self.client.get_images_detailed(filters=filters)407 self.assertEqualImages(images, (UUID4,), unjsonify=False)408 # Expect 0 images (0 deleted)409 filters = {'changes-since': iso4}410 images = self.client.get_images(filters=filters)411 self.assertEqualImages(images, (), unjsonify=False)412 def test_get_image_details_with_size_min(self):413 """Tests that a detailed call can be filtered by size_min"""414 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving')415 db_api.image_create(self.context, extra_fixture)416 images = self.client.get_images_detailed(filters={'size_min': 20})417 self.assertEqual(1, len(images))418 for image in images:419 self.assertGreaterEqual(image['size'], 20)420 def test_get_image_details_by_property(self):421 """Tests that a detailed call can be filtered by a property"""422 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving',423 properties={'p a': 'v a'})424 db_api.image_create(self.context, extra_fixture)425 filters = {'property-p a': 'v a'}426 images = self.client.get_images_detailed(filters=filters)427 self.assertEqual(1, len(images))428 for image in images:429 self.assertEqual('v a', image['properties']['p a'])430 def test_get_image_is_public_v1(self):431 """Tests that a detailed call can be filtered by a property"""432 extra_fixture = self.get_fixture(id=_gen_uuid(), status='saving',433 properties={'is_public': 'avalue'})434 context = copy.copy(self.context)435 db_api.image_create(context, extra_fixture)436 filters = {'property-is_public': 'avalue'}437 images = self.client.get_images_detailed(filters=filters)438 self.assertEqual(1, len(images))439 for image in images:440 self.assertEqual('avalue', image['properties']['is_public'])441 def test_get_image_details_sort_disk_format_asc(self):442 """443 Tests that a detailed call returns list of444 public images sorted alphabetically by disk_format in445 ascending order.446 """447 UUID3 = _gen_uuid()448 extra_fixture = self.get_fixture(id=UUID3, name='asdf',449 disk_format='ami',450 container_format='ami')451 db_api.image_create(self.context, extra_fixture)452 UUID4 = _gen_uuid()453 extra_fixture = self.get_fixture(id=UUID4, name='xyz',454 disk_format='vdi')455 db_api.image_create(self.context, extra_fixture)456 images = self.client.get_images_detailed(sort_key='disk_format',457 sort_dir='asc')458 self.assertEqualImages(images, (UUID3, UUID4, UUID2), unjsonify=False)459 def test_get_image(self):460 """Tests that the detailed info about an image returned"""461 fixture = self.get_fixture(id=UUID1, name='fake image #1',462 disk_format='ami', container_format='ami',463 is_public=False, size=13,464 properties={'type': 'kernel'})465 data = self.client.get_image(UUID1)466 for k, v in fixture.items():467 el = data[k]468 self.assertEqual(v, data[k],469 "Failed v != data[k] where v = %(v)s and "...
__init__.py
Source:__init__.py
1# coding: utf-82# flake8: noqa3"""4 No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)5 6"""7from __future__ import absolute_import8# import apis into sdk package9from douyin.open.image_create.api.image_api import ImageApi10# import ApiClient11from douyin.open.image_create.api_client import ApiClient12from douyin.open.image_create.configuration import Configuration13# import models into sdk package14from douyin.open.image_create.model.description import Description15from douyin.open.image_create.model.encrypted_item_id import EncryptedItemId16from douyin.open.image_create.model.error_code import ErrorCode17from douyin.open.image_create.model.image_create_body import ImageCreateBody18from douyin.open.image_create.model.image_create_response import ImageCreateResponse19from douyin.open.image_create.model.image_create_response_data import ImageCreateResponseData20from douyin.open.image_create.model.image_upload_body import ImageUploadBody21from douyin.open.image_create.model.image_upload_response import ImageUploadResponse22from douyin.open.image_create.model.image_upload_response_data import ImageUploadResponseData...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!