示例#1
0
    def test_launch(self):
        instance = boto.ec2.instance.Instance()
        instance.id = TEST_INSTANCE_ID
        instance.image_id = TEST_IMAGE_ID
        reservation = boto.ec2.instance.Reservation()
        reservation.instances = [instance]

        conn = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(forms, 'get_key_pair_choices')
        self.mox.StubOutWithMock(forms, 'get_instance_type_choices')
        self.mox.StubOutWithMock(self.project, 'get_openstack_connection')

        self.project.get_openstack_connection().AndReturn(conn)

        forms.get_key_pair_choices(self.project).AndReturn(
            self.create_key_pair_choices([TEST_KEY]))
        forms.get_instance_type_choices().AndReturn(
            self.create_instance_type_choices())

        params = {
            'addressing_type': 'private',
            'UserData': '',
            'display_name': u'name',
            'MinCount': '1',
            'key_name': TEST_KEY,
            'MaxCount': '1',
            'InstanceType': 'm1.medium',
            'ImageId': TEST_IMAGE_ID
        }
        conn.get_object('RunInstances',
                        params,
                        boto.ec2.instance.Reservation,
                        verb='POST').AndReturn(reservation)

        self.mox.ReplayAll()

        url = reverse('nova_images_launch', args=[TEST_PROJECT, TEST_IMAGE_ID])
        data = {
            'key_name': TEST_KEY,
            'count': '1',
            'size': 'm1.medium',
            'display_name': 'name',
            'user_data': ''
        }
        res = self.client.post(url, data)
        self.assertRedirectsNoFollow(
            res, reverse('nova_instances', args=[TEST_PROJECT]))
        self.mox.VerifyAll()
示例#2
0
    def test_index(self):
        self.mox.StubOutWithMock(self.project, 'get_images')
        self.mox.StubOutWithMock(forms, 'get_key_pair_choices')
        self.mox.StubOutWithMock(forms, 'get_instance_type_choices')

        self.project.get_images().AndReturn([])
        forms.get_key_pair_choices(self.project).AndReturn([])
        forms.get_instance_type_choices().AndReturn([])

        self.mox.ReplayAll()

        res = self.client.get(reverse('nova_images', args=[TEST_PROJECT]))
        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'django_openstack/nova/images/index.html')
        self.assertEqual(len(res.context['image_lists']), 3)

        self.mox.VerifyAll()
示例#3
0
    def test_index(self):
        self.mox.StubOutWithMock(self.project, 'get_images')
        self.mox.StubOutWithMock(forms, 'get_key_pair_choices')
        self.mox.StubOutWithMock(forms, 'get_instance_type_choices')

        self.project.get_images().AndReturn([])
        forms.get_key_pair_choices(self.project).AndReturn([])
        forms.get_instance_type_choices().AndReturn([])

        self.mox.ReplayAll()

        res = self.client.get(reverse('nova_images', args=[TEST_PROJECT]))
        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'django_openstack/nova/images/index.html')
        self.assertEqual(len(res.context['image_lists']), 3)

        self.mox.VerifyAll()
示例#4
0
    def test_launch_form(self):
        self.mox.StubOutWithMock(self.project, 'get_image')
        self.mox.StubOutWithMock(forms, 'get_key_pair_choices')
        self.mox.StubOutWithMock(forms, 'get_instance_type_choices')

        self.project.get_image(TEST_IMAGE_ID).AndReturn(self.ami)
        forms.get_key_pair_choices(self.project).AndReturn([])
        forms.get_instance_type_choices().AndReturn([])

        self.mox.ReplayAll()

        args = [TEST_PROJECT, TEST_IMAGE_ID]
        res = self.client.get(reverse('nova_images_launch', args=args))
        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res,
                'django_openstack/nova/images/launch.html')
        self.assertEqual(res.context['ami'].id, TEST_IMAGE_ID)

        self.mox.VerifyAll()
示例#5
0
    def test_launch_form(self):
        self.mox.StubOutWithMock(self.project, 'get_image')
        self.mox.StubOutWithMock(forms, 'get_key_pair_choices')
        self.mox.StubOutWithMock(forms, 'get_instance_type_choices')

        self.project.get_image(TEST_IMAGE_ID).AndReturn(self.ami)
        forms.get_key_pair_choices(self.project).AndReturn([])
        forms.get_instance_type_choices().AndReturn([])

        self.mox.ReplayAll()

        args = [TEST_PROJECT, TEST_IMAGE_ID]
        res = self.client.get(reverse('nova_images_launch', args=args))
        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res,
                                'django_openstack/nova/images/launch.html')
        self.assertEqual(res.context['ami'].id, TEST_IMAGE_ID)

        self.mox.VerifyAll()
示例#6
0
    def test_launch(self):
        instance = boto.ec2.instance.Instance()
        instance.id = TEST_INSTANCE_ID
        instance.image_id = TEST_IMAGE_ID
        reservation = boto.ec2.instance.Reservation()
        reservation.instances = [instance]

        conn = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(forms, 'get_key_pair_choices')
        self.mox.StubOutWithMock(forms, 'get_instance_type_choices')
        self.mox.StubOutWithMock(self.project, 'get_openstack_connection')

        self.project.get_openstack_connection().AndReturn(conn)

        forms.get_key_pair_choices(self.project).AndReturn(
                self.create_key_pair_choices([TEST_KEY]))
        forms.get_instance_type_choices().AndReturn(
                self.create_instance_type_choices())

        params = {'addressing_type': 'private',
                'UserData': '', 'display_name': u'name',
                'MinCount': '1', 'key_name': TEST_KEY,
                'MaxCount': '1', 'InstanceType': 'm1.medium',
                'ImageId': TEST_IMAGE_ID}
        conn.get_object('RunInstances', params, boto.ec2.instance.Reservation,
                verb='POST').AndReturn(reservation)

        self.mox.ReplayAll()

        url = reverse('nova_images_launch', args=[TEST_PROJECT, TEST_IMAGE_ID])
        data = {'key_name': TEST_KEY,
                'count': '1',
                'size': 'm1.medium',
                'display_name': 'name',
                'user_data': ''}
        res = self.client.post(url, data)
        self.assertRedirectsNoFollow(res, reverse('nova_instances',
                                                  args=[TEST_PROJECT]))
        self.mox.VerifyAll()
示例#7
0
    def test_detail(self):
        self.mox.StubOutWithMock(self.project, 'get_images')
        self.mox.StubOutWithMock(self.project, 'get_image')
        self.mox.StubOutWithMock(shortcuts, 'get_user_image_permissions')
        self.mox.StubOutWithMock(forms, 'get_key_pair_choices')
        self.mox.StubOutWithMock(forms, 'get_instance_type_choices')

        self.project.get_images().AndReturn([self.ami])
        self.project.get_image(TEST_IMAGE_ID).AndReturn(self.ami)
        forms.get_key_pair_choices(self.project).AndReturn(
            self.create_key_pair_choices([TEST_KEY]))
        forms.get_instance_type_choices().AndReturn(
            self.create_instance_type_choices())

        self.mox.ReplayAll()

        res = self.client.get(reverse('nova_images_detail',
                                      args=[TEST_PROJECT, TEST_IMAGE_ID]))
        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'django_openstack/nova/images/index.html')
        self.assertEqual(res.context['ami'].id, TEST_IMAGE_ID)

        self.mox.VerifyAll()
示例#8
0
    def test_detail(self):
        self.mox.StubOutWithMock(self.project, 'get_images')
        self.mox.StubOutWithMock(self.project, 'get_image')
        self.mox.StubOutWithMock(shortcuts, 'get_user_image_permissions')
        self.mox.StubOutWithMock(forms, 'get_key_pair_choices')
        self.mox.StubOutWithMock(forms, 'get_instance_type_choices')

        self.project.get_images().AndReturn([self.ami])
        self.project.get_image(TEST_IMAGE_ID).AndReturn(self.ami)
        forms.get_key_pair_choices(self.project).AndReturn(
            self.create_key_pair_choices([TEST_KEY]))
        forms.get_instance_type_choices().AndReturn(
            self.create_instance_type_choices())

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('nova_images_detail', args=[TEST_PROJECT, TEST_IMAGE_ID]))
        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'django_openstack/nova/images/index.html')
        self.assertEqual(res.context['ami'].id, TEST_IMAGE_ID)

        self.mox.VerifyAll()