Lab as a Service 2.0
[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
14
15 class ConfigUtil():
16     count=0
17
18     @staticmethod
19     def makeScenario():
20         return Scenario.objects.create(name="testScenario")
21
22     @staticmethod
23     def makeInstaller():
24         inst = Installer.objects.create(
25             name = "testInstaller"
26         )
27         inst.sup_scenarios = [ConfigUtil.makeScenario()]
28         return inst
29
30     @staticmethod
31     def makeOpsys():
32         os = Opsys.objects.create(
33             name = "test Operating System"
34         )
35         os.sup_installers = [ConfigUtil.makeInstaller()]
36         return os
37
38     @staticmethod
39     def makeConfigBundle():
40         user = User.objects.create(username="test_user" + str(ConfigUtil.count))
41         ConfigUtil.count += 1
42         return ConfigBundle.objects.create(
43             owner = user
44         )
45
46     @staticmethod
47     def makeOPNFVConfig():
48         installer = ConfigUtil.makeInstaller()
49         scenario = ConfigUtil.makeScenario()
50         bundle = ConfigUtil.makeConfigBundle()
51         return OPNFVConfig.objects.create(
52                 installer=installer,
53                 scenario=scenario,
54                 bundle=bundle
55                 )
56
57     @staticmethod
58     def makeOPNFVRole():
59         return OPNFVRole.objects.create(
60                 name="Test role",
61                 description="This is a test role"
62                 )
63
64     @staticmethod
65     def makeImage():
66         owner = User.objects.create(username="another test user")
67         lab_user = User.objects.create(username="labUserForTests")
68         lab = Lab.objects.create(
69                 lab_user=lab_user,
70                 name="this is lab for testing",
71                 contact_email="email@mail.com",
72                 contact_phone="123-4567"
73                 )
74
75         return Image.objects.create(
76                 lab_id=0,
77                 from_lab=lab,
78                 name="an image for testing",
79                 owner=owner
80                 )
81
82
83     @staticmethod
84     def makeGenericHost():
85         profile = HostProfile.objects.create(
86                 host_type=0,
87                 name="test lab for config bundle",
88                 description="this is a test profile"
89                 )
90         user = User.objects.create(username="test sample user 12")
91         bundle = GenericResourceBundle.objects.create(
92                 name="Generic bundle for config tests",
93                 xml="",
94                 owner=user,
95                 description=""
96                 )
97
98         resource = GenericResource.objects.create(
99                 bundle=bundle,
100                 name="a test generic resource"
101                 )
102
103         return GenericHost.objects.create(
104                 profile=profile,
105                 resource=resource
106                 )
107
108     @staticmethod
109     def makeHostConfiguration():
110         host = ConfigUtil.makeGenericHost()
111         image = ConfigUtil.makeImage()
112         bundle = ConfigUtil.makeConfigBundle()
113         opnfvRole = ConfigUtil.makeOPNFVRole()
114         return HostConfiguration.objects.create(
115                 host=host,
116                 image=image,
117                 bundle=bundle,
118                 opnfvRole=opnfvRole
119                 )
120
121
122 class ScenarioTestCase(TestCase):
123
124     def test_save(self):
125         self.assertTrue(ConfigUtil.makeScenario())
126
127 class InstallerTestCase(TestCase):
128
129     def test_save(self):
130         self.assertTrue(ConfigUtil.makeInstaller())
131
132 class OperatingSystemTestCase(TestCase):
133
134     def test_save(self):
135         self.assertTrue(ConfigUtil.makeOpsys())
136
137 class ConfigBundleTestCase(TestCase):
138
139     def test_save(self):
140         self.assertTrue(ConfigUtil.makeConfigBundle())
141
142 class OPNFVConfigTestCase(TestCase):
143
144     def test_save(self):
145         self.assertTrue(ConfigUtil.makeOPNFVConfig())
146
147 class OPNFVRoleTestCase(TestCase):
148
149     def test_save(self):
150         self.assertTrue(ConfigUtil.makeOPNFVRole())
151
152
153 class HostConfigurationTestCase(TestCase):
154
155     def test_save(self):
156         self.assertTrue(ConfigUtil.makeHostConfiguration())
157
158
159 class ImageTestCase(TestCase):
160
161     def test_save(self):
162         self.assertTrue(ConfigUtil.makeImage())