~marcustomlinson/unity-js-scopes/lp-1541720

« back to all changes in this revision

Viewing changes to tests/owm_scope/tests/unit/test-scope.py

  • Committer: Marcus Tomlinson
  • Date: 2015-11-09 12:54:21 UTC
  • Revision ID: marcus.tomlinson@canonical.com-20151109125421-zuqmfdk1cvqir4dq
Added python scope-harness tests (starting with an OpenWeatherMap test scope)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
 
 
3
from scope_harness import (
 
4
    CategoryListMatcher, CategoryListMatcherMode, CategoryMatcher,
 
5
    Parameters, ResultMatcher, ScopeHarness
 
6
)
 
7
from scope_harness.testing import *
 
8
import unittest, sys, os
 
9
from subprocess import Popen, PIPE
 
10
 
 
11
class AppsTest (ScopeHarnessTestCase):
 
12
    @classmethod
 
13
    def setUpClass(cls):
 
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
 
18
 
 
19
    @classmethod
 
20
    def tearDownClass(cls):
 
21
        cls.process.terminate()
 
22
 
 
23
 
 
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
 
28
 
 
29
 
 
30
    def test_surfacing_results(self):
 
31
        self.start_harness()
 
32
        self.view.search_query = ''
 
33
 
 
34
        match = CategoryListMatcher() \
 
35
            .has_exactly(2) \
 
36
            .mode(CategoryListMatcherMode.BY_ID) \
 
37
            .category(CategoryMatcher("current") \
 
38
                .title("London, GB") \
 
39
                .has_at_least(1) \
 
40
                .result(ResultMatcher("2643743") \
 
41
                    .title("21.83°C") \
 
42
                    .art("http://openweathermap.org/img/w/02d.png") \
 
43
                    .subtitle("few clouds") ) ) \
 
44
            .category(CategoryMatcher("forecast") \
 
45
                .title("7 day forecast") \
 
46
                .has_at_least(7) \
 
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)
 
77
 
 
78
 
 
79
    def test_search_results(self):
 
80
        self.start_harness()
 
81
        self.view.search_query = 'Manchester,uk'
 
82
 
 
83
        match = CategoryListMatcher() \
 
84
            .has_exactly(2) \
 
85
            .mode(CategoryListMatcherMode.BY_ID) \
 
86
            .category(CategoryMatcher("current") \
 
87
                .title("Manchester, GB") \
 
88
                .has_at_least(1) \
 
89
                .result(ResultMatcher("2643123") \
 
90
                    .title("17.35°C") \
 
91
                    .art("http://openweathermap.org/img/w/03d.png") \
 
92
                    .subtitle("scattered clouds") ) ) \
 
93
            .category(CategoryMatcher("forecast") \
 
94
                .title("7 day forecast") \
 
95
                .has_at_least(7) \
 
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)
 
126
 
 
127
 
 
128
if __name__ == '__main__':
 
129
    SCOPE_NAME = sys.argv[1]
 
130
    SCOPE_INI = sys.argv[2]
 
131
    FAKE_SERVER = sys.argv[3]
 
132
 
 
133
    unittest.main(argv = sys.argv[:1])