Merge lp:~tiagosh/messaging-app/online-modem-for-tests into lp:messaging-app

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 123
Merged at revision: 129
Proposed branch: lp:~tiagosh/messaging-app/online-modem-for-tests
Merge into: lp:messaging-app
Diff against target: 116 lines (+68/-14)
2 files modified
tests/autopilot/messaging_app/helpers.py (+66/-0)
tests/autopilot/messaging_app/tests/__init__.py (+2/-14)
To merge this branch: bzr merge lp:~tiagosh/messaging-app/online-modem-for-tests
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+225176@code.launchpad.net

Commit message

Force modem to go online during tests.

Description of the change

Force modem to go online during tests.

-- Checklist --
Are there any related MPs required for this MP to build/function as expected? Please list.
No

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)
Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?
Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/messaging-app) on device or emulator?
Yes

If you changed the UI, was the change specified/approved by design?
N/A

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?
N/A

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
Yes

Did CI run pass? If not, please explain why.
Yes

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
Yes

Code looks good and works as expected!

review: Approve
124. By Tiago Salem Herrmann

fix test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/messaging_app/helpers.py'
2--- tests/autopilot/messaging_app/helpers.py 2014-06-04 17:46:01 +0000
3+++ tests/autopilot/messaging_app/helpers.py 2014-07-08 23:14:09 +0000
4@@ -11,6 +11,10 @@
5 import os
6 import shutil
7 import tempfile
8+import subprocess
9+import sys
10+import time
11+from dbus import exceptions
12
13
14 def receive_sms(sender, text):
15@@ -38,3 +42,65 @@
16 script_proxy.SetPath(script_dir)
17 script_proxy.Run("sms.js")
18 shutil.rmtree(script_dir)
19+
20+
21+def get_phonesim():
22+ bus = dbus.SystemBus()
23+ try:
24+ manager = dbus.Interface(bus.get_object('org.ofono', '/'),
25+ 'org.ofono.Manager')
26+ except dbus.exceptions.DBusException:
27+ return False
28+
29+ modems = manager.GetModems()
30+
31+ for path, properties in modems:
32+ if path == '/phonesim':
33+ return properties
34+
35+ return None
36+
37+
38+def is_phonesim_running():
39+ """Determine whether we are running with phonesim."""
40+ phonesim = get_phonesim()
41+ return phonesim is not None
42+
43+
44+def ensure_ofono_account():
45+ # oFono modems are now set online by NetworkManager, so for the tests
46+ # we need to manually put them online.
47+ subprocess.check_call(['/usr/share/ofono/scripts/enable-modem',
48+ '/phonesim'])
49+ subprocess.check_call(['/usr/share/ofono/scripts/online-modem',
50+ '/phonesim'])
51+
52+ # wait until the modem is actually online
53+ for index in range(10):
54+ phonesim = get_phonesim()
55+ if phonesim['Online'] == 1:
56+ break
57+ time.sleep(1)
58+ else:
59+ raise exceptions.RuntimeError("oFono simulator didn't get online.")
60+
61+ # this is a bit drastic, but sometimes mission-control-5 won't recognize
62+ # clients installed after it was started, so, we make sure it gets
63+ # restarted
64+ subprocess.check_call(['pkill', '-9', 'mission-control'])
65+
66+ if not _is_ofono_account_set():
67+ subprocess.check_call(['ofono-setup'])
68+ if not _is_ofono_account_set():
69+ sys.stderr.write('ofono-setup failed to create ofono account!\n')
70+ sys.exit(1)
71+
72+
73+def _is_ofono_account_set():
74+ mc_tool = subprocess.Popen(
75+ [
76+ 'mc-tool',
77+ 'list',
78+ ], stdout=subprocess.PIPE, universal_newlines=True)
79+ mc_accounts = mc_tool.communicate()[0]
80+ return 'ofono/ofono/account' in mc_accounts
81
82=== modified file 'tests/autopilot/messaging_app/tests/__init__.py'
83--- tests/autopilot/messaging_app/tests/__init__.py 2014-06-25 07:21:10 +0000
84+++ tests/autopilot/messaging_app/tests/__init__.py 2014-07-08 23:14:09 +0000
85@@ -16,29 +16,17 @@
86 from testtools.matchers import Equals
87
88 from ubuntuuitoolkit import emulators as toolkit_emulators
89-from messaging_app import emulators
90+from messaging_app import emulators, helpers
91
92 import os
93-import sys
94 import logging
95 import subprocess
96
97 logger = logging.getLogger(__name__)
98
99-
100 # ensure we have an ofono account; we assume that we have these tools,
101 # otherwise we consider this a test failure (missing dependencies)
102-def tp_has_ofono():
103- mc_tool = subprocess.Popen(['mc-tool', 'list'], stdout=subprocess.PIPE,
104- universal_newlines=True)
105- mc_accounts = mc_tool.communicate()[0]
106- return 'ofono/ofono/account' in mc_accounts
107-
108-if not tp_has_ofono():
109- subprocess.check_call(['ofono-setup'])
110- if not tp_has_ofono():
111- sys.stderr.write('ofono-setup failed to create ofono account!\n')
112- sys.exit(1)
113+helpers.ensure_ofono_account()
114
115
116 class MessagingAppTestCase(AutopilotTestCase):

Subscribers

People subscribed via source and target branches