diff --git a/tests/integration/test_dcim.py b/tests/integration/test_dcim.py index 544ef71..d717c2f 100644 --- a/tests/integration/test_dcim.py +++ b/tests/integration/test_dcim.py @@ -183,6 +183,7 @@ def test_fetching_vc_success(self, nb_client): role={"name": "Leaf Switch"}, location=location.id, status={"name": "Active"}, + local_config_context_data={"foo": "bar"}, ) vc = nb_client.dcim.virtual_chassis.create(name="VC1", master=dev1.id) nb_client.dcim.devices.create( @@ -193,6 +194,7 @@ def test_fetching_vc_success(self, nb_client): status={"name": "Active"}, virtual_chassis=vc.id, vc_position=2, + local_config_context_data={"foo": "bar"}, ) all_vcs = nb_client.dcim.virtual_chassis.all() assert len(all_vcs) == 1 diff --git a/tests/integration/test_endpoint.py b/tests/integration/test_endpoint.py index f97287b..a22f9d0 100644 --- a/tests/integration/test_endpoint.py +++ b/tests/integration/test_endpoint.py @@ -1,3 +1,19 @@ +class TestEndpoint: + """Verify different methods on an endpoint.""" + + def test_get_all_devices(self, nb_client): + devices = nb_client.dcim.devices.all() + assert len(devices) == 8 + + def test_get_all_devices_include_context(self, nb_client): + devices = nb_client.dcim.devices.all(name="dev-1", include=["config_context"]) + assert devices[0].config_context == {"foo": "bar"} + + def test_get_filtered_devices(self, nb_client): + devices = nb_client.dcim.devices.filter(device_type="DCS-7050TX3-48C8") + assert len(devices) == 6 + + class TestPagination: """Verify we can limit and offset results on an endpoint.""" diff --git a/tests/unit/test_endpoint.py b/tests/unit/test_endpoint.py index cbe7b65..abacdab 100644 --- a/tests/unit/test_endpoint.py +++ b/tests/unit/test_endpoint.py @@ -15,13 +15,6 @@ def test_filter(self): test = test_obj.filter(test="test") self.assertEqual(len(test), 2) - def test_filter_empty_kwargs(self): - api = Mock(base_url="http://localhost:8000/api") - app = Mock(name="test") - test_obj = Endpoint(api, app, "test") - with self.assertRaises(ValueError) as _: - test_obj.filter() - def test_filter_reserved_kwargs(self): api = Mock(base_url="http://localhost:8000/api") app = Mock(name="test") @@ -38,6 +31,22 @@ def test_all_none_limit_offset(self): with self.assertRaises(ValueError) as _: test_obj.all(limit=None, offset=1) + def test_all_equals_filter_empty_kwargs(self): + with patch("pynautobot.core.query.Request.get", return_value=Mock()) as mock: + api = Mock(base_url="http://localhost:8000/api") + app = Mock(name="test") + mock.return_value = [{"id": 123}, {"id": 321}] + test_obj = Endpoint(api, app, "test") + self.assertEqual(test_obj.all(), test_obj.filter()) + + def test_all_accepts_kwargs(self): + with patch("pynautobot.core.endpoint.Endpoint.filter", return_value=Mock()) as mock: + api = Mock(base_url="http://localhost:8000/api") + app = Mock(name="test") + test_obj = Endpoint(api, app, "test") + test_obj.all(include=["config_context"]) + mock.assert_called_with(include=["config_context"]) + def test_filter_zero_limit_offset(self): with patch("pynautobot.core.query.Request.get", return_value=Mock()) as mock: api = Mock(base_url="http://localhost:8000/api")