diff --git a/ipfabric/models.py b/ipfabric/models.py index ef7278b..2c71b0a 100644 --- a/ipfabric/models.py +++ b/ipfabric/models.py @@ -91,6 +91,38 @@ class Table(BaseModel): def name(self): return self.endpoint.split("/")[-1] + def fetch( + self, + columns: list = None, + filters: Optional[dict] = None, + snapshot_id: Optional[str] = None, + reports: Optional[str] = None, + sort: Optional[dict] = None, + limit: Optional[int] = 1000, + start: Optional[int] = 0, + ): + """ + Gets all data from corresponding endpoint + :param columns: list: Optional columns to return, default is all + :param filters: dict: Optional filters + :param snapshot_id: str: Optional snapshot ID to override class + :param reports: str: String of frontend URL where the reports are displayed + :param sort: dict: Dictionary to apply sorting: {"order": "desc", "column": "lastChange"} + :param limit: int: Default to 1,000 rows + :param start: int: Starts at 0 + :return: list: List of Dictionaries + """ + return self.client.fetch( + self.endpoint, + columns=columns, + filters=filters, + snapshot_id=snapshot_id, + reports=reports, + sort=sort, + limit=limit, + start=start, + ) + def all( self, columns: list = None, diff --git a/tests/unittests/test_models.py b/tests/unittests/test_models.py index d7d3116..983e1a7 100644 --- a/tests/unittests/test_models.py +++ b/tests/unittests/test_models.py @@ -39,6 +39,18 @@ def test_table_all(self, MockClient): MockClient.fetch_all.return_value = list() self.assertEqual(table.all(), list()) + @patch("ipfabric.IPFClient") + def test_table_fetch(self, MockClient): + table = models.Table(client=MockClient, endpoint="/network/ip") + MockClient.fetch.return_value = list() + self.assertEqual(table.fetch(), list()) + + @patch("ipfabric.IPFClient") + def test_table_count(self, MockClient): + table = models.Table(client=MockClient, endpoint="/network/ip") + MockClient.get_count.return_value = 1 + self.assertEqual(table.count(), 1) + def test_inventory(self): i = models.Inventory(client=MagicMock()) self.assertIsInstance(i.vendors, models.Table)