3
from scope_harness import *
4
from scope_harness.testing import *
5
import unittest, sys, os
6
from subprocess import Popen, PIPE
8
class AppsTest (ScopeHarnessTestCase):
11
cls.process = Popen(["/usr/bin/python3", FAKE_SERVER], stdout=PIPE)
12
port = cls.process.stdout.readline().decode("utf-8").rstrip('\n')
13
os.environ["NETWORK_SCOPE_APIROOT"] = "http://127.0.0.1:" + port
16
def tearDownClass(cls):
17
cls.process.terminate()
20
def start_harness(self):
21
self.harness = ScopeHarness.new_from_scope_list(Parameters([SCOPE_INI]))
22
self.view = self.harness.results_view
23
self.view.active_scope = SCOPE_NAME
26
def test_surfacing_results(self):
28
self.view.search_query = ''
30
match = CategoryListMatcher() \
32
.mode(CategoryListMatcherMode.BY_ID) \
33
.category(CategoryMatcher("current") \
34
.title("London, GB") \
36
.result(ResultMatcher("5091") \
38
.art("http://openweathermap.org/img/w/02d.png") \
39
.subtitle("few clouds") ) ) \
40
.category(CategoryMatcher("forecast") \
41
.title("7 day forecast") \
43
.result(ResultMatcher("500") \
44
.title("25.1°C to 18.8°C") \
45
.art("http://openweathermap.org/img/w/10d.png") \
46
.subtitle("light rain") ) \
47
.result(ResultMatcher("501") \
48
.title("20.9°C to 15.5°C") \
49
.art("http://openweathermap.org/img/w/10d.png") \
50
.subtitle("moderate rain") ) \
51
.result(ResultMatcher("802") \
52
.title("19.6°C to 13.2°C") \
53
.art("http://openweathermap.org/img/w/03d.png") \
54
.subtitle("scattered clouds") ) \
55
.result(ResultMatcher("501") \
56
.title("18.1°C to 13.5°C") \
57
.art("http://openweathermap.org/img/w/10d.png") \
58
.subtitle("moderate rain") ) \
59
.result(ResultMatcher("502") \
60
.title("17.4°C to 15.4°C") \
61
.art("http://openweathermap.org/img/w/10d.png") \
62
.subtitle("heavy intensity rain") ) \
63
.result(ResultMatcher("501") \
64
.title("18.4°C to 16.2°C") \
65
.art("http://openweathermap.org/img/w/10d.png") \
66
.subtitle("moderate rain") ) \
67
.result(ResultMatcher("500") \
68
.title("19°C to 16.7°C") \
69
.art("http://openweathermap.org/img/w/10d.png") \
70
.subtitle("light rain") ) ) \
71
.match(self.view.categories)
72
self.assertMatchResult(match)
75
def test_search_results(self):
77
self.view.search_query = 'Manchester,uk'
79
match = CategoryListMatcher() \
81
.mode(CategoryListMatcherMode.BY_ID) \
82
.category(CategoryMatcher("current") \
83
.title("Manchester, GB") \
85
.result(ResultMatcher("5060") \
87
.art("http://openweathermap.org/img/w/03d.png") \
88
.subtitle("scattered clouds") ) ) \
89
.category(CategoryMatcher("forecast") \
90
.title("7 day forecast") \
92
.result(ResultMatcher("800") \
93
.title("18.8°C to 12°C") \
94
.art("http://openweathermap.org/img/w/01d.png") \
95
.subtitle("sky is clear") ) \
96
.result(ResultMatcher("501") \
97
.title("18.6°C to 12.3°C") \
98
.art("http://openweathermap.org/img/w/10d.png") \
99
.subtitle("moderate rain") ) \
100
.result(ResultMatcher("803") \
101
.title("17.1°C to 10.8°C") \
102
.art("http://openweathermap.org/img/w/04d.png") \
103
.subtitle("broken clouds") ) \
104
.result(ResultMatcher("501") \
105
.title("16°C to 12.2°C") \
106
.art("http://openweathermap.org/img/w/10d.png") \
107
.subtitle("moderate rain") ) \
108
.result(ResultMatcher("500") \
109
.title("15.7°C to 13°C") \
110
.art("http://openweathermap.org/img/w/10d.png") \
111
.subtitle("light rain") ) \
112
.result(ResultMatcher("501") \
113
.title("17.6°C to 14.1°C") \
114
.art("http://openweathermap.org/img/w/10d.png") \
115
.subtitle("moderate rain") ) \
116
.result(ResultMatcher("501") \
117
.title("15.5°C to 13.4°C") \
118
.art("http://openweathermap.org/img/w/10d.png") \
119
.subtitle("moderate rain") ) ) \
120
.match(self.view.categories)
121
self.assertMatchResult(match)
124
if __name__ == '__main__':
125
SCOPE_NAME = sys.argv[1]
126
SCOPE_INI = sys.argv[2]
127
FAKE_SERVER = sys.argv[3]
129
unittest.main(argv = sys.argv[:1])