add nick
[laas.git] / src / resource_inventory / tests / test_models.py
1 ##############################################################################
2 # Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from django.test import TestCase
10 from django.contrib.auth.models import User
11 from account.models import Lab
12 from resource_inventory.models import (
13     Scenario,
14     Installer,
15     Opsys,
16     ConfigBundle,
17     OPNFVConfig,
18     OPNFVRole,
19     Image,
20     HostProfile,
21     GenericResourceBundle,
22     GenericResource,
23     GenericHost,
24     HostConfiguration
25 )
26
27
28 class ConfigUtil():
29     count = 0
30
31     @staticmethod
32     def makeScenario():
33         return Scenario.objects.create(name="testScenario")
34
35     @staticmethod
36     def makeInstaller():
37         inst = Installer.objects.create(name="testInstaller")
38         inst.sup_scenarios = [ConfigUtil.makeScenario()]
39         return inst
40
41     @staticmethod
42     def makeOpsys():
43         os = Opsys.objects.create(name="test Operating System")
44         os.sup_installers = [ConfigUtil.makeInstaller()]
45         return os
46
47     @staticmethod
48     def makeConfigBundle():
49         user = User.objects.create(username="test_user" + str(ConfigUtil.count))
50         ConfigUtil.count += 1
51         return ConfigBundle.objects.create(owner=user)
52
53     @staticmethod
54     def makeOPNFVConfig():
55         installer = ConfigUtil.makeInstaller()
56         scenario = ConfigUtil.makeScenario()
57         bundle = ConfigUtil.makeConfigBundle()
58         return OPNFVConfig.objects.create(
59             installer=installer,
60             scenario=scenario,
61             bundle=bundle
62         )
63
64     @staticmethod
65     def makeOPNFVRole():
66         return OPNFVRole.objects.create(
67             name="Test role",
68             description="This is a test role"
69         )
70
71     @staticmethod
72     def makeImage():
73         owner = User.objects.create(username="another test user")
74         lab_user = User.objects.create(username="labUserForTests")
75         lab = Lab.objects.create(
76             lab_user=lab_user,
77             name="this is lab for testing",
78             contact_email="email@mail.com",
79             contact_phone="123-4567"
80         )
81
82         return Image.objects.create(
83             cobbler_id="profile1",
84             from_lab=lab,
85             name="an image for testing",
86             owner=owner
87         )
88
89     @staticmethod
90     def makeGenericHost():
91         profile = HostProfile.objects.create(
92             host_type=0,
93             name="test lab for config bundle",
94             description="this is a test profile"
95         )
96         user = User.objects.create(username="test sample user 12")
97         bundle = GenericResourceBundle.objects.create(
98             name="Generic bundle for config tests",
99             xml="",
100             owner=user,
101             description=""
102         )
103
104         resource = GenericResource.objects.create(
105             bundle=bundle,
106             name="a test generic resource"
107         )
108
109         return GenericHost.objects.create(
110             profile=profile,
111             resource=resource
112         )
113
114     @staticmethod
115     def makeHostConfiguration():
116         host = ConfigUtil.makeGenericHost()
117         image = ConfigUtil.makeImage()
118         bundle = ConfigUtil.makeConfigBundle()
119         opnfvRole = ConfigUtil.makeOPNFVRole()
120         return HostConfiguration.objects.create(
121             host=host,
122             image=image,
123             bundle=bundle,
124             opnfvRole=opnfvRole
125         )
126
127
128 class ScenarioTestCase(TestCase):
129
130     def test_save(self):
131         self.assertTrue(ConfigUtil.makeScenario())
132
133
134 class InstallerTestCase(TestCase):
135
136     def test_save(self):
137         self.assertTrue(ConfigUtil.makeInstaller())
138
139
140 class OperatingSystemTestCase(TestCase):
141
142     def test_save(self):
143         self.assertTrue(ConfigUtil.makeOpsys())
144
145
146 class ConfigBundleTestCase(TestCase):
147
148     def test_save(self):
149         self.assertTrue(ConfigUtil.makeConfigBundle())
150
151
152 class OPNFVConfigTestCase(TestCase):
153
154     def test_save(self):
155         self.assertTrue(ConfigUtil.makeOPNFVConfig())
156
157
158 class OPNFVRoleTestCase(TestCase):
159
160     def test_save(self):
161         self.assertTrue(ConfigUtil.makeOPNFVRole())
162
163
164 class HostConfigurationTestCase(TestCase):
165
166     def test_save(self):
167         self.assertTrue(ConfigUtil.makeHostConfiguration())
168
169
170 class ImageTestCase(TestCase):
171
172     def test_save(self):
173         self.assertTrue(ConfigUtil.makeImage())