Skip to content

Commit 252fa3e

Browse files
author
Zach Moody
committed
Add unit tests for Endpoint.get()
1 parent 118b6b2 commit 252fa3e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/unit/test_endpoint.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,36 @@ def test_choices(self):
5959
choices = test_obj.choices()
6060
self.assertEqual(choices["letter"][1]["display_name"], "B")
6161
self.assertEqual(choices["letter"][1]["value"], 2)
62+
63+
def test_get_with_filter(self):
64+
with patch(
65+
"pynetbox.core.query.Request._make_call", return_value=Mock()
66+
) as mock:
67+
mock.return_value = [{"id": 123}]
68+
api = Mock(base_url="http://localhost:8000/api")
69+
app = Mock(name="test")
70+
test_obj = Endpoint(api, app, "test")
71+
test = test_obj.get(name="test")
72+
self.assertEqual(test.id, 123)
73+
74+
def test_get_greater_than_one(self):
75+
with patch(
76+
"pynetbox.core.query.Request._make_call", return_value=Mock()
77+
) as mock:
78+
mock.return_value = [{"id": 123}, {"id": 321}]
79+
api = Mock(base_url="http://localhost:8000/api")
80+
app = Mock(name="test")
81+
test_obj = Endpoint(api, app, "test")
82+
with self.assertRaises(ValueError) as _:
83+
test_obj.get(name="test")
84+
85+
def test_get_no_results(self):
86+
with patch(
87+
"pynetbox.core.query.Request._make_call", return_value=Mock()
88+
) as mock:
89+
mock.return_value = []
90+
api = Mock(base_url="http://localhost:8000/api")
91+
app = Mock(name="test")
92+
test_obj = Endpoint(api, app, "test")
93+
test = test_obj.get(name="test")
94+
self.assertIsNone(test)

0 commit comments

Comments
 (0)