-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_uploadMeasurementHandler.py
More file actions
70 lines (53 loc) · 1.78 KB
/
test_uploadMeasurementHandler.py
File metadata and controls
70 lines (53 loc) · 1.78 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
from unittest.mock import Mock
import handler
from flask import Flask
def test_uploadMeasurementHandler_constructor():
m = Mock()
h = handler.UploadMeasurementHandler(addMeasurementFunc=m)
assert h._addMeasurement == m
def test_post_standard_notecard_event():
app = Flask(__name__)
m = Mock()
d = standardNotehubEvent
h = handler.UploadMeasurementHandler(addMeasurementFunc=m)
with app.test_request_context('/',method='POST',json=d):
r = h.dispatch_request()
m.assert_called_once_with(d["device"],d["when"],d["body"]["type"],d["body"]["value"],d["body"]["units"])
def test_post_response():
app = Flask(__name__)
m = Mock()
d = standardNotehubEvent
h = handler.UploadMeasurementHandler(addMeasurementFunc=m)
with app.test_request_context('/',method='POST',json=d):
r = h.dispatch_request()
assert r[1] == 200
standardNotehubEvent = {
"event": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"session": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"best_id": "dev:xxxxxxxxxxxxxxx",
"device": "dev:xxxxxxxxxxxxxxx",
"product": "product:com.email.myname:uid",
"received": 1627495495.552799,
"routed": 1627495495,
"req": "note.add",
"when": 1627495494,
"file": "data.qo",
"body": {
"type": "type1",
"value": 13.3,
"units":"unit1"
},
"best_location_type": "tower",
"best_lat": 47.0001,
"best_lon": -73.0001,
"best_location": "Somewhere MA",
"best_country": "US",
"best_timezone": "America/New_York",
"tower_when": 1627494970,
"tower_lat": 47.0001,
"tower_lon": -73.0001,
"tower_country": "US",
"tower_location": "Somewhere MA",
"tower_timezone": "America/New_York",
"tower_id": "310,410,1049,15864835",
}