def setUp(self): super(ImageViewTests, self).setUp() image_dict = {'name': 'visibleImage', 'container_format': 'novaImage'} self.visibleImage = api.Image(image_dict) image_dict = {'name': 'invisibleImage', 'container_format': 'aki'} self.invisibleImage = api.Image(image_dict) self.images = (self.visibleImage, self.invisibleImage) flavor = self.mox.CreateMock(api.Flavor) flavor.id = 1 flavor.name = 'm1.massive' flavor.vcpus = 1000 flavor.disk = 1024 flavor.ram = 10000 self.flavors = (flavor, ) keypair = self.mox.CreateMock(api.KeyPair) keypair.name = 'keyName' self.keypairs = (keypair, ) security_group = self.mox.CreateMock(api.SecurityGroup) security_group.name = 'default' self.security_groups = (security_group, )
def test_metadata_download(self): IMAGE_ID = u'1' image_dict = { 'name': 'visibleImage', 'container_format': 'novaImage', 'location': 'swift://localhost/', 'container_format': '', 'disk_format': '', 'size': '', 'image.min_disk': '', 'image.min_ram': '' } image = api.Image(image_dict) self.visibleImage = api.Image(image_dict) self.mox.StubOutWithMock(api, 'image_get_meta') api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(image) self.mox.ReplayAll() res = self.client.get( reverse('dash_metadata_download', args=[self.TEST_TENANT, IMAGE_ID])) #self.assertIn('images', res.context) #images = res.context['images'] #self.assertEqual(len(images), 1) #self.assertEqual(images[0].name, 'visibleImage') self.mox.VerifyAll()
def test_metadata_update_post(self): self.setActiveUser(self.TEST_TOKEN, self.TEST_USER, self.TEST_TENANT) IMAGE_ID = u'1' image_dict = { 'name': 'visibleImage', 'container_format': 'novaImage', 'location': 'swift://localhost/', 'container_format': '', 'disk_format': '', 'image.size': '', 'image.min_disk': '', 'image.min_ram': '' } image = api.Image(image_dict) form_data = { 'method': 'UpdateImageForm', 'name': 'visibleImage', 'image_id': IMAGE_ID, 'location': 'swift://localhost/', 'user': '******', 'password': '******' } self.visibleImage = api.Image(image_dict) self.mox.StubOutWithMock(api, 'image_get_meta') api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(image) self.mox.ReplayAll() res = self.client.post( reverse('dash_metadata_update', args=[self.TEST_TENANT, IMAGE_ID]), form_data) #self.assertIn('images', res.context) #images = res.context['images'] #self.assertEqual(len(images), 1) #self.assertEqual(images[0].name, 'visibleImage') self.mox.VerifyAll()
def test_metadata_download_invalid(self): IMAGE_ID = u'1' image_dict = { 'name': 'visibleImage', 'container_format': 'novaImage', 'location': 'swift://localhost/' } image = api.Image(image_dict) self.visibleImage = api.Image(image_dict) self.mox.StubOutWithMock(api, 'image_get_meta') api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(image) self.mox.ReplayAll() res = self.client.post( reverse('dash_metadata_download', args=[self.TEST_TENANT, IMAGE_ID])) self.assertRedirectsNoFollow( res, reverse('dash_images_metadata', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def test_metadata_upload_post(self): IMAGE_ID = u'1' METADATA_DATA = """ <image type="openstack-glance"> <name>visibleImage</name> <location>swift://localhost/AUTH_test/Cont</location> <format> <disk /> <container /> </format> <size>0</size> <info> <min_disk>0</min_disk> <min_ram>1G</min_ram> <properties /> </info> </image> """ METADATA_FILE = tempfile.TemporaryFile() METADATA_FILE.write(METADATA_DATA) METADATA_FILE.flush() METADATA_FILE.seek(0) image_dict = { 'name': 'visibleImage', 'container_format': 'novaImage', 'location': 'swift://localhost/', 'container_format': '', 'disk_format': '', 'image.size': '', 'image.min_disk': '', 'image.min_ram': '' } form_data = { 'method': 'UploadMetadata', 'image_meta_file': METADATA_FILE } image = api.Image(image_dict) self.visibleImage = api.Image(image_dict) #self.mox.StubOutWithMock(api, 'image_get_meta') #api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(image) self.mox.StubOutWithMock(api, 'token_get_tenant') api.token_get_tenant(IsA(http.HttpRequest), self.TEST_TENANT) self.mox.StubOutWithMock(api, 'image_list_detailed') api.image_list_detailed(IsA(http.HttpRequest)).AndReturn(self.images) self.mox.StubOutWithMock(api, 'image_create') api.image_create(IsA(http.HttpRequest), image, None) self.mox.ReplayAll() res = self.client.post( reverse('dash_images_metadata', args=[self.TEST_TENANT]), form_data) self.assertTemplateUsed( res, 'django_openstack/dash/images_metadata/index.html') #self.assertIn('images', res.context) #images = res.context['images'] #self.assertEqual(len(images), 1) #self.assertEqual(images[0].name, 'visibleImage') self.mox.VerifyAll()