4
4
#
5
5
# SPDX-License-Identifier: GPL-3.0-or-later
6
6
7
- import unittest
8
7
import tempfile
9
8
import json
10
9
import parameterized
20
19
21
20
from ..lib .web import RacksDBCustomTestResponse
22
21
from ..lib .common import schema_path , db_path , drawing_schema_path
23
-
24
- # Expected values from example DB.
25
- EXAMPLE_DATACENTERS = ["paris" , "london" ]
26
- EXAMPLE_INFRASTRUCTURES = ["mercury" , "jupiter" , "sharednet" ]
22
+ from ..lib .reference import (
23
+ TestRacksDBReferenceDB ,
24
+ REFDB_DATACENTERS ,
25
+ REFDB_INFRASTRUCTURES ,
26
+ )
27
27
28
28
29
29
class FakeRacksDBWebApp (flask .Flask ):
@@ -38,7 +38,7 @@ def __init__(self, schema, db, drawing_schema, openapi):
38
38
self .register_blueprint (self .blueprint )
39
39
40
40
41
- class TestRacksDBWebBlueprint (unittest . TestCase ):
41
+ class TestRacksDBWebBlueprint (TestRacksDBReferenceDB ):
42
42
def setUp (self ):
43
43
try :
44
44
self .schema_path = schema_path ()
@@ -120,26 +120,10 @@ def test_schema(self):
120
120
tmp .write (response .text )
121
121
RacksDB .load (schema = tmp .name , db = self .db_path )
122
122
123
- # test schema
124
-
125
123
#
126
124
# datacenters
127
125
#
128
126
129
- def assertDatacentersResponse (self , content ):
130
- self .assertIsInstance (content , list )
131
- self .assertEqual (len (content ), 2 )
132
- self .assertCountEqual (
133
- [datacenter ["name" ] for datacenter in content ], EXAMPLE_DATACENTERS
134
- )
135
- self .assertIsInstance (content [0 ], dict )
136
- # tags key is optional, it may not be present in selected datacenter.
137
- for key in ["name" , "rooms" , "location" ]:
138
- self .assertIn (
139
- key ,
140
- content [0 ],
141
- )
142
-
143
127
def test_datacenters (self ):
144
128
response = self .client .get (f"/v{ get_version ()} /datacenters" )
145
129
self .assertEqual (response .status_code , 200 )
@@ -157,17 +141,17 @@ def test_datacenters_list(self):
157
141
self .assertEqual (response .status_code , 200 )
158
142
self .assertEqual (response .mimetype , "application/json" )
159
143
self .assertIsInstance (response .json , list )
160
- self .assertCountEqual (response .json , EXAMPLE_DATACENTERS )
144
+ self .assertCountEqual (response .json , REFDB_DATACENTERS )
161
145
162
146
def test_datacenters_name (self ):
163
147
response = self .client .get (
164
- f"/v{ get_version ()} /datacenters?name={ EXAMPLE_DATACENTERS [0 ]} "
148
+ f"/v{ get_version ()} /datacenters?name={ REFDB_DATACENTERS [0 ]} "
165
149
)
166
150
self .assertEqual (response .status_code , 200 )
167
151
self .assertEqual (response .mimetype , "application/json" )
168
152
self .assertIsInstance (response .json , list )
169
153
self .assertEqual (len (response .json ), 1 )
170
- self .assertCountEqual (response .json [0 ]["name" ], EXAMPLE_DATACENTERS [0 ])
154
+ self .assertCountEqual (response .json [0 ]["name" ], REFDB_DATACENTERS [0 ])
171
155
172
156
def test_datacenters_name_not_found (self ):
173
157
response = self .client .get (f"/v{ get_version ()} /datacenters?name=fail" )
@@ -216,21 +200,6 @@ def test_datacenters_fold(self):
216
200
# infrastructures
217
201
#
218
202
219
- def assertInfrastructuresResponse (self , content ):
220
- self .assertIsInstance (content , list )
221
- self .assertEqual (len (content ), 3 )
222
- self .assertCountEqual (
223
- [infrastructure ["name" ] for infrastructure in content ],
224
- EXAMPLE_INFRASTRUCTURES ,
225
- )
226
- self .assertIsInstance (content [0 ], dict )
227
- # tags key is optional, it may not be present in selected infrastructure.
228
- for key in ["name" , "description" , "layout" ]:
229
- self .assertIn (
230
- key ,
231
- content [0 ],
232
- )
233
-
234
203
def test_infrastructures (self ):
235
204
response = self .client .get (f"/v{ get_version ()} /infrastructures" )
236
205
self .assertEqual (response .status_code , 200 )
@@ -248,16 +217,16 @@ def test_infrastructures_list(self):
248
217
self .assertEqual (response .status_code , 200 )
249
218
self .assertEqual (response .mimetype , "application/json" )
250
219
self .assertIsInstance (response .json , list )
251
- self .assertCountEqual (response .json , EXAMPLE_INFRASTRUCTURES )
220
+ self .assertCountEqual (response .json , REFDB_INFRASTRUCTURES )
252
221
253
222
def test_infrastructures_name (self ):
254
223
response = self .client .get (
255
- f"/v{ get_version ()} /infrastructures?name={ EXAMPLE_INFRASTRUCTURES [0 ]} "
224
+ f"/v{ get_version ()} /infrastructures?name={ REFDB_INFRASTRUCTURES [0 ]} "
256
225
)
257
226
self .assertEqual (response .status_code , 200 )
258
227
self .assertEqual (response .mimetype , "application/json" )
259
228
self .assertIsInstance (response .json , list )
260
- self .assertEqual (response .json [0 ]["name" ], EXAMPLE_INFRASTRUCTURES [0 ])
229
+ self .assertEqual (response .json [0 ]["name" ], REFDB_INFRASTRUCTURES [0 ])
261
230
262
231
def test_infrastructures_name_not_found (self ):
263
232
response = self .client .get (f"/v{ get_version ()} /infrastructures?name=fail" )
@@ -321,15 +290,6 @@ def test_infrastructures_fold(self):
321
290
# nodes
322
291
#
323
292
324
- def assertNodesResponse (self , content ):
325
- self .assertIsInstance (content , list )
326
- self .assertEqual (len (content ), 130 )
327
- self .assertIsInstance (content [0 ], dict )
328
- self .assertCountEqual (
329
- content [0 ].keys (),
330
- ["name" , "infrastructure" , "rack" , "type" , "slot" , "tags" , "position" ],
331
- )
332
-
333
293
def test_nodes (self ):
334
294
response = self .client .get (f"/v{ get_version ()} /nodes" )
335
295
self .assertEqual (response .status_code , 200 )
@@ -438,26 +398,6 @@ def test_nodes_infrastructure_not_found(self):
438
398
# racks
439
399
#
440
400
441
- def assertRacksResponse (self , content ):
442
- self .assertIsInstance (content , list )
443
- self .assertEqual (len (content ), 101 )
444
- self .assertIsInstance (content [0 ], dict )
445
- # tags key is optional, it may not be present in select rack.
446
- for key in [
447
- "name" ,
448
- "slot" ,
449
- "type" ,
450
- "datacenter" ,
451
- "room" ,
452
- "row" ,
453
- "nodes" ,
454
- "fillrate" ,
455
- ]:
456
- self .assertIn (
457
- key ,
458
- content [0 ].keys (),
459
- )
460
-
461
401
def test_racks (self ):
462
402
response = self .client .get (f"/v{ get_version ()} /racks" )
463
403
self .assertEqual (response .status_code , 200 )
0 commit comments