forked from Botts-Innovative-Research/OSHConnect-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_oshconnect.py
More file actions
84 lines (68 loc) · 3.29 KB
/
test_oshconnect.py
File metadata and controls
84 lines (68 loc) · 3.29 KB
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
79
80
81
82
83
84
# ==============================================================================
# Copyright (c) 2024 Botts Innovative Research, Inc.
# Date: 2024/5/28
# Author: Ian Patterson
# Contact Email: ian@botts-inc.com
# ==============================================================================
import sys
import os
import websockets
from src.oshconnect import OSHConnect, Node
from timemanagement import TimePeriod, TimeInstant
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src')))
class TestOSHConnect:
TEST_PORT = 8282
def test_time_period(self):
tp = TimePeriod(start="2024-06-18T15:46:32Z", end="2024-06-18T20:00:00Z")
assert tp is not None
tps = tp.start
tpe = tp.end
assert isinstance(tps, TimeInstant)
assert isinstance(tpe, TimeInstant)
assert tps.epoch_time == TimeInstant.from_string("2024-06-18T15:46:32Z").epoch_time
assert tpe.epoch_time == TimeInstant.from_string("2024-06-18T20:00:00Z").epoch_time
tp = TimePeriod(start="now", end="2025-06-18T20:00:00Z")
assert tp is not None
assert tp.start == "now"
assert tp.end.epoch_time == TimeInstant.from_string("2025-06-18T20:00:00Z").epoch_time
tp = TimePeriod(start="2024-06-18T20:00:00Z", end="now")
assert tp is not None
assert tp.start.epoch_time == TimeInstant.from_string("2024-06-18T20:00:00Z").epoch_time
assert tp.end == "now"
# tp = TimePeriod(start="now", end="now")
def test_oshconnect_create(self):
app = OSHConnect(name="Test OSH Connect")
assert app is not None
assert app.get_name() == "Test OSH Connect"
def test_oshconnect_add_node(self):
app = OSHConnect(name="Test OSH Connect")
node = Node(address="http://localhost", port=self.TEST_PORT, protocol="http", username="admin",
password="admin")
# node.add_basicauth("admin", "admin")
app.add_node(node)
assert len(app._nodes) == 1
assert app._nodes[0] == node
def test_find_systems(self):
app = OSHConnect(name="Test OSH Connect")
node = Node(address="localhost", port=self.TEST_PORT, username="admin", password="admin", protocol="http")
# node.add_basicauth("admin", "admin")
app.add_node(node)
app.discover_systems()
print(f'Found systems: {app._systems}')
# assert len(systems) == 1
# assert systems[0] == node.get_api_endpoint()
def test_oshconnect_find_datastreams(self):
app = OSHConnect(name="Test OSH Connect")
node = Node(address="localhost", port=self.TEST_PORT, username="admin", password="admin", protocol="http")
app.add_node(node)
app.discover_systems()
app.discover_datastreams()
assert len(app._datastreams) > 0
async def test_obs_ws_stream(self):
ds_url = (
"ws://localhost:8282/sensorhub/api/datastreams/038q16egp1t0/observations?resultTime=latest"
"/2026-01-01T12:00:00Z&f=application%2Fjson")
# stream = requests.get(ds_url, stream=True, auth=('admin', 'admin'))
async with websockets.connect(ds_url, extra_headers={'Authorization': 'Basic YWRtaW46YWRtaW4='}) as stream:
async for message in stream:
print(message)