Skip to content

Commit

Permalink
org -> organization
Browse files Browse the repository at this point in the history
  • Loading branch information
lswainemoore committed Nov 28, 2023
1 parent 72f85fa commit fe7e61c
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 64 deletions.
6 changes: 3 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ the Usage section for instructions on how to use them.
endpoints.users.Users.update


.. rubric:: Orgs Endpoints
.. rubric:: Organizations Endpoints

.. autosummary::
:toctree: generated/

endpoints.orgs.Orgs.list
endpoints.orgs.Orgs.get
endpoints.organizations.Organizations.list
endpoints.organizations.Organizations.get


.. rubric:: Networks Endpoints
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/quantaq.QuantAQAPIClient.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
~QuantAQAPIClient.logs
~QuantAQAPIClient.models
~QuantAQAPIClient.networks
~QuantAQAPIClient.orgs
~QuantAQAPIClient.organizations
~QuantAQAPIClient.users


2 changes: 1 addition & 1 deletion docs/generated/quantaq.client.APIClient.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
~APIClient.logs
~APIClient.models
~APIClient.networks
~APIClient.orgs
~APIClient.organizations
~APIClient.users


2 changes: 1 addition & 1 deletion docs/generated/quantaq.client.DevelopmentAPIClient.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
~DevelopmentAPIClient.logs
~DevelopmentAPIClient.models
~DevelopmentAPIClient.networks
~DevelopmentAPIClient.orgs
~DevelopmentAPIClient.organizations
~DevelopmentAPIClient.users


2 changes: 1 addition & 1 deletion docs/generated/quantaq.client.ProductionAPIClient.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
~ProductionAPIClient.logs
~ProductionAPIClient.models
~ProductionAPIClient.networks
~ProductionAPIClient.orgs
~ProductionAPIClient.organizations
~ProductionAPIClient.users


2 changes: 1 addition & 1 deletion docs/generated/quantaq.client.StagingAPIClient.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
~StagingAPIClient.logs
~StagingAPIClient.models
~StagingAPIClient.networks
~StagingAPIClient.orgs
~StagingAPIClient.organizations
~StagingAPIClient.users


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
quantaq.endpoints.organizations.Organizations.get
=================================================

.. currentmodule:: quantaq.endpoints.organizations

.. automethod:: Organizations.get
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
quantaq.endpoints.organizations.Organizations.list
==================================================

.. currentmodule:: quantaq.endpoints.organizations

.. automethod:: Organizations.list
6 changes: 0 additions & 6 deletions docs/generated/quantaq.endpoints.orgs.Orgs.get.rst

This file was deleted.

6 changes: 0 additions & 6 deletions docs/generated/quantaq.endpoints.orgs.Orgs.list.rst

This file was deleted.

18 changes: 9 additions & 9 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ You can retrieve a list of all the organizations visible to you:

.. code-block:: python
>>> orgs = client.orgs.list()
>>> print (orgs)
>>> organizations = client.organizations.list()
>>> print (organizations)
Get a Single Organization
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -93,8 +93,8 @@ with the id as an argument:

.. code-block:: python
>>> org = client.orgs.get(id=1)
>>> print (org)
>>> organization = client.organizations.get(id=1)
>>> print (organization)
Networks
Expand All @@ -104,11 +104,11 @@ List All Networks
^^^^^^^^^^^^^^^^^

You can retrieve a list of all the networks visible to you, in the context of
a given organization, with the org_id as an argument:
a given organization, with the organization_id as an argument:

.. code-block:: python
>>> networks = client.networks.list(org_id=1)
>>> networks = client.networks.list(organization_id=1)
>>> print (networks)
Get a Single Network
Expand All @@ -119,7 +119,7 @@ with the parent organization_id and the network_id as arguments:

.. code-block:: python
>>> network = client.networks.get(org_id=1, network_id=1)
>>> network = client.networks.get(organization_id=1, network_id=1)
>>> print (network)
Expand Down Expand Up @@ -151,12 +151,12 @@ function to convert the list to a dataframe:
Devices - Advanced Queries
^^^^^^^^^^^^^^^^^^^^^^^^^^

Devices are filterable by organization and network, using the org_id and network_id
Devices are filterable by organization and network, using the organization_id and network_id
kwargs. For example, to get the devices in a particular organization:

.. code-block:: python
>>> devices = client.devices.list(org_id=1)
>>> devices = client.devices.list(organization_id=1)
>>> print (devices)
Expand Down
12 changes: 6 additions & 6 deletions quantaq/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(

self._users = None
self._devices = None
self._orgs = None
self._organizations = None
self._networks = None
self._data = None
self._logs = None
Expand Down Expand Up @@ -217,12 +217,12 @@ def users(self):
return self._users

@property
def orgs(self):
def organizations(self):
""""""
if self._orgs is None:
from .endpoints.orgs import Orgs
self._orgs = Orgs(self)
return self._orgs
if self._organizations is None:
from .endpoints.organizations import Organizations
self._organizations = Organizations(self)
return self._organizations

@property
def networks(self):
Expand Down
5 changes: 4 additions & 1 deletion quantaq/endpoints/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, client) -> None:
def list(self, **kwargs) -> list:
"""Return all (available) devices.
:param int org_id: Filter to devices owned by given org.
:param int organization_id: Filter to devices owned by given organization.
:param int network_id: Filter to devices owned by given network.
:param str limit: Limit the number of results returned
:param str sort: Sort the results by a specific attribute
Expand All @@ -26,6 +26,9 @@ def list(self, **kwargs) -> list:
:returns: List of devices.
:rtype: list of dict
"""
# translate this to what's expected by the API
if 'organization_id' in kwargs:
kwargs["org_id"] = kwargs.pop("organization_id")
return self.client.requests("devices/", **kwargs)

def get(self, **kwargs) -> dict:
Expand Down
18 changes: 9 additions & 9 deletions quantaq/endpoints/networks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

class Networks(Domain):
"""
Note: the Networks endpoint is scoped within the Orgs endpoint,
Note: the Networks endpoint is scoped within the Organizations endpoint,
so all requests for networks (all or singular) are in the context
of a particular organization.
"""

def list(self, **kwargs):
"""
Return a list of networks accessible by the account,
in the context of the org with id=org_id.
in the context of the organization with id=organization_id.
:param int org_id: The parent org id.
:param int organization_id: The parent organization id.
:param str limit: Limit the number of results returned
:param str sort: Sort the results by a specific attribute
:param str filter: Filter the query
Expand All @@ -22,20 +22,20 @@ def list(self, **kwargs):
:returns: Networks
:rtype: list of dict
"""
org_id = kwargs.pop("org_id")
return self.client.requests(f"orgs/{org_id}/networks/", **kwargs)
organization_id = kwargs.pop("organization_id")
return self.client.requests(f"orgs/{organization_id}/networks/", **kwargs)

def get(self, **kwargs):
"""
Return network with id=network_id in org with id=org_id.
Return network with id=network_id in organization with id=organization_id.
:param int org_id: The parent org id
:param int organization_id: The parent organization id
:param int network_id: The network id
:returns: Network information
:rtype: dict
"""
org_id = kwargs.pop("org_id")
organization_id = kwargs.pop("organization_id")
network_id = kwargs.pop("network_id")

return self.client.requests(f"orgs/{org_id}/networks/{network_id}", **kwargs)
return self.client.requests(f"orgs/{organization_id}/networks/{network_id}", **kwargs)
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
from quantaq.endpoints import Domain


class Orgs(Domain):
class Organizations(Domain):
def list(self, **kwargs):
"""
Return a list of orgs accessible by the account.
Return a list of organizations accessible by the account.
:param str limit: Limit the number of results returned
:param str sort: Sort the results by a specific attribute
:param str filter: Filter the query
:param int per_page: Define the number of results to return per page
:returns: Orgs
:returns: Organizations
:rtype: list of dict
"""
return self.client.requests("orgs/", **kwargs)

def get(self, **kwargs):
"""
Return org with id = id.
Return organizations with id = id.
:param int id: The org id
:param int id: The organization id
:returns: Org information
:returns: Organizations information
:rtype: dict
"""
id = kwargs.pop("id")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def test_devices_list():
assert 'status' in resp[0]
assert len(resp) == 3

# brief check that org_id/network_id are passed on as query parameters
resp = client.devices.list(org_id=1, network_id=1)
assert 'org_id=1&network_id=1' in responses.calls[1].request.url
# brief check that organization_id/network_id are passed on as query parameters
resp = client.devices.list(organization_id=1, network_id=1)
assert 'network_id=1&org_id=1' in responses.calls[1].request.url
assert type(resp) == list

@responses.activate
Expand Down
4 changes: 2 additions & 2 deletions tests/test_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_networks_list():
"https://localhost/device-api/",
api_key="a123", version="v1")

resp = client.networks.list(org_id=1)
resp = client.networks.list(organization_id=1)

assert type(resp) == list
assert type(resp[0]) == dict
Expand All @@ -55,6 +55,6 @@ def test_networks_get():
api_key="a123", version="v1")

# test the GET verb
resp = client.networks.get(org_id=1, network_id=1)
resp = client.networks.get(organization_id=1, network_id=1)

assert type(resp) == dict
16 changes: 8 additions & 8 deletions tests/test_orgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import quantaq


ORG = {
"name": "Org 1",
ORGANIZATION = {
"name": "Organization 1",
"id": 1,
"description": "",
"created_on": "2023-11-16T00:00:00.000000+00:00",
Expand All @@ -15,7 +15,7 @@


@responses.activate
def test_orgs_list():
def test_organizations_list():
responses.add(responses.GET,"https://localhost/device-api/v1/orgs/",
status=200,
json={
Expand All @@ -29,33 +29,33 @@ def test_orgs_list():
"prev_url": None,
"total": 2
},
"data": [ORG],
"data": [ORGANIZATION],
}
)

client = quantaq.client.APIClient(
"https://localhost/device-api/",
api_key="a123", version="v1")

resp = client.orgs.list()
resp = client.organizations.list()

assert type(resp) == list
assert type(resp[0]) == dict
assert len(resp) == 1


@responses.activate
def test_orgs_get():
def test_organizations_get():
responses.add(responses.GET, "https://localhost/device-api/v1/orgs/1",
status=200,
json=ORG,
json=ORGANIZATION,
)

client = quantaq.client.APIClient(
"https://localhost/device-api/",
api_key="a123", version="v1")

# test the GET verb
resp = client.orgs.get(id=1)
resp = client.organizations.get(id=1)

assert type(resp) == dict

0 comments on commit fe7e61c

Please sign in to comment.