Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthew Macdonald-Wallace
committed
Apr 18, 2019
1 parent
2f3aca0
commit d1a900b
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |