This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest_application.py
78 lines (64 loc) · 2.78 KB
/
test_application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# coding: Latin-1
# Copyright © 2018 The Things Network
# Use of this source code is governed by the
# MIT license that can be found in the LICENSE file.
import unittest
from app_mock import MockApplicationManager
from ttn import ApplicationClient
import ttn.github_com.TheThingsNetwork.api.handler.handler_pb2 as handler
from ttn.utils import stubs
import binascii
class TestApplicationClient(unittest.TestCase):
def setUp(self):
self.mock = MockApplicationManager()
self.manager = ApplicationClient("test", "pswd")
self.manager.client = self.mock
def test_get(self):
self.mock.reset()
self.mock.application = handler.Application()
self.mock.application.app_id = "test"
res = self.manager.get()
assert res["application"].app_id == "test"
def test_payload_format(self):
self.mock.reset()
self.mock.application = handler.Application()
self.mock.application.payload_format = "custom"
res = self.manager.get()
assert res["application"].payload_format == "custom"
self.manager.set_payload_format("other")
assert self.mock.application.payload_format == "other"
def test_custom_payload(self):
self.mock.reset()
self.mock.application = handler.Application()
self.mock.application.payload_format = "custom"
self.mock.application.decoder = "decoder"
self.mock.application.converter = "converter"
self.mock.application.validator ="validator"
self.mock.application.encoder = "encoder"
res = self.manager.get()
assert res["application"].payload_format == "custom" and \
res["application"].validator =="validator" and \
res["application"].decoder =="decoder"
self.manager.set_custom_payload_functions(validator="nvalidator",
decoder="ndecoder")
res = self.manager.get()
assert res["application"].payload_format == "custom" and \
res["application"].validator =="nvalidator" and \
res["application"].decoder =="ndecoder"
def test_device(self):
self.mock.reset()
self.manager.register_device("foo", stubs.devicetest)
res = self.manager.device("foo")
assert res.dev_id == "foo"
res = self.manager.devices()
assert res is not None
update = {
"devEui": "1100223344556677",
}
self.manager.update_device("foo", update)
res = self.manager.device("foo")
assert res.lorawan_device.dev_eui == binascii.unhexlify("110022"
"3344556677")
self.manager.delete_device("foo")
res = self.manager.device("foo")
assert res is None