def test_index(self): instance_id = 'i-abcdefgh' volume = boto.ec2.volume.Volume() volume.id = TEST_VOLUME volume.displayName = TEST_VOLUME volume.size = 1 self.mox.StubOutWithMock(self.project, 'get_volumes') self.mox.StubOutWithMock(forms, 'get_available_volume_choices') self.mox.StubOutWithMock(forms, 'get_instance_choices') self.project.get_volumes().AndReturn([]) forms.get_available_volume_choices(mox.IgnoreArg()).AndReturn( self.create_available_volume_choices([volume])) forms.get_instance_choices(mox.IgnoreArg()).AndReturn( self.create_instance_choices([instance_id])) self.mox.ReplayAll() response = self.client.get(reverse('nova_volumes', args=[TEST_PROJECT])) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'django_nova/volumes/index.html') self.assertEqual(len(response.context['volumes']), 0) self.mox.VerifyAll()
def test_attach_post(self): volume = boto.ec2.volume.Volume() volume.id = TEST_VOLUME volume.displayName = TEST_VOLUME volume.size = 1 instance_id = 'i-abcdefgh' device = '/dev/vdb' self.mox.StubOutWithMock(self.project, 'attach_volume') self.mox.StubOutWithMock(forms, 'get_available_volume_choices') self.mox.StubOutWithMock(forms, 'get_instance_choices') self.project.attach_volume(TEST_VOLUME, instance_id, device) \ .AndReturn(True) forms.get_available_volume_choices(mox.IgnoreArg()).AndReturn( self.create_available_volume_choices([volume])) forms.get_instance_choices(mox.IgnoreArg()).AndReturn( self.create_instance_choices([instance_id])) self.mox.ReplayAll() url = reverse('nova_volumes_attach', args=[TEST_PROJECT]) data = {'volume': TEST_VOLUME, 'instance': instance_id, 'device': device} res = self.client.post(url, data) self.assertRedirectsNoFollow(res, reverse('nova_volumes', args=[TEST_PROJECT])) self.mox.VerifyAll()