Skip to content

Commit 898c1d8

Browse files
Unit testing (#50)
1 parent 8f67d74 commit 898c1d8

File tree

2 files changed

+76
-86
lines changed

2 files changed

+76
-86
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ matrix:
2121
# Setup netbox container for integration testing
2222
- git clone https://github.com/FragmentedPacket/netbox-docker.git
2323
- cd netbox-docker
24-
- git checkout startup-dcim-interfaces-2.5
2524
- docker-compose pull
2625
- docker-compose up -d
2726
- cd ..

tests/unit/module_utils/test_netbox_base_class.py

Lines changed: 76 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -143,85 +143,57 @@ def test_init(mock_netbox_module, find_ids_return):
143143
assert mock_netbox_module.data == find_ids_return
144144

145145

146-
def test_normalize_data_returns_correct_data(mock_netbox_module):
147-
data = {
148-
"circuit": "Test-Circuit-1000",
149-
"circuit_termination": "Test Circuit",
150-
"circuit_type": "Test Circuit Type",
151-
"cluster": "Test Cluster",
152-
"cluster_group": "Test Cluster_group",
153-
"cluster_type": "Test Cluster Type",
154-
"device": "Test Device",
155-
"device_role": "Core Switch",
156-
"device_type": "Cisco Switch",
157-
"group": "Test Group1",
158-
"installed_device": "Test Device",
159-
"manufacturer": "Cisco",
160-
"nat_inside": "192.168.1.1/24",
161-
"nat_outside": "192.168.10.1/24",
162-
"platform": "Cisco IOS",
163-
"prefix_role": "TEst Role-1",
164-
"primary_ip": "192.168.1.1/24",
165-
"primary_ip4": "192.168.1.1/24",
166-
"primary_ip6": "2001::1/128",
167-
"provider": "Test Provider",
168-
"rack": "Test Rack",
169-
"rack_group": "RacK_group",
170-
"rack_role": "Test Rack Role",
171-
"region": "Test Region_1",
172-
"rir": "Test RIR_One",
173-
"prefix_role": "TEst Role-1",
174-
"slug": "Test to_slug",
175-
"site": "Test Site",
176-
"tenant": "Test Tenant",
177-
"tenant_group": "Test Tenant Group",
178-
"time_zone": "America/Los Angeles",
179-
"virtual_machine": "Test VM 100",
180-
"vlan": "Test VLAN",
181-
"vlan_group": "Test VLAN Group",
182-
"vlan_role": "Access Role",
183-
"vrf": "Test VRF",
184-
}
185-
norm_data_expected = {
186-
"circuit": "Test-Circuit-1000",
187-
"circuit_termination": "Test Circuit",
188-
"circuit_type": "test-circuit-type",
189-
"cluster": "Test Cluster",
190-
"cluster_group": "test-cluster_group",
191-
"cluster_type": "test-cluster-type",
192-
"device": "Test Device",
193-
"device_role": "core-switch",
194-
"device_type": "cisco-switch",
195-
"group": "test-group1",
196-
"installed_device": "Test Device",
197-
"manufacturer": "cisco",
198-
"nat_inside": "192.168.1.1/24",
199-
"nat_outside": "192.168.10.1/24",
200-
"platform": "cisco-ios",
201-
"prefix_role": "test-role-1",
202-
"primary_ip": "192.168.1.1/24",
203-
"primary_ip4": "192.168.1.1/24",
204-
"primary_ip6": "2001::1/128",
205-
"provider": "test-provider",
206-
"rack": "Test Rack",
207-
"rack_group": "rack_group",
208-
"rack_role": "test-rack-role",
209-
"region": "test-region_1",
210-
"rir": "test-rir_one",
211-
"slug": "test-to_slug",
212-
"site": "test-site",
213-
"tenant": "Test Tenant",
214-
"tenant_group": "test-tenant-group",
215-
"time_zone": "America/Los_Angeles",
216-
"virtual_machine": "Test VM 100",
217-
"vlan": "Test VLAN",
218-
"vlan_group": "test-vlan-group",
219-
"vlan_role": "Access Role",
220-
"vrf": "Test VRF",
221-
}
222-
norm_data = mock_netbox_module._normalize_data(data)
146+
@pytest.mark.parametrize(
147+
"before, after",
148+
[
149+
({"circuit": "Test-Circuit-1000"}, {"circuit": "Test-Circuit-1000"}),
150+
(
151+
{"circuit_termination": "Test Circuit"},
152+
{"circuit_termination": "Test Circuit"},
153+
),
154+
({"circuit_type": "Test Circuit Type"}, {"circuit_type": "test-circuit-type"}),
155+
({"cluster": "Test Cluster"}, {"cluster": "Test Cluster"}),
156+
(
157+
{"cluster_group": "Test Cluster_group"},
158+
{"cluster_group": "test-cluster_group"},
159+
),
160+
({"cluster_type": "Test Cluster Type"}, {"cluster_type": "test-cluster-type"}),
161+
({"device": "Test Device"}, {"device": "Test Device"}),
162+
({"device_role": "Core Switch"}, {"device_role": "core-switch"}),
163+
({"device_type": "Cisco Switch"}, {"device_type": "cisco-switch"}),
164+
({"group": "Test Group1"}, {"group": "test-group1"}),
165+
({"installed_device": "Test Device"}, {"installed_device": "Test Device"}),
166+
({"manufacturer": "Cisco"}, {"manufacturer": "cisco"}),
167+
({"nat_inside": "192.168.1.1/24"}, {"nat_inside": "192.168.1.1/24"}),
168+
({"nat_outside": "192.168.10.1/24"}, {"nat_outside": "192.168.10.1/24"}),
169+
({"platform": "Cisco IOS"}, {"platform": "cisco-ios"}),
170+
({"prefix_role": "TEst Role-1"}, {"prefix_role": "test-role-1"}),
171+
({"primary_ip": "192.168.1.1/24"}, {"primary_ip": "192.168.1.1/24"}),
172+
({"primary_ip4": "192.168.1.1/24"}, {"primary_ip4": "192.168.1.1/24"}),
173+
({"primary_ip6": "2001::1/128"}, {"primary_ip6": "2001::1/128"}),
174+
({"provider": "Test Provider"}, {"provider": "test-provider"}),
175+
({"rack": "Test Rack"}, {"rack": "Test Rack"}),
176+
({"rack_group": "RacK_group"}, {"rack_group": "rack_group"}),
177+
({"rack_role": "Test Rack Role"}, {"rack_role": "test-rack-role"}),
178+
({"region": "Test Region_1"}, {"region": "test-region_1"}),
179+
({"rir": "Test RIR_One"}, {"rir": "test-rir_one"}),
180+
({"prefix_role": "TEst Role-1"}, {"prefix_role": "test-role-1"}),
181+
({"slug": "Test to_slug"}, {"slug": "test-to_slug"}),
182+
({"site": "Test Site"}, {"site": "test-site"}),
183+
({"tenant": "Test Tenant"}, {"tenant": "Test Tenant"}),
184+
({"tenant_group": "Test Tenant Group"}, {"tenant_group": "test-tenant-group"}),
185+
({"time_zone": "America/Los Angeles"}, {"time_zone": "America/Los_Angeles"}),
186+
({"virtual_machine": "Test VM 100"}, {"virtual_machine": "Test VM 100"}),
187+
({"vlan": "Test VLAN"}, {"vlan": "Test VLAN"}),
188+
({"vlan_group": "Test VLAN Group"}, {"vlan_group": "test-vlan-group"}),
189+
({"vlan_role": "Access Role"}, {"vlan_role": "Access Role"}),
190+
({"vrf": "Test VRF"}, {"vrf": "Test VRF"}),
191+
],
192+
)
193+
def test_normalize_data_returns_correct_data(mock_netbox_module, before, after):
194+
norm_data = mock_netbox_module._normalize_data(before)
223195

224-
assert norm_data == norm_data_expected
196+
assert norm_data == after
225197

226198

227199
def test_to_slug_returns_valid_slug(mock_netbox_module):
@@ -374,6 +346,7 @@ def test_update_netbox_object_with_changes_check_mode_true(
374346
"status": "Provisioning",
375347
"status": "Deprovisioning",
376348
"status": "Decommissioned",
349+
"status": 1,
377350
},
378351
{
379352
"status": 1,
@@ -382,6 +355,7 @@ def test_update_netbox_object_with_changes_check_mode_true(
382355
"status": 3,
383356
"status": 0,
384357
"status": 5,
358+
"status": 1,
385359
},
386360
),
387361
(
@@ -393,8 +367,10 @@ def test_update_netbox_object_with_changes_check_mode_true(
393367
"status": "Staged",
394368
"status": "Failed",
395369
"status": "Inventory",
370+
"status": 5,
396371
"face": "Front",
397372
"face": "Rear",
373+
"face": 1,
398374
},
399375
{
400376
"status": 1,
@@ -405,6 +381,7 @@ def test_update_netbox_object_with_changes_check_mode_true(
405381
"status": 5,
406382
"face": 0,
407383
"face": 1,
384+
"face": 1,
408385
},
409386
),
410387
(
@@ -419,8 +396,9 @@ def test_update_netbox_object_with_changes_check_mode_true(
419396
"mode": "Access",
420397
"mode": "Tagged",
421398
"mode": "Tagged all",
399+
"mode": 100,
422400
},
423-
{"form_factor": 1000, "mode": 100, "mode": 200, "mode": 300},
401+
{"form_factor": 1000, "mode": 100, "mode": 200, "mode": 300, "mode": 100},
424402
),
425403
(
426404
"ip_addresses",
@@ -429,6 +407,7 @@ def test_update_netbox_object_with_changes_check_mode_true(
429407
"status": "Reserved",
430408
"status": "Deprecated",
431409
"status": "DHCP",
410+
"status": 1,
432411
"role": "Loopback",
433412
"role": "Secondary",
434413
"role": "Anycast",
@@ -437,12 +416,14 @@ def test_update_netbox_object_with_changes_check_mode_true(
437416
"role": "HSRP",
438417
"role": "GLBP",
439418
"role": "CARP",
419+
"role": 30,
440420
},
441421
{
442422
"status": 1,
443423
"status": 2,
444424
"status": 3,
445425
"status": 5,
426+
"status": 1,
446427
"role": 10,
447428
"role": 20,
448429
"role": 30,
@@ -451,6 +432,7 @@ def test_update_netbox_object_with_changes_check_mode_true(
451432
"role": 42,
452433
"role": 43,
453434
"role": 44,
435+
"role": 30,
454436
},
455437
),
456438
(
@@ -460,8 +442,9 @@ def test_update_netbox_object_with_changes_check_mode_true(
460442
"status": "Container",
461443
"status": "Reserved",
462444
"status": "Deprecated",
445+
"status": 2,
463446
},
464-
{"status": 1, "status": 0, "status": 2, "status": 3},
447+
{"status": 1, "status": 0, "status": 2, "status": 3, "status": 2},
465448
),
466449
(
467450
"racks",
@@ -478,6 +461,7 @@ def test_update_netbox_object_with_changes_check_mode_true(
478461
"type": "4-post Cabinet",
479462
"type": "Wall-mounted Frame",
480463
"type": "Wall-mounted Cabinet",
464+
"type": 1100,
481465
},
482466
{
483467
"status": 3,
@@ -492,12 +476,13 @@ def test_update_netbox_object_with_changes_check_mode_true(
492476
"type": 300,
493477
"type": 1000,
494478
"type": 1100,
479+
"type": 1100,
495480
},
496481
),
497482
(
498483
"sites",
499-
{"status": "Active", "status": "Planned", "status": "Retired"},
500-
{"status": 1, "status": 2, "status": 4},
484+
{"status": "Active", "status": "Planned", "status": "Retired", "status": 2},
485+
{"status": 1, "status": 2, "status": 4, "status": 2},
501486
),
502487
(
503488
"virtual_machines",
@@ -507,13 +492,19 @@ def test_update_netbox_object_with_changes_check_mode_true(
507492
"status": "Staged",
508493
"face": "Front",
509494
"face": "Rear",
495+
"face": 0,
510496
},
511-
{"status": 0, "status": 1, "status": 3, "face": 0, "face": 1},
497+
{"status": 0, "status": 1, "status": 3, "face": 0, "face": 1, "face": 0},
512498
),
513499
(
514500
"vlans",
515-
{"status": "Active", "status": "Reserved", "status": "Deprecated"},
516-
{"status": 1, "status": 2, "status": 3},
501+
{
502+
"status": "Active",
503+
"status": "Reserved",
504+
"status": "Deprecated",
505+
"status": 2,
506+
},
507+
{"status": 1, "status": 2, "status": 3, "status": 2},
517508
),
518509
],
519510
)

0 commit comments

Comments
 (0)