Merge lp:~om26er/messaging-app/fix-test-1418074 into lp:messaging-app

Proposed by Omer Akram
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 304
Merged at revision: 308
Proposed branch: lp:~om26er/messaging-app/fix-test-1418074
Merge into: lp:messaging-app
Diff against target: 180 lines (+85/-47)
2 files modified
tests/autopilot/messaging_app/fixture_setup.py (+35/-0)
tests/autopilot/messaging_app/tests/test_messaging.py (+50/-47)
To merge this branch: bzr merge lp:~om26er/messaging-app/fix-test-1418074
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+248582@code.launchpad.net

Commit message

Provide a pre-populated database for search test so that we don't conflict with the On Screen Display Notification

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
304. By Omer Akram

fix testdata location reference

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good and works as expected!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/messaging_app/fixture_setup.py'
2--- tests/autopilot/messaging_app/fixture_setup.py 2014-09-10 16:54:37 +0000
3+++ tests/autopilot/messaging_app/fixture_setup.py 2015-02-06 16:04:16 +0000
4@@ -10,16 +10,22 @@
5 import dbus
6 import os
7 import subprocess
8+import shutil
9
10 import fixtures
11
12
13 class MessagingTestEnvironment(fixtures.Fixture):
14
15+ def __init__(self, use_testdata_db=False):
16+ self.use_testdata_db = use_testdata_db
17+
18 def setUp(self):
19 super(MessagingTestEnvironment, self).setUp()
20 self.useFixture(OfonoPhoneSIM())
21 self.useFixture(BackupHistory())
22+ if self.use_testdata_db:
23+ self.useFixture(FillCustomSmsHistory())
24 self.useFixture(RespawnService())
25
26
27@@ -45,6 +51,35 @@
28 os.rename(self.history + '.orig', self.history)
29
30
31+class FillCustomSmsHistory(fixtures.Fixture):
32+
33+ history_service_dir = os.path.expanduser("~/.local/share/history-service/")
34+ history_db = "history.sqlite"
35+ testdata_sys = "/usr/lib/python3/dist-packages/messaging_app/testdata/"
36+ testdata_local = "messaging_app/testdata/"
37+
38+ prefilled_history_local = os.path.join(testdata_local, history_db)
39+ prefilled_history_system = os.path.join(testdata_sys, history_db)
40+
41+ def setUp(self):
42+ super(FillCustomSmsHistory, self).setUp()
43+ self.addCleanup(self._clear_test_data())
44+ self._copy_test_data_history()
45+
46+ def _copy_test_data_history(self):
47+ if os.path.exists(self.prefilled_history_local):
48+ shutil.copy(
49+ self.prefilled_history_local, self.history_service_dir)
50+ else:
51+ shutil.copy(
52+ self.prefilled_history_system, self.history_service_dir)
53+
54+ def _clear_test_data(self):
55+ test_data = os.path.join(self.history_service_dir, self.history_db)
56+ if os.path.exists(test_data):
57+ os.remove(test_data)
58+
59+
60 class RespawnService(fixtures.Fixture):
61
62 def setUp(self):
63
64=== added directory 'tests/autopilot/messaging_app/testdata'
65=== added file 'tests/autopilot/messaging_app/testdata/history.sqlite'
66Binary files tests/autopilot/messaging_app/testdata/history.sqlite 1970-01-01 00:00:00 +0000 and tests/autopilot/messaging_app/testdata/history.sqlite 2015-02-06 16:04:16 +0000 differ
67=== modified file 'tests/autopilot/messaging_app/tests/test_messaging.py'
68--- tests/autopilot/messaging_app/tests/test_messaging.py 2015-01-24 20:32:58 +0000
69+++ tests/autopilot/messaging_app/tests/test_messaging.py 2015-02-06 16:04:16 +0000
70@@ -300,53 +300,6 @@
71 list_view = self.main_view.get_multiple_selection_list_view()
72 self.assertThat(list_view.count, Eventually(Equals(0)))
73
74- def test_search_for_message(self):
75- def count_visible_threads(threads):
76- count = 0
77- for thread in threads:
78- if thread.height != 0:
79- count += 1
80- return count
81-
82- # populate history
83- helpers.receive_sms('08151', 'Ubuntu')
84- helpers.receive_sms('08152', 'Ubuntu1')
85- helpers.receive_sms('08153', 'Ubuntu2')
86- helpers.receive_sms('08154', 'Ubuntu22')
87- helpers.receive_sms('08155', 'Ubuntu23')
88-
89- # verify that we got the messages
90- self.assertThat(self.thread_list.count, Eventually(Equals(5)))
91- threads = self.thread_list.select_many('ThreadDelegate')
92-
93- # tap search
94- self.main_view.click_header_action('searchAction')
95- text_field = self.main_view.select_single(
96- ubuntuuitoolkit.TextField,
97- objectName='searchField')
98-
99- text_field.write('Ubuntu2')
100- self.assertThat(
101- lambda: count_visible_threads(threads), Eventually(Equals(3)))
102-
103- text_field.clear()
104- text_field.write('Ubuntu1')
105- self.assertThat(
106- lambda: count_visible_threads(threads), Eventually(Equals(1)))
107-
108- text_field.clear()
109- text_field.write('Ubuntu')
110- self.assertThat(
111- lambda: count_visible_threads(threads), Eventually(Equals(5)))
112-
113- text_field.clear()
114- text_field.write('%')
115- # as we are testing for items NOT to appear, there is no other way
116- # other than sleeping for awhile before checking if the threads are
117- # visible
118- time.sleep(5)
119- self.assertThat(count_visible_threads(threads), Equals(0))
120-
121
122 class MessagingTestCaseWithExistingThread(BaseMessagingTestCase):
123
124@@ -393,6 +346,56 @@
125 remaining_message_text, self.messages[0])
126
127
128+class MessagingTestSearch(MessagingAppTestCase):
129+
130+ def setUp(self):
131+ test_setup = fixture_setup.MessagingTestEnvironment(
132+ use_testdata_db=True)
133+ self.useFixture(test_setup)
134+ super(MessagingTestSearch, self).setUp()
135+ self.thread_list = self.app.select_single(objectName='threadList')
136+
137+ def test_search_for_message(self):
138+ def count_visible_threads(threads):
139+ count = 0
140+ for thread in threads:
141+ if thread.height != 0:
142+ count += 1
143+ return count
144+
145+ # verify that we got the messages
146+ self.assertThat(self.thread_list.count, Eventually(Equals(5)))
147+ threads = self.thread_list.select_many('ThreadDelegate')
148+
149+ # tap search
150+ self.main_view.click_header_action('searchAction')
151+ text_field = self.main_view.select_single(
152+ ubuntuuitoolkit.TextField,
153+ objectName='searchField')
154+
155+ text_field.write('Ubuntu2')
156+ self.assertThat(
157+ lambda: count_visible_threads(threads), Eventually(Equals(3)))
158+
159+ text_field.clear()
160+ text_field.write('Ubuntu1')
161+ self.assertThat(
162+ lambda: count_visible_threads(threads), Eventually(Equals(1)))
163+
164+ text_field.clear()
165+ text_field.write('Ubuntu')
166+ self.assertThat(
167+ lambda: count_visible_threads(threads), Eventually(Equals(5)))
168+
169+ text_field.clear()
170+ text_field.write('%')
171+ # as we are testing for items NOT to appear, there is no other way
172+ # other than sleeping for awhile before checking if the threads are
173+ # visible
174+ time.sleep(5)
175+ self.assertThat(count_visible_threads(threads), Equals(0))
176+
177+
178 class MessagingTestCaseWithArgument(MessagingAppTestCase):
179
180 def setUp(self):

Subscribers

People subscribed via source and target branches