-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
86 lines (69 loc) · 2.63 KB
/
test.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
79
80
81
82
83
84
85
86
#!/usr/bin/env python
from unittest.mock import MagicMock
from unittest import TestCase
import unittest
from shapely.measurement import area
from BeachMap import BeachMap
from BeachBot import BeachBot
from mastodon import Mastodon
import json
def load_date() -> list:
with open("areas.json", "r") as reader:
geojson = json.load(reader)
return geojson
class TestBeachBot(TestCase):
@classmethod
def setUpClass(cls):
cls.mastodon = Mastodon(
access_token="token",
api_base_url="server"
)
# cls.mastodon.status_post = MagicMock(return_value={'id': 12345})
# cls.mastodon.media_post = MagicMock(return_value={'id': 54321})
cls.mastodon.status_post = MagicMock()
cls.mastodon.media_post = MagicMock()
with open("areas.json", "r") as reader:
cls.areas = json.load(reader)
with open("tests/geojson-fixture-tidy.json", "r") as reader:
cls.geojson = json.load(reader)
def testToot(self):
bb = BeachBot(self.mastodon, self.areas, self.geojson, 500, "Australia/Sydney")
bb.do_all_the_things()
# TODO: Confirm called with:
# 'Sydney beach pollution forecasts as of 01:30PM (AEST).\nCheck https://www.beachwatch.nsw.gov.au for details.\n#sydney #pollution #ocean\n'
# 'Pollution forecast for Eastern Suburbs:\n✅ Unlikely: Bondi Beach.\n'
self.mastodon.status_post.assert_called()
@classmethod
def tearDownClass(cls):
pass
class TestBeachMap(TestCase):
@classmethod
def setUpClass(cls):
cls.mastodon = Mastodon(
access_token="token",
api_base_url="server"
)
cls.mastodon.status_post = MagicMock({'id': 12345})
cls.mastodon.media_post = MagicMock({'id': 54321})
with open("areas.json", "r") as reader:
cls.areas = json.load(reader)
with open("tests/geojson-fixture.json", "r") as reader:
cls.geojson = json.load(reader)
def testMap(self):
bb = BeachBot(self.mastodon, self.areas, self.geojson, 500, "Australia/Sydney")
areas_data = [
{
"name": area["name"],
"data": bb.build_area_data(area, bb.geojson)
}
for area in bb.areas
]
for area_data in areas_data:
# Create BeachMap instance using area_data
# if area_data["name"] != "Sydney Harbour":
# continue
bm = BeachMap(area_data['name'], area_data['data'])
bm.draw_map()
print(areas_data)
if __name__ == "__main__":
unittest.main()