-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
65 lines (50 loc) · 2.11 KB
/
tests.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
from GovWeatherAlertInterface import GovWeatherAlertInterface
from Processor import Processor
class MockNetworkInterface:
def __init__(self):
self.counter = 122
# IDs will start at 123 and then increment each time
def get(self, url):
self.counter += 1
return {"features": [{"id": self.counter, "properties": {"headline": "testHeadline", "description": "testDescription", "instruction": "testInstruction"}}]}
class MockMessageInterface:
def __init__(self):
pass
def sendMessage(self, str):
return True
class MockDatabaseInterface:
def __init__(self, mockInDBResult):
self.mockInDBResult = mockInDBResult
def isInDB(self, id):
return self.mockInDBResult
def addToDB(self, id):
pass
events = GovWeatherAlertInterface(
MockNetworkInterface(), ['test'], ['test']).getEvents()
assert len(events) == 2
assert events[123] == "testHeadline\ntestDescription\ntestInstruction\n"
assert events[124] == "testHeadline\ntestDescription\ntestInstruction\n"
results = Processor(
weatherInterface=GovWeatherAlertInterface(
MockNetworkInterface(), ['test'], ['test']),
messageInterface=MockMessageInterface(),
databaseInterface=None).process()
assert len(results) == 2
assert results[0] == (123, "testHeadline\ntestDescription\ntestInstruction\n")
assert results[1] == (124, "testHeadline\ntestDescription\ntestInstruction\n")
results = Processor(
weatherInterface=GovWeatherAlertInterface(
MockNetworkInterface(), ['test'], ['test']),
messageInterface=MockMessageInterface(),
databaseInterface=MockDatabaseInterface(False)).process()
assert len(results) == 2
assert results[0] == (123, "testHeadline\ntestDescription\ntestInstruction\n")
assert results[1] == (124, "testHeadline\ntestDescription\ntestInstruction\n")
results = Processor(
weatherInterface=GovWeatherAlertInterface(
MockNetworkInterface(), ['test'], ['test']),
messageInterface=MockMessageInterface(),
databaseInterface=MockDatabaseInterface(True)).process()
assert len(results) == 2
assert results[0] == None
assert results[1] == None