Merge lp:~elopio/u1-test-utils/smart_scopes_tests into lp:~canonical-isd-hackers/u1-test-utils/test-in-dash-payments

Proposed by Leo Arias
Status: Rejected
Rejected by: Natalia Bidart
Proposed branch: lp:~elopio/u1-test-utils/smart_scopes_tests
Merge into: lp:~canonical-isd-hackers/u1-test-utils/test-in-dash-payments
Diff against target: 143 lines (+91/-2)
3 files modified
tests/dash.py (+50/-2)
tests/schema.py (+4/-0)
tests/test_smart_scopes.py (+37/-0)
To merge this branch: bzr merge lp:~elopio/u1-test-utils/smart_scopes_tests
Reviewer Review Type Date Requested Status
Vincent Ladeuil (community) Needs Information
Review via email: mp+170969@code.launchpad.net
To post a comment you must log in.
66. By Leo Arias

Preview the result.

67. By Leo Arias

Click the View button.

68. By Leo Arias

Check the URL on the browser.

Revision history for this message
Vincent Ladeuil (vila) wrote :

26 +def _wait_for_result_settle(test):

Why don't you use Eventually here ?

It seems unlikely that the code will loop forever but it can be exited with 0 rows. Why not use a specific number of rows and an overall timeout (which Eventually implements) instead ?

review: Needs Information
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Setting MP as Rejected because is more than 500 days old, and did not have any activity recorded. Change status again if this MP is still current, and please ping someone for review and landing.
Thanks!

Unmerged revisions

68. By Leo Arias

Check the URL on the browser.

67. By Leo Arias

Click the View button.

66. By Leo Arias

Preview the result.

65. By Leo Arias

Added the first part of the first scope search test.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/dash.py'
2--- tests/dash.py 2013-06-19 20:35:04 +0000
3+++ tests/dash.py 2013-06-23 07:46:25 +0000
4@@ -1,3 +1,7 @@
5+import time
6+
7+import unity.emulators.dash
8+from autopilot import input
9 from autopilot.matchers import Eventually
10 from testtools.matchers import (
11 Equals,
12@@ -6,6 +10,36 @@
13 )
14
15
16+def search_home_scope(test, query):
17+ test.addCleanup(test.unity.dash.ensure_hidden)
18+ test.unity.dash.ensure_visible()
19+ test.addCleanup(test.unity.dash.clear_search)
20+ test.keyboard.type(query)
21+ _wait_for_result_settle(test)
22+
23+
24+# Copied from unity tests. TODO move it to the unity emulator.
25+# --elopio -2013-06-22
26+def _wait_for_result_settle(test):
27+ """wait for row count to settle"""
28+ old_row_count = -1
29+ new_row_count = test.unity.dash.get_num_rows()
30+ while(old_row_count != new_row_count):
31+ time.sleep(1)
32+ old_row_count = new_row_count
33+ new_row_count = test.unity.dash.get_num_rows()
34+
35+
36+def get_result_from_category_by_name(test, name, category_name):
37+ current_scope = test.unity.dash.get_current_scope()
38+ category = current_scope.get_category_by_name(category_name)
39+ test.assertTrue(category.is_visible)
40+ for result in category.get_results():
41+ if result.name == name:
42+ return result
43+ return None
44+
45+
46 def search_music_scope(test, query):
47 test.addCleanup(test.unity.dash.ensure_hidden)
48 test.unity.dash.reveal_music_scope()
49@@ -37,6 +71,7 @@
50 def preview_result(test, result):
51 current_scope = test.unity.dash.get_current_scope()
52 test.assertThat(current_scope.get_num_visible_categories(), GreaterThan(0))
53+ test.addCleanup(ensure_preview_closed, test)
54 result.preview()
55 _wait_for_preview_animation(test)
56
57@@ -66,7 +101,21 @@
58 Eventually(NotEquals(None)))
59 container = test.unity.dash.view.get_preview_container()
60 test.assertThat(container.waiting_preview, Eventually(Equals(False)))
61- return container.current_preview
62+ return container.current_preview
63+
64+
65+def execute_preview_action_by_label(test, preview, label):
66+ # XXX Most of this code comes from the unity Preview emulator, that clicks
67+ # an action by its id. On the smart scopes, the id is the URL, not nice.
68+ # Ask David Calle -- elopio - 2013-06-23
69+ actions = preview.get_children_by_type(unity.emulators.dash.ActionButton)
70+ for action in actions:
71+ if action.label == label:
72+ tx = action.x + (action.width / 2)
73+ ty = action.y + (action.height / 2)
74+ m = input.Mouse.create()
75+ m.move(tx, ty)
76+ m.click()
77
78
79 class Window(object):
80@@ -86,7 +135,6 @@
81 def get_preview(self, test, good):
82 search_music_scope(test, good.search)
83 result = self.get_result(test)
84- test.addCleanup(ensure_preview_closed, test)
85 preview_result(test, result)
86 # We have the preview now
87 return Preview(self.user, good)
88
89=== modified file 'tests/schema.py'
90--- tests/schema.py 2013-05-23 23:27:05 +0000
91+++ tests/schema.py 2013-06-23 07:46:25 +0000
92@@ -18,5 +18,9 @@
93 class musicsearch(schema.Section):
94 musicsearch_server_url = schema.StringOption()
95
96+ class smartscopes(schema.Section):
97+ smartscopes_server_url = schema.StringOption()
98+ smartscopes_geo_store = schema.StringOption()
99+
100
101 schema = InDashPaymentsSchema
102
103=== added file 'tests/test_smart_scopes.py'
104--- tests/test_smart_scopes.py 1970-01-01 00:00:00 +0000
105+++ tests/test_smart_scopes.py 2013-06-23 07:46:25 +0000
106@@ -0,0 +1,37 @@
107+import os
108+import subprocess
109+
110+# FIXME do not use django config to get the server settings.
111+# -- elopio - 2013-05-15
112+from django import conf
113+
114+import tests
115+from tests import browsers, dash
116+
117+
118+class SmartScopesSearchTestCase(tests.UnitySSTestcase):
119+
120+ def setUp(self):
121+ super(SmartScopesSearchTestCase, self).setUp()
122+ self._run_home_scope()
123+
124+ def _run_home_scope(self):
125+ os.environ['SMART_SCOPES_SERVER"'] = (
126+ conf.settings.SMARTSCOPES_SERVER_URL)
127+ os.environ['SMART_SCOPES_GEO_STORE'] = (
128+ conf.settings.SMARTSCOPES_GEO_STORE)
129+ os.system('pkill unity-scope-home*')
130+ subprocess.Popen(
131+ '/usr/lib/x86_64-linux-gnu/unity-scope-home/unity-scope-home')
132+
133+ def test_search_wikipedia(self):
134+ dash.search_home_scope(self, 'wikipedia:Test')
135+ result = dash.get_result_from_category_by_name(
136+ self, 'Test', 'Reference')
137+ dash.preview_result(self, result)
138+ preview = dash.get_current_preview(self)
139+ dash.execute_preview_action_by_label(self, preview, 'View')
140+ browser = browsers.Browser(self)
141+ # We've been redirected to the web
142+ browser.switch_to_new_window(self)
143+ self.assertEqual(browser.url, 'http://en.wikipedia.org/wiki/Test')

Subscribers

People subscribed via source and target branches