Skip to content

Commit

Permalink
List applications
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Macdonald-Wallace committed Apr 18, 2019
1 parent 2f3aca0 commit d1a900b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pyloraserver/applications.py
@@ -0,0 +1,25 @@
class Application:

def __init__(self,
name=None,
description=None,
loraserver_connection=None
):
self.lscx = loraserver_connection

def list(self,
limit=10,
offset=0,
search_term=None,
orgid=None):
url = "%s/api/applications?limit=%s&offset=%s" % (
self.lscx.loraserver_url,
limit,
offset)
if search_term is not None:
url = "%s&search=%s" % (url, search_term)
if orgid is not None:
url = "%s&organizationID=%s" % (url, orgid)

ret_list = self.lscx.connection.get(url)
return ret_list.json()
45 changes: 45 additions & 0 deletions tests/test_applications.py
@@ -0,0 +1,45 @@
import pytest
from pyloraserver import applications


class TestApplication:
@pytest.fixture
def lora_connection(self, requests_mock):
# Mock the Authentication Handler
requests_mock.get(
"https://loraserver/api/applications",
json={
"result": [
{
"description": "A test application from the test fixture", # noqa: E501
"id": "1",
"name": "TEST_APPLICATION",
"organizationID": "1",
"serviceProfileID": "54767cb5-beef-494e-dead-8821ddd69bcb", # noqa: E501
"serviceProfileName": "testServiceProfile"
}
],
"totalCount": "string"
}
)

requests_mock.post(
"https://loraserver/api/internal/login",
json={
"jwt": "eyJhbGciOiZXJ2ZXIiLCJleHAiOjE1NTU1OTk1ODMsImlzcyI6ImxvcmEtYXBwLXNlcnZlciIsIm5iZiI6MTU1NTUxMzE4Mywic3ViIjoidXNlciIsInVzZXJuYW1lIjoiYXBpYWNjb3VudCJ9.MBkIe1pxh51lB4-qRkjxlMaOa2HBnMhwk148wYrBDj0JIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJsb3JhLWFwcC1z" # noqa: E501
}
)
from pyloraserver import loraserver
return loraserver.Loraserver(
loraserver_url="https://loraserver",
loraserver_user="test_user",
loraserver_pass="test_pass"
)

def test_device_profile_list(self,
lora_connection
):
a = applications.Application(
loraserver_connection=lora_connection)
alist = a.list()
assert alist['result'][0]['name'] == "TEST_APPLICATION"

0 comments on commit d1a900b

Please sign in to comment.