Skip to content

Commit

Permalink
Merge pull request #224 from tsm1th/u/tsm1th-fix-terminations-that-in…
Browse files Browse the repository at this point in the history
…c-circuits

Fixed issue where circuit details are not known without fetching them
  • Loading branch information
joewesch authored Aug 12, 2024
2 parents 24648b6 + 8796d99 commit 6f06bf0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
8 changes: 1 addition & 7 deletions pynautobot/models/dcim.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,7 @@ def elevation(self):

class Termination(Record):
def __str__(self):
# hacky check to see if we're a circuit termination to
# avoid another call to Nautobot because of a non-existent attr
# in self.name
if "circuit" in str(self.url):
return self.circuit.cid

return self.name
return self.display

device = Devices
circuit = Circuits
Expand Down
6 changes: 4 additions & 2 deletions tests/fixtures/dcim/cable.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"display_name": "tst1-test1"
},
"name": "Console",
"cable": 1
"cable": 1,
"display": "foo"
},
"termination_b_type": "dcim.consoleserverport",
"termination_b_id": 2,
Expand All @@ -26,7 +27,8 @@
"display_name": "tst1-test2"
},
"name": "Port 10",
"cable": 1
"cable": 1,
"display": "foo"
},
"type": null,
"status": {
Expand Down
18 changes: 12 additions & 6 deletions tests/fixtures/dcim/cables.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"display_name": "tst1-test1"
},
"name": "Console",
"cable": 1
"cable": 1,
"display": "foo"
},
"termination_b_type": "dcim.consoleserverport",
"termination_b_id": 2,
Expand All @@ -31,7 +32,8 @@
"display_name": "tst1-test2"
},
"name": "Port 10",
"cable": 1
"cable": 1,
"display": "foo"
},
"type": null,
"status": {
Expand All @@ -57,7 +59,8 @@
"display_name": "tst1-test3"
},
"name": "Console",
"cable": 2
"cable": 2,
"display": "foo"
},
"termination_b_type": "dcim.consoleserverport",
"termination_b_id": 4,
Expand All @@ -71,7 +74,8 @@
"display_name": "tst1-test4"
},
"name": "Port 11",
"cable": 2
"cable": 2,
"display": "foo"
},
"type": null,
"status": {
Expand All @@ -97,7 +101,8 @@
"display_name": "tst1-test5"
},
"name": "Console",
"cable": 3
"cable": 3,
"display": "foo"
},
"termination_b_type": "dcim.consoleserverport",
"termination_b_id": 6,
Expand All @@ -111,7 +116,8 @@
"display_name": "tst1-test6"
},
"name": "Port 1",
"cable": 3
"cable": 3,
"display": "foo"
},
"type": null,
"status": {
Expand Down
5 changes: 3 additions & 2 deletions tests/test_dcim.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class CablesTestCase(Generic.Tests):
app = "dcim"
name = "cables"

def test_get_circuit(self):
def test_get_cable_between_device_and_circuit(self):
response_obj = Response(
content={
"id": self.uuid,
Expand All @@ -368,9 +368,9 @@ def test_get_circuit(self):
"circuit": {
"id": 346,
"url": "http://localhost:8000/api/circuits/circuits/1/",
"cid": "TEST123321",
},
"term_side": "A",
"display": "TEST123321",
},
"termination_b_type": "dcim.interface",
"termination_b_id": 2,
Expand All @@ -384,6 +384,7 @@ def test_get_circuit(self):
"display_name": "tst1-test2",
},
"name": "xe-0/0/0",
"display": "xe-0/0/0",
"cable": 1,
},
"type": None,
Expand Down

0 comments on commit 6f06bf0

Please sign in to comment.