~davidc3/ubuntu-sdk-tutorials/scope-tutorial-settings-may2015

« back to all changes in this revision

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

  • Committer: David Callé
  • Date: 2015-05-20 22:02:45 UTC
  • Revision ID: davidc@framli.eu-20150520220245-fai23juqq7f6pb2q
Simple scope with settings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
 
 
3
from scope_harness import *
 
4
from scope_harness.testing import *
 
5
import unittest, sys, os
 
6
from subprocess import Popen, PIPE
 
7
 
 
8
class AppsTest (ScopeHarnessTestCase):
 
9
    @classmethod
 
10
    def setUpClass(cls):
 
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
 
14
 
 
15
    @classmethod
 
16
    def tearDownClass(cls):
 
17
        cls.process.terminate()
 
18
 
 
19
 
 
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
 
24
 
 
25
 
 
26
    def test_surfacing_results(self):
 
27
        self.start_harness()
 
28
        self.view.search_query = ''
 
29
 
 
30
        match = CategoryListMatcher() \
 
31
            .has_exactly(2) \
 
32
            .mode(CategoryListMatcherMode.BY_ID) \
 
33
            .category(CategoryMatcher("current") \
 
34
                .title("London, GB") \
 
35
                .has_at_least(1) \
 
36
                .result(ResultMatcher("5091") \
 
37
                    .title("21.8°C") \
 
38
                    .art("http://openweathermap.org/img/w/02d.png") \
 
39
                    .subtitle("few clouds") ) ) \
 
40
            .category(CategoryMatcher("forecast") \
 
41
                .title("7 day forecast") \
 
42
                .has_at_least(7) \
 
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)
 
73
 
 
74
 
 
75
    def test_search_results(self):
 
76
        self.start_harness()
 
77
        self.view.search_query = 'Manchester,uk'
 
78
 
 
79
        match = CategoryListMatcher() \
 
80
            .has_exactly(2) \
 
81
            .mode(CategoryListMatcherMode.BY_ID) \
 
82
            .category(CategoryMatcher("current") \
 
83
                .title("Manchester, GB") \
 
84
                .has_at_least(1) \
 
85
                .result(ResultMatcher("5060") \
 
86
                    .title("17.4°C") \
 
87
                    .art("http://openweathermap.org/img/w/03d.png") \
 
88
                    .subtitle("scattered clouds") ) ) \
 
89
            .category(CategoryMatcher("forecast") \
 
90
                .title("7 day forecast") \
 
91
                .has_at_least(7) \
 
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)
 
122
 
 
123
 
 
124
if __name__ == '__main__':
 
125
    SCOPE_NAME = sys.argv[1]
 
126
    SCOPE_INI = sys.argv[2]
 
127
    FAKE_SERVER = sys.argv[3]
 
128
 
 
129
    unittest.main(argv = sys.argv[:1])
 
130
 
 
131