Merge lp:~nskaggs/ubuntu-terminal-app/restore-autopilot into lp:~ubuntu-terminal-dev/ubuntu-terminal-app/reboot

Proposed by Nicholas Skaggs
Status: Merged
Approved by: Stefano Verzegnassi
Approved revision: 193
Merged at revision: 189
Proposed branch: lp:~nskaggs/ubuntu-terminal-app/restore-autopilot
Merge into: lp:~ubuntu-terminal-dev/ubuntu-terminal-app/reboot
Diff against target: 798 lines (+258/-482)
9 files modified
README.autopilot.md (+74/-0)
old-tests/CMakeLists.txt (+0/-1)
old-tests/autopilot/CMakeLists.txt (+0/-8)
old-tests/autopilot/ubuntu_terminal_app/__init__.py (+0/-174)
old-tests/autopilot/ubuntu_terminal_app/tests/__init__.py (+0/-131)
old-tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py (+0/-157)
tests/autopilot/ubuntu_terminal_app/__init__.py (+23/-1)
tests/autopilot/ubuntu_terminal_app/tests/__init__.py (+153/-1)
tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py (+8/-9)
To merge this branch: bzr merge lp:~nskaggs/ubuntu-terminal-app/restore-autopilot
Reviewer Review Type Date Requested Status
Stefano Verzegnassi Approve
Jenkins Bot continuous-integration Approve
Review via email: mp+288347@code.launchpad.net

Commit message

Add back templates for autopilot
add autopilot readme

Description of the change

Add back templates for autopilot
add autopilot readme

To post a comment you must log in.
191. By Nicholas Skaggs

undo pot change

Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
192. By Nicholas Skaggs

typos

Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :
Revision history for this message
Stefano Verzegnassi (verzegnassi-stefano) wrote :

Tested on my PC and it works well.
My only question is about Python coding style: should we still refer to the pep8 conventions?

PS. One diff comment included (i.e. music-app typo).

======

$ pep8 ./tests
./tests/autopilot/ubuntu_terminal_app/tests/__init__.py:42:80: E501 line too long (94 > 79 characters)
./tests/autopilot/ubuntu_terminal_app/tests/__init__.py:45:80: E501 line too long (90 > 79 characters)
./tests/autopilot/ubuntu_terminal_app/tests/__init__.py:47:80: E501 line too long (89 > 79 characters)
./tests/autopilot/ubuntu_terminal_app/tests/__init__.py:72:80: E501 line too long (80 > 79 characters)
./tests/autopilot/ubuntu_terminal_app/tests/__init__.py:90:5: E303 too many blank lines (2)

review: Needs Information
193. By Nicholas Skaggs

flake8 and typo

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Absolutely; I fixed things and ran flake8:

flake8 ubuntu_terminal_app/*.py ubuntu_terminal_app/tests/*.py
ubuntu_terminal_app/tests/__init__.py:22:1: E402 module level import not at top of file
ubuntu_terminal_app/tests/__init__.py:38:39: W503 line break before binary operator

Both those warnings are ok -- we have to use the require before import to avoid other issues.

Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Stefano Verzegnassi (verzegnassi-stefano) wrote :

Ok, thanks! LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'README.autopilot.md'
2--- README.autopilot.md 1970-01-01 00:00:00 +0000
3+++ README.autopilot.md 2016-03-08 13:55:06 +0000
4@@ -0,0 +1,74 @@
5+Running Autopilot tests
6+=======================
7+If you are looking for more info about Autopilot or writing AP tests, here are some useful links to help you:
8+
9+- [Ubuntu - Quality](http://developer.ubuntu.com/start/quality)
10+- [Autopilot - Python](https://developer.ubuntu.com/api/autopilot/python/1.5.0/)
11+
12+For help and options on running tests, see:
13+
14+- [Autopilot tests](https://developer.ubuntu.com/en/start/platform/guides/running-autopilot-tests/)
15+
16+Prerequisites
17+=============
18+
19+Install the following autopilot packages required to run the tests,
20+
21+ $ sudo apt-get install python3-autopilot libautopilot-qt ubuntu-ui-toolkit-autopilot python3-autopilot-vis
22+
23+Running tests on the desktop
24+============================
25+
26+Using terminal:
27+
28+* Branch the code
29+
30+ $ bzr branch lp:ubuntu-terminal-app
31+
32+* Navigate to the tests/autopilot directory.
33+
34+ $ cd tests/autopilot
35+
36+* run all tests.
37+
38+ $ autopilot3 run -vv ubuntu_terminal_app
39+
40+* to list all tests:
41+
42+ $ autopilot3 list ubuntu_terminal_app
43+
44+ To run only one test
45+
46+ $ autopilot3 run -vv ubuntu_terminal_app.tests.test_name
47+
48+* Debugging tests using autopilot vis
49+
50+ $ autopilot3 launch -i Qt qmlscene src/app/terminal
51+
52+ $ autopilot3 vis
53+
54+Running tests using Ubuntu SDK
55+==============================
56+
57+Refer this [tutorial](https://developer.ubuntu.com/en/start/platform/guides/running-autopilot-tests/) to run tests on Ubuntu SDK:
58+
59+Running tests on device or emulator:
60+====================================
61+
62+Using autopkg:
63+
64+* Branch the code, for example,
65+
66+ $ bzr branch lp:ubuntu-terminal-app
67+
68+* Navigate to the source directory.
69+
70+ $ cd ubuntu-terminal-app
71+
72+* Build a click package
73+
74+ $ click-buddy .
75+
76+* Run the tests on device (assumes only one click package in the directory)
77+
78+ $ adt-run . *.click --- ssh -s adb -- -p <PASSWORD>
79\ No newline at end of file
80
81=== removed directory 'old-tests'
82=== removed file 'old-tests/CMakeLists.txt'
83--- old-tests/CMakeLists.txt 2014-10-25 04:42:31 +0000
84+++ old-tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
85@@ -1,1 +0,0 @@
86-add_subdirectory(autopilot)
87
88=== removed directory 'old-tests/autopilot'
89=== removed file 'old-tests/autopilot/CMakeLists.txt'
90--- old-tests/autopilot/CMakeLists.txt 2014-10-25 04:42:31 +0000
91+++ old-tests/autopilot/CMakeLists.txt 1970-01-01 00:00:00 +0000
92@@ -1,8 +0,0 @@
93-if(INSTALL_TESTS)
94-execute_process(COMMAND python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
95- OUTPUT_VARIABLE PYTHON_PACKAGE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
96-
97-install(DIRECTORY ${AUTOPILOT_DIR}
98- DESTINATION ${PYTHON_PACKAGE_DIR}
99- )
100-endif(INSTALL_TESTS)
101
102=== removed directory 'old-tests/autopilot/ubuntu_terminal_app'
103=== removed file 'old-tests/autopilot/ubuntu_terminal_app/__init__.py'
104--- old-tests/autopilot/ubuntu_terminal_app/__init__.py 2014-10-25 04:42:31 +0000
105+++ old-tests/autopilot/ubuntu_terminal_app/__init__.py 1970-01-01 00:00:00 +0000
106@@ -1,174 +0,0 @@
107-# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
108-#
109-# Copyright (C) 2013 Canonical Ltd.
110-#
111-# This program is free software; you can redistribute it and/or modify
112-# it under the terms of the GNU Lesser General Public License as published by
113-# the Free Software Foundation; version 3.
114-#
115-# This program is distributed in the hope that it will be useful,
116-# but WITHOUT ANY WARRANTY; without even the implied warranty of
117-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118-# GNU Lesser General Public License for more details.
119-#
120-# You should have received a copy of the GNU Lesser General Public License
121-# along with this program. If not, see <http://www.gnu.org/licenses/>.
122-
123-"""Terminal app autopilot helpers."""
124-
125-from time import sleep
126-import sqlite3
127-import os.path
128-import ubuntuuitoolkit
129-
130-
131-class TerminalApp(object):
132-
133- """Autopilot helper object for the terminal application."""
134-
135- def __init__(self, app_proxy):
136- self.app = app_proxy
137- self.main_view = self.app.select_single(MainView)
138-
139- @property
140- def pointing_device(self):
141- return self.app.pointing_device
142-
143-
144-class MainView(ubuntuuitoolkit.MainView):
145-
146- """Autopilot custom proxy object for the MainView."""
147-
148- def __init__(self, *args):
149- super(MainView, self).__init__(*args)
150- self.visible.wait_for(True)
151-
152- def get_slider_item(self, slider):
153- return self.wait_select_single("Slider", objectName=slider)
154-
155- def get_control_panel(self):
156- return self.wait_select_single("CtrlKeys", objectName="kbCtrl")
157-
158- def get_function_panel(self):
159- return self.wait_select_single("FnKeys", objectName="kbFn")
160-
161- def get_text_panel(self):
162- return self.wait_select_single("ScrlKeys", objectName="kbScrl")
163-
164- def get_terminal_page(self):
165- return self.wait_select_single("Terminal", objectName="pgTerm")
166-
167- def get_circle_menu(self):
168- return self.wait_select_single("CircleMenu", objectName="cmenu")
169-
170- def long_tap_terminal_center(self):
171- x, y, w, h = self.globalRect
172- tap_x = (x + w) / 2
173- tap_y = (y + h) / 3
174-
175- # tap in the top third of the screen, to avoid OSK
176- self.pointing_device.move(tap_x, tap_y)
177- self.pointing_device.press()
178- # we can hold the press for a long time without issue
179- # so we'll ensure the app recieves our signal when under load
180- sleep(4)
181- self.pointing_device.release()
182-
183- def drag_horizontal_slider(self, slider, pos):
184- """Drag slider until value is set"""
185- slItem = self.get_slider_item(slider)
186-
187- slRect = slItem.select_single("SliderStyle")
188-
189- slideMin = int(slItem.minimumValue)
190- slideMax = int(slItem.maximumValue)
191-
192- if pos > slideMax:
193- raise ValueError("Pos cannot be greater than" + str(slideMax))
194-
195- if pos < slideMin:
196- raise ValueError("Pos cannot be less than" + str(slideMin))
197-
198- x, y, w, h = slRect.globalRect
199- # calculate the approximate slide step width
200- # we take half of the theoretical step value just to make
201- # sure we don't miss any values
202- step = w / ((slideMax - slideMin) * 2)
203- sx = x + step
204- sy = y + h / 2
205- loop = 1
206-
207- # set the slider to minimum value and loop
208- self.pointing_device.move(sx, sy)
209- self.pointing_device.click()
210-
211- # drag through the slider until the pos matches our desired value
212- # in case of bad sliding, loop will also timeout
213- while round(slItem.value) != pos and slItem.value < slideMax \
214- and loop <= (slideMax * 2):
215- valuePos = int(sx + step)
216- self.pointing_device.drag(sx, sy, valuePos, sy)
217- sx = valuePos
218- sleep(1)
219- loop = loop + 1
220-
221-
222-class DbMan(object):
223-
224- """
225- Helper functions for dealing with sqlite databases
226- """
227-
228- def get_db(self):
229- dbs_path = os.path.expanduser(
230- "~/.local/share/com.ubuntu.terminal/Databases")
231- if not os.path.exists(dbs_path):
232- return None
233-
234- files = [f for f in os.listdir(dbs_path)
235- if os.path.splitext(f)[1] == ".ini"]
236- for f in files:
237- ini_path = os.path.join(dbs_path, f)
238- with open(ini_path) as ini:
239- for line in ini:
240- if "=" in line:
241- key, val = line.strip().split("=")
242- if key == "Name" and val == "UbuntuTerminalDB":
243- try:
244- return ini_path.replace(".ini", ".sqlite")
245- except OSError:
246- pass
247- return None
248-
249- def clean_db(self):
250- path = self.get_db()
251- if path is None:
252- self.assertNotEquals(path, None)
253- try:
254- os.remove(path)
255- except OSError:
256- pass
257-
258- def get_font_size_from_storage(self):
259- db = self.get_db()
260- conn = sqlite3.connect(db)
261-
262- with conn:
263- cur = conn.cursor()
264- cur.execute("SELECT value FROM config WHERE item='fontSize'")
265- row = cur.fetchone()
266- if row is None:
267- self.assertNotEquals(row, None)
268- return int(row[0])
269-
270- def get_color_scheme_from_storage(self):
271- db = self.get_db()
272- conn = sqlite3.connect(db)
273-
274- with conn:
275- cur = conn.cursor()
276- cur.execute("SELECT value FROM config WHERE item='colorScheme'")
277- row = cur.fetchone()
278- if row is None:
279- self.assertNotEquals(row, None)
280- return row[0]
281
282=== removed directory 'old-tests/autopilot/ubuntu_terminal_app/tests'
283=== removed file 'old-tests/autopilot/ubuntu_terminal_app/tests/__init__.py'
284--- old-tests/autopilot/ubuntu_terminal_app/tests/__init__.py 2014-10-25 04:42:31 +0000
285+++ old-tests/autopilot/ubuntu_terminal_app/tests/__init__.py 1970-01-01 00:00:00 +0000
286@@ -1,131 +0,0 @@
287-# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
288-# Copyright 2013 Canonical
289-#
290-# This program is free software: you can redistribute it and/or modify it
291-# under the terms of the GNU General Public License version 3, as published
292-# by the Free Software Foundation.
293-
294-"""Terminal app autopilot tests."""
295-
296-import os.path
297-import fixtures
298-import logging
299-import tempfile
300-
301-from autopilot import logging as autopilot_logging
302-from autopilot.testcase import AutopilotTestCase
303-import ubuntuuitoolkit
304-
305-import ubuntu_terminal_app
306-from gi.repository import Click
307-
308-logger = logging.getLogger(__name__)
309-
310-
311-class TerminalTestCase(AutopilotTestCase):
312-
313- """A common testcase class that provides useful methods for the terminal
314- app.
315-
316- """
317-
318- binary = 'terminal'
319- source_dir = os.path.dirname(os.path.dirname(os.path.abspath('.')))
320- local_location_binary = os.path.join(source_dir, 'src', 'app', binary)
321- installed_location_binary = os.path.join('/usr/bin/', binary)
322- installed_location_qml = '/usr/share/terminal/qml/ubuntu-terminal-app.qml'
323-
324- def setUp(self):
325- super(TerminalTestCase, self).setUp()
326- launcher_method, _ = self.get_launcher_method_and_type()
327- self.app = ubuntu_terminal_app.TerminalApp(launcher_method())
328-
329- def get_launcher_method_and_type(self):
330- if os.path.exists(self.local_location_binary):
331- launcher = self.launch_test_local
332- test_type = 'local'
333- elif os.path.exists(self.installed_location_binary):
334- launcher = self.launch_test_installed
335- test_type = 'deb'
336- else:
337- launcher = self.launch_test_click
338- test_type = 'click'
339- return launcher, test_type
340-
341- @autopilot_logging.log_action(logger.info)
342- def launch_test_local(self):
343- self.useFixture(fixtures.EnvironmentVariable(
344- 'QML2_IMPORT_PATH', newvalue=os.path.join(self.source_dir,
345- 'src', 'plugin')))
346-
347- return self.launch_test_application(
348- self.local_location_binary,
349- app_type='qt',
350- emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
351-
352- @autopilot_logging.log_action(logger.info)
353- def launch_test_installed(self):
354- return self.launch_test_application(
355- self.installed_location_binary,
356- '-q', self.installed_location_qml,
357- app_type='qt',
358- emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
359-
360- @autopilot_logging.log_action(logger.info)
361- def launch_test_click(self):
362- # We need to pass the "--forceAuth false" argument to the terminal app
363- # binary, but ubuntu-app-launch doesn't pass arguments to the exec line
364- # on the desktop file. So we make a test desktop file that has the
365- # "--forceAuth false" on the exec line.
366- desktop_file_path = self.write_sandbox_desktop_file()
367- desktop_file_name = os.path.basename(desktop_file_path)
368- application_name, _ = os.path.splitext(desktop_file_name)
369- return self.launch_upstart_application(
370- application_name,
371- emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
372-
373- def write_sandbox_desktop_file(self):
374- desktop_file_dir = self.get_local_desktop_file_directory()
375- desktop_file = self.get_named_temporary_file(
376- suffix='.desktop', dir=desktop_file_dir)
377- desktop_file.write('[Desktop Entry]\n')
378- version, installed_path = self.get_installed_version_and_directory()
379- terminal_sandbox_exec = (
380- 'aa-exec-click -p com.ubuntu.terminal_terminal_{}'
381- ' -- terminal --forceAuth false'.format(version))
382- desktop_file_dict = {
383- 'Type': 'Application',
384- 'Name': 'terminal',
385- 'Exec': terminal_sandbox_exec,
386- 'Icon': 'Not important',
387- 'Path': installed_path
388- }
389- for key, value in desktop_file_dict.items():
390- desktop_file.write('{key}={value}\n'.format(key=key, value=value))
391- desktop_file.close()
392- logger.debug(terminal_sandbox_exec)
393- for key, value in desktop_file_dict.items():
394- logger.debug("%s: %s" % (key, value))
395- return desktop_file.name
396-
397- def get_local_desktop_file_directory(self):
398- return os.path.join(
399- os.path.expanduser('~'), '.local', 'share', 'applications')
400-
401- def get_named_temporary_file(
402- self, dir=None, mode='w+t', delete=False, suffix=''):
403- # Discard files with underscores which look like an APP_ID to Unity
404- # See https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1329141
405- chars = tempfile._RandomNameSequence.characters.strip("_")
406- tempfile._RandomNameSequence.characters = chars
407- return tempfile.NamedTemporaryFile(
408- dir=dir, mode=mode, delete=delete, suffix=suffix)
409-
410- def get_installed_version_and_directory(self):
411- db = Click.DB()
412- db.read()
413- package_name = 'com.ubuntu.terminal'
414- registry = Click.User.for_user(db, name=os.environ.get('USER'))
415- version = registry.get_version(package_name)
416- directory = registry.get_path(package_name)
417- return version, directory
418
419=== removed file 'old-tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py'
420--- old-tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py 2014-10-25 04:42:31 +0000
421+++ old-tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py 1970-01-01 00:00:00 +0000
422@@ -1,157 +0,0 @@
423-# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
424-# Copyright 2013 Canonical
425-#
426-# This program is free software: you can redistribute it and/or modify it
427-# under the terms of the GNU General Public License version 3, as published
428-# by the Free Software Foundation.
429-
430-"""Terminal app autopilot tests."""
431-
432-from __future__ import absolute_import
433-
434-from autopilot.matchers import Eventually
435-from testtools.matchers import Equals
436-
437-from ubuntu_terminal_app.tests import TerminalTestCase
438-from ubuntu_terminal_app import DbMan
439-from ubuntuuitoolkit import ToolkitException
440-from testscenarios import TestWithScenarios
441-
442-from time import sleep
443-import random
444-
445-
446-class TestMainWindow(TerminalTestCase):
447-
448- def test_circle_menu_shows(self):
449- """Make sure that Circle Menu is visible
450- on long tap"""
451- self.app.main_view.long_tap_terminal_center()
452- menu = self.app.main_view.get_circle_menu()
453- self.assertThat(menu.visible, Eventually(Equals(True)))
454-
455- def test_header(self):
456- """Make sure that Header is visible
457- in Portrait Mode and not visible in landscape mode"""
458- kterm = self.app.main_view.get_terminal_page()
459- header = self.app.main_view.get_header()
460- if kterm.width > kterm.height:
461- self.assertThat(header.visible, Equals(False))
462- else:
463- self.assertThat(header.visible, Equals(True))
464-
465-
466-class TestPanel(TerminalTestCase, TestWithScenarios):
467-
468- scenarios = [
469- ('controlpanel',
470- {'button': 'controlkeysaction',
471- 'helper_method': 'get_control_panel'
472- }),
473-
474- ('functionpanel',
475- {'button': 'functionkeysaction',
476- 'helper_method': 'get_function_panel'
477- }),
478-
479- ('textpanel',
480- {'button': 'textkeysaction',
481- 'helper_method': 'get_text_panel'
482- })
483- ]
484-
485- def open_panel(self, button, helper_method):
486- """Open named panel"""
487- header = self.app.main_view.get_header()
488- header.click_action_button(button)
489- get_panel = getattr(self.app.main_view, helper_method)
490- return get_panel()
491-
492- def hide_panel(self):
493- """Close any open panel"""
494- header = self.app.main_view.get_header()
495-
496- # the overflow panel can be left open, so we need to try again
497- # https://bugs.launchpad.net/ubuntu-terminal-app/+bug/1363233
498- try:
499- header.click_action_button('hidepanelaction')
500- try:
501- sleep(2)
502- header.click_action_button('hidepanelaction')
503- except ToolkitException:
504- pass
505- except ToolkitException:
506- pass
507-
508- def test_panels(self):
509- """Make sure that Panel is visible
510- when clicking the toolbar popup items and hides properly."""
511- panel = self.open_panel(self.button, self.helper_method)
512- self.assertThat(panel.visible, Eventually(Equals(True)))
513- self.hide_panel()
514- self.assertThat(panel.visible, Eventually(Equals(False)))
515-
516-
517-class TestSettings(TerminalTestCase, DbMan):
518-
519- def click_item_selector_item(self, selector, value):
520- """Clicks item from item selector"""
521- # This needs a toolkit helper
522- # https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1272345
523- select = self.app.main_view.wait_select_single('ItemSelector',
524- objectName=selector)
525- container = select.wait_select_single('Standard',
526- objectName='listContainer')
527- self.app.pointing_device.click_object(container)
528- select.currentlyExpanded.wait_for(True)
529- # waiting for currentlyExpanded is not enough
530- # some animation is not accounted for and thus we sleep
531- sleep(2)
532- item = container.wait_select_single('Label', text=value)
533- self.app.pointing_device.click_object(item)
534- select.currentlyExpanded.wait_for(False)
535- # waiting for currentlyExpanded is not enough
536- # some animation is not accounted for and thus we sleep
537- sleep(1)
538-
539- def test_color_scheme_changes(self):
540- """Make sure that color scheme is set correctly"""
541-
542- # are these string translatable?
543- # if so, we need to do this another way
544- schemeList = ("BlackOnRandomLight",
545- "BlackOnWhite",
546- "BlackOnLightYellow",
547- "DarkPastels",
548- "GreenOnBlack",
549- "Linux",
550- "WhiteOnBlack")
551-
552- colorScheme = self.get_color_scheme_from_storage
553- for scheme in schemeList:
554- header = self.app.main_view.get_header()
555- header.click_action_button('SettingsButton')
556- self.click_item_selector_item("liSchemes", scheme)
557- self.app.main_view.go_back()
558- self.assertThat(colorScheme, Eventually(Equals(scheme)))
559-
560- def test_font_size_changes(self):
561- """Make sure that font size is set correctly"""
562- header = self.app.main_view.get_header()
563- header.click_action_button('SettingsButton')
564-
565- font_size = self.get_font_size_from_storage
566-
567- # change font size to min
568- self.app.main_view.drag_horizontal_slider("slFont", 8)
569- self.assertThat(font_size, Eventually(Equals(8)))
570-
571- # change font size to max
572- self.app.main_view.drag_horizontal_slider("slFont", 32)
573- self.assertThat(font_size, Eventually(Equals(32)))
574-
575- # change font size to random sizes
576- for loop in range(1, 3):
577- randSize = random.randrange(9, 31, 1)
578- self.app.main_view.drag_horizontal_slider("slFont", randSize)
579- self.assertThat(font_size, Eventually(Equals(randSize)))
580
581=== modified file 'tests/autopilot/ubuntu_terminal_app/__init__.py'
582--- tests/autopilot/ubuntu_terminal_app/__init__.py 2015-02-25 00:09:54 +0000
583+++ tests/autopilot/ubuntu_terminal_app/__init__.py 2016-03-08 13:55:06 +0000
584@@ -16,4 +16,26 @@
585
586 """Terminal app autopilot helpers."""
587
588-# TODO Insert new tests here
589+import ubuntuuitoolkit
590+
591+
592+class TerminalApp(object):
593+
594+ """Autopilot helper object for the terminal application."""
595+
596+ def __init__(self, app_proxy):
597+ self.app = app_proxy
598+ self.main_view = self.app.select_single(MainView)
599+
600+ @property
601+ def pointing_device(self):
602+ return self.app.pointing_device
603+
604+
605+class MainView(ubuntuuitoolkit.MainView):
606+
607+ """Autopilot custom proxy object for the MainView."""
608+
609+ def __init__(self, *args):
610+ super(MainView, self).__init__(*args)
611+ self.visible.wait_for(True)
612
613=== modified file 'tests/autopilot/ubuntu_terminal_app/tests/__init__.py'
614--- tests/autopilot/ubuntu_terminal_app/tests/__init__.py 2015-02-25 00:09:54 +0000
615+++ tests/autopilot/ubuntu_terminal_app/tests/__init__.py 2016-03-08 13:55:06 +0000
616@@ -7,4 +7,156 @@
617
618 """Terminal app autopilot tests."""
619
620-# TODO Insert new tests here.
621+import os.path
622+import fixtures
623+import logging
624+import tempfile
625+import gi
626+
627+from autopilot import logging as autopilot_logging
628+from autopilot.testcase import AutopilotTestCase
629+import ubuntuuitoolkit
630+
631+import ubuntu_terminal_app
632+gi.require_version('Click', '0.4')
633+from gi.repository import Click
634+
635+
636+logger = logging.getLogger(__name__)
637+
638+
639+class TerminalTestCase(AutopilotTestCase):
640+
641+ """A common testcase class that provides useful methods for the terminal
642+ app.
643+
644+ """
645+
646+ local_build_location = os.path.dirname(os.path.dirname(os.getcwd()))
647+ sdk_build_location = os.path.join(os.path.dirname(local_build_location),
648+ os.path.basename(local_build_location)
649+ + '-build')
650+
651+ local_build_location_qml = os.path.join(
652+ local_build_location, 'src', 'app', 'qml', 'ubuntu-terminal-app.qml')
653+ local_build_location_binary = os.path.join(local_build_location,
654+ 'src', 'app', 'terminal')
655+ sdk_build_location_qml = os.path.join(
656+ sdk_build_location, 'src', 'app', 'qml', 'ubuntu-terminal-app.qml')
657+ sdk_build_location_binary = os.path.join(sdk_build_location,
658+ 'src', 'app', 'terminal')
659+ installed_location_binary = os.path.join('usr', 'bin',
660+ 'ubuntu-terminal-app')
661+ installed_location_qml = os.path.join('usr', 'share',
662+ 'ubuntu-terminal-app', 'qml',
663+ 'ubuntu-terminal-app.qml')
664+
665+ def setUp(self):
666+ super(TerminalTestCase, self).setUp()
667+ launcher_method, _ = self.get_launcher_method_and_type()
668+ self.app = ubuntu_terminal_app.TerminalApp(launcher_method())
669+
670+ def get_launcher_method_and_type(self):
671+ if os.path.exists(self.local_build_location_binary):
672+ launcher = self.launch_test_local
673+ test_type = 'local'
674+ elif os.path.exists(self.sdk_build_location_binary):
675+ launcher = self.launch_test_sdk
676+ test_type = 'sdk'
677+ elif os.path.exists(self.installed_location_binary):
678+ launcher = self.launch_test_installed
679+ test_type = 'deb'
680+ else:
681+ launcher = self.launch_test_click
682+ test_type = 'click'
683+ return launcher, test_type
684+
685+ @autopilot_logging.log_action(logger.info)
686+ def launch_test_local(self):
687+ plugin_location = os.path.join(self.local_build_location,
688+ 'src', 'plugin')
689+ self.useFixture(fixtures.EnvironmentVariable(
690+ 'QML2_IMPORT_PATH', newvalue=plugin_location))
691+ return self.launch_test_application(
692+ self.local_build_location_binary,
693+ app_type='qt',
694+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
695+
696+ @autopilot_logging.log_action(logger.info)
697+ def launch_test_sdk(self):
698+ plugin_location = os.path.join(self.sdk_build_location,
699+ 'src', 'plugin')
700+ self.useFixture(fixtures.EnvironmentVariable(
701+ 'QML2_IMPORT_PATH', newvalue=plugin_location))
702+
703+ return self.launch_test_application(
704+ self.sdk_build_location_binary,
705+ app_type='qt',
706+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
707+
708+ @autopilot_logging.log_action(logger.info)
709+ def launch_test_installed(self):
710+ return self.launch_test_application(
711+ self.installed_location_binary,
712+ '-q', self.installed_location_qml,
713+ app_type='qt',
714+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
715+
716+ @autopilot_logging.log_action(logger.info)
717+ def launch_test_click(self):
718+ # We need to pass the "--forceAuth false" argument to the terminal app
719+ # binary, but ubuntu-app-launch doesn't pass arguments to the exec line
720+ # on the desktop file. So we make a test desktop file that has the
721+ # "--forceAuth false" on the exec line.
722+ desktop_file_path = self.write_sandbox_desktop_file()
723+ desktop_file_name = os.path.basename(desktop_file_path)
724+ application_name, _ = os.path.splitext(desktop_file_name)
725+ return self.launch_upstart_application(
726+ application_name,
727+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
728+
729+ def write_sandbox_desktop_file(self):
730+ desktop_file_dir = self.get_local_desktop_file_directory()
731+ desktop_file = self.get_named_temporary_file(
732+ suffix='.desktop', dir=desktop_file_dir)
733+ desktop_file.write('[Desktop Entry]\n')
734+ version, installed_path = self.get_installed_version_and_directory()
735+ terminal_sandbox_exec = (
736+ 'aa-exec-click -p com.ubuntu.terminal_terminal_{}'
737+ ' -- terminal --forceAuth false'.format(version))
738+ desktop_file_dict = {
739+ 'Type': 'Application',
740+ 'Name': 'terminal',
741+ 'Exec': terminal_sandbox_exec,
742+ 'Icon': 'Not important',
743+ 'Path': installed_path
744+ }
745+ for key, value in desktop_file_dict.items():
746+ desktop_file.write('{key}={value}\n'.format(key=key, value=value))
747+ desktop_file.close()
748+ logger.debug(terminal_sandbox_exec)
749+ for key, value in desktop_file_dict.items():
750+ logger.debug("%s: %s" % (key, value))
751+ return desktop_file.name
752+
753+ def get_local_desktop_file_directory(self):
754+ return os.path.join(
755+ os.path.expanduser('~'), '.local', 'share', 'applications')
756+
757+ def get_named_temporary_file(
758+ self, dir=None, mode='w+t', delete=False, suffix=''):
759+ # Discard files with underscores which look like an APP_ID to Unity
760+ # See https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1329141
761+ chars = tempfile._RandomNameSequence.characters.strip("_")
762+ tempfile._RandomNameSequence.characters = chars
763+ return tempfile.NamedTemporaryFile(
764+ dir=dir, mode=mode, delete=delete, suffix=suffix)
765+
766+ def get_installed_version_and_directory(self):
767+ db = Click.DB()
768+ db.read()
769+ package_name = 'com.ubuntu.terminal'
770+ registry = Click.User.for_user(db, name=os.environ.get('USER'))
771+ version = registry.get_version(package_name)
772+ directory = registry.get_path(package_name)
773+ return version, directory
774
775=== modified file 'tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py'
776--- tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py 2015-02-25 18:37:32 +0000
777+++ tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py 2016-03-08 13:55:06 +0000
778@@ -7,12 +7,11 @@
779
780 """Terminal app autopilot tests."""
781
782-from autopilot.testcase import AutopilotTestCase
783-
784-# TODO Insert new tests here.
785-
786-
787-class DummyTest(AutopilotTestCase):
788- """This is just a placeholder test"""
789- def test_dummy_true(self):
790- self.assertTrue(True)
791+from ubuntu_terminal_app.tests import TerminalTestCase
792+
793+
794+class TestMainWindow(TerminalTestCase):
795+ def test_example_test(self):
796+ """Just launch app, assert on main view"""
797+ main_view = self.app.main_view
798+ self.assertTrue(main_view)

Subscribers

People subscribed via source and target branches