summaryrefslogtreecommitdiff
path: root/tuskar_ui/infrastructure/resource_management/flavors/tests.py
blob: deba53cd1375d8869f4feceb6105cb3143829877 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from django.core.urlresolvers import reverse
from django import http
from mox import IsA

from tuskar_ui import api as tuskar
from openstack_dashboard.test import helpers as test


class FlavorTemplatesTests(test.BaseAdminViewTests):

    @test.create_stubs({tuskar.FlavorTemplate: ('list', 'create')})
    def test_create_flavor_template(self):
        template = self.tuskar_flavor_templates.first()

        tuskar.FlavorTemplate.list(
            IsA(http.HttpRequest)).AndReturn([])
        tuskar.FlavorTemplate.create(IsA(http.HttpRequest),
                                     template.name,
                                     0, 0, 0, 0, 0).AndReturn(template)
        self.mox.ReplayAll()

        url = reverse(
            'horizon:infrastructure:resource_management:flavors:create')
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        self.assertTemplateUsed(
            resp, "infrastructure/resource_management/flavors/create.html")

        data = {'name': template.name,
                'cpu': 0,
                'memory': 0,
                'storage': 0,
                'ephemeral_disk': 0,
                'swap_disk': 0}
        resp = self.client.post(url, data)
        self.assertRedirectsNoFollow(
            resp, reverse('horizon:infrastructure:resource_management:index'))

    @test.create_stubs({tuskar.FlavorTemplate: ('list', 'update', 'get')})
    def test_edit_flavor_template_get(self):
        template = self.tuskar_flavor_templates.first()  # has no extra spec

        tuskar.FlavorTemplate.get(IsA(http.HttpRequest),
                                  template.id).AndReturn(template)
        self.mox.ReplayAll()

        url = reverse(
            'horizon:infrastructure:resource_management:flavors:edit',
            args=[template.id])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        self.assertTemplateUsed(
            resp, "infrastructure/resource_management/flavors/edit.html")

    @test.create_stubs({tuskar.FlavorTemplate: ('list', 'update', 'get')})
    def test_edit_flavor_template_post(self):
        template = self.tuskar_flavor_templates.first()  # has no extra spec

        tuskar.FlavorTemplate.list(IsA(http.HttpRequest)).AndReturn(
            self.tuskar_flavor_templates.list())
        tuskar.FlavorTemplate.update(IsA(http.HttpRequest),
                                     template.id,
                                     template.name,
                                     0, 0, 0, 0, 0).AndReturn(template)
        tuskar.FlavorTemplate.get(IsA(http.HttpRequest),
                                  template.id).AndReturn(template)
        self.mox.ReplayAll()

        data = {'flavor_id': template.id,
                'name': template.name,
                'cpu': 0,
                'memory': 0,
                'storage': 0,
                'ephemeral_disk': 0,
                'swap_disk': 0}
        url = reverse(
            'horizon:infrastructure:resource_management:flavors:edit',
            args=[template.id])
        resp = self.client.post(url, data)
        self.assertNoFormErrors(resp)
        self.assertMessageCount(success=1)
        self.assertRedirectsNoFollow(
            resp, reverse('horizon:infrastructure:resource_management:index'))

    @test.create_stubs({tuskar.FlavorTemplate: ('list', 'delete')})
    def test_delete_flavor_template(self):
        template = self.tuskar_flavor_templates.first()

        tuskar.FlavorTemplate.list(IsA(http.HttpRequest)).\
            AndReturn(self.tuskar_flavor_templates.list())
        tuskar.FlavorTemplate.delete(IsA(http.HttpRequest), template.id)
        self.mox.ReplayAll()

        form_data = {'action': 'flavors__delete__%s' % template.id}
        res = self.client.post(
            reverse('horizon:infrastructure:resource_management:index'),
            form_data)

        self.assertRedirectsNoFollow(
            res, reverse('horizon:infrastructure:resource_management:index'))

    @test.create_stubs({tuskar.FlavorTemplate: ('get',)})
    def test_detail_flavor_template(self):
        template = self.tuskar_flavor_templates.first()

        tuskar.FlavorTemplate.get(IsA(http.HttpRequest),
                                  template.id).AndReturn(template)
        tuskar.FlavorTemplate.resource_classes = self. \
            tuskar_resource_classes

        self.mox.ReplayAll()

        url = reverse(
            'horizon:infrastructure:resource_management:flavors:detail',
            args=[template.id])
        res = self.client.get(url)
        self.assertTemplateUsed(
            res, "infrastructure/resource_management/flavors/detail.html")