3
from scope_harness import (
4
CategoryListMatcher, CategoryListMatcherMode, CategoryMatcher,
5
Parameters, ResultMatcher, ScopeHarness
7
from scope_harness.testing import *
8
import unittest, sys, os
9
from subprocess import Popen, PIPE
11
class AppsTest (ScopeHarnessTestCase):
14
cls.process = Popen(["/usr/bin/python3", FAKE_SERVER], stdout=PIPE)
15
port = cls.process.stdout.readline().decode("utf-8").rstrip('\n')
16
os.environ["NETWORK_SCOPE_APIROOT"] = "localhost"
17
os.environ["NETWORK_SCOPE_APIPORT"] = port
20
def tearDownClass(cls):
21
cls.process.terminate()
24
def start_harness(self):
25
self.harness = ScopeHarness.new_from_scope_list(Parameters([SCOPE_INI]))
26
self.view = self.harness.results_view
27
self.view.active_scope = SCOPE_NAME
30
def test_surfacing_results(self):
32
self.view.search_query = ''
34
match = CategoryListMatcher() \
36
.mode(CategoryListMatcherMode.BY_ID) \
37
.category(CategoryMatcher("current") \
38
.title("London, GB") \
40
.result(ResultMatcher("2643743") \
42
.art("http://openweathermap.org/img/w/02d.png") \
43
.subtitle("few clouds") ) ) \
44
.category(CategoryMatcher("forecast") \
45
.title("7 day forecast") \
47
.result(ResultMatcher("500") \
48
.title("18.84°C to 25.09°C") \
49
.art("http://openweathermap.org/img/w/10d.png") \
50
.subtitle("light rain") ) \
51
.result(ResultMatcher("501") \
52
.title("15.54°C to 20.86°C") \
53
.art("http://openweathermap.org/img/w/10d.png") \
54
.subtitle("moderate rain") ) \
55
.result(ResultMatcher("802") \
56
.title("13.19°C to 19.58°C") \
57
.art("http://openweathermap.org/img/w/03d.png") \
58
.subtitle("scattered clouds") ) \
59
.result(ResultMatcher("501") \
60
.title("13.46°C to 18.09°C") \
61
.art("http://openweathermap.org/img/w/10d.png") \
62
.subtitle("moderate rain") ) \
63
.result(ResultMatcher("502") \
64
.title("15.39°C to 17.38°C") \
65
.art("http://openweathermap.org/img/w/10d.png") \
66
.subtitle("heavy intensity rain") ) \
67
.result(ResultMatcher("501") \
68
.title("16.17°C to 18.44°C") \
69
.art("http://openweathermap.org/img/w/10d.png") \
70
.subtitle("moderate rain") ) \
71
.result(ResultMatcher("500") \
72
.title("16.67°C to 19.02°C") \
73
.art("http://openweathermap.org/img/w/10d.png") \
74
.subtitle("light rain") ) ) \
75
.match(self.view.categories)
76
self.assertMatchResult(match)
79
def test_search_results(self):
81
self.view.search_query = 'Manchester,uk'
83
match = CategoryListMatcher() \
85
.mode(CategoryListMatcherMode.BY_ID) \
86
.category(CategoryMatcher("current") \
87
.title("Manchester, GB") \
89
.result(ResultMatcher("2643123") \
91
.art("http://openweathermap.org/img/w/03d.png") \
92
.subtitle("scattered clouds") ) ) \
93
.category(CategoryMatcher("forecast") \
94
.title("7 day forecast") \
96
.result(ResultMatcher("800") \
97
.title("11.96°C to 18.83°C") \
98
.art("http://openweathermap.org/img/w/01d.png") \
99
.subtitle("sky is clear") ) \
100
.result(ResultMatcher("501") \
101
.title("12.33°C to 18.59°C") \
102
.art("http://openweathermap.org/img/w/10d.png") \
103
.subtitle("moderate rain") ) \
104
.result(ResultMatcher("803") \
105
.title("10.79°C to 17.11°C") \
106
.art("http://openweathermap.org/img/w/04d.png") \
107
.subtitle("broken clouds") ) \
108
.result(ResultMatcher("501") \
109
.title("12.21°C to 15.98°C") \
110
.art("http://openweathermap.org/img/w/10d.png") \
111
.subtitle("moderate rain") ) \
112
.result(ResultMatcher("500") \
113
.title("12.99°C to 15.73°C") \
114
.art("http://openweathermap.org/img/w/10d.png") \
115
.subtitle("light rain") ) \
116
.result(ResultMatcher("501") \
117
.title("14.08°C to 17.64°C") \
118
.art("http://openweathermap.org/img/w/10d.png") \
119
.subtitle("moderate rain") ) \
120
.result(ResultMatcher("501") \
121
.title("13.37°C to 15.52°C") \
122
.art("http://openweathermap.org/img/w/10d.png") \
123
.subtitle("moderate rain") ) ) \
124
.match(self.view.categories)
125
self.assertMatchResult(match)
128
if __name__ == '__main__':
129
SCOPE_NAME = sys.argv[1]
130
SCOPE_INI = sys.argv[2]
131
FAKE_SERVER = sys.argv[3]
133
unittest.main(argv = sys.argv[:1])