Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Updates for tables
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeff07 committed Aug 17, 2022
1 parent 240a2cb commit f0d0dbe
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ipfabric/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions tests/unittests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f0d0dbe

Please sign in to comment.