@@ -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