~canonical-platform-qa/ubuntu-system-tests/vivid

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/scopes/apps/clickscope.py

  • Committer: Richard Huddie
  • Date: 2017-01-04 10:09:31 UTC
  • mfrom: (474.1.26 trunk)
  • Revision ID: richard.huddie@canonical.com-20170104100931-phxqhed28t6n10r5
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
#
20
20
 
21
 
import unityclickscope
22
 
 
23
 
"""
24
 
This file should be used to import the helpers from unityclickscope, rather
25
 
than importing unityclickscope directly.
26
 
 
27
 
Any CPOs written should derive from the classes defined in this file rather
28
 
than directly from unityclickscope.
29
 
 
30
 
It is required to over-ride the imported classes to ensure they cannot be
31
 
instantiated directly. Otherwise this can cause Autopilot CPO errors.
32
 
 
33
 
"""
34
 
 
35
 
 
36
 
class ClickScope(unityclickscope.ClickScope):
37
 
 
38
 
    @classmethod
39
 
    def validate_dbus_object(cls, path, state):
40
 
        """This class can never be selected."""
41
 
        return False
42
 
 
43
 
 
44
 
class StoreScope(unityclickscope.StoreScope):
45
 
 
46
 
    @classmethod
47
 
    def validate_dbus_object(cls, path, state):
48
 
        """This class can never be selected."""
49
 
        return False
50
 
 
51
 
 
52
 
class Preview(unityclickscope.Preview):
53
 
 
54
 
    @classmethod
55
 
    def validate_dbus_object(cls, path, state):
56
 
        """This class can never be selected."""
57
 
        return False
 
21
import logging
 
22
import threading
 
23
 
 
24
from gi.repository import Accounts, GLib
 
25
from autopilot.exceptions import StateNotFoundError
 
26
 
 
27
from ubuntu_system_tests.helpers.input_manager import input_manager
 
28
from ubuntu_system_tests.helpers.scopes.base import (
 
29
    Preview as PreviewBase
 
30
)
 
31
 
 
32
logger = logging.getLogger(__name__)
 
33
 
 
34
 
 
35
class Preview(PreviewBase):
 
36
 
 
37
    @classmethod
 
38
    def validate_dbus_object(cls, path, state):
 
39
        """This class can never be selected."""
 
40
        return False
 
41
 
 
42
    def get_details(self):
 
43
        """Return the details of the application whose preview is open."""
 
44
        header_widget = self.select_single('PreviewWidget', objectName='hdr')
 
45
        title_label = header_widget.select_single(
 
46
            'Label', objectName='titleLabel')
 
47
        subtitle_label = header_widget.select_single(
 
48
            'Label', objectName='subtitleLabel')
 
49
        return dict(
 
50
            title=title_label.text, subtitle=subtitle_label.text)
 
51
 
 
52
    def install(self):
 
53
        install_button = self.select_single(
 
54
            'PreviewActionButton', objectName='buttoninstall_click')
 
55
        input_manager.pointer.click_object(install_button)
 
56
 
 
57
    def is_progress_bar_visible(self):
 
58
        try:
 
59
            self.select_single('ProgressBar', objectName='progressBar')
 
60
            return True
 
61
        except StateNotFoundError:
 
62
            return False
 
63
 
 
64
 
 
65
class AccountManager(object):
 
66
 
 
67
    def __init__(self):
 
68
        self.manager = Accounts.Manager()
 
69
 
 
70
    def _start_main_loop(self):
 
71
        self.error = None
 
72
        self._main_loop = GLib.MainLoop()
 
73
        self._main_loop_thread = threading.Thread(
 
74
            target=self._main_loop.run)
 
75
        self._main_loop_thread.start()
 
76
 
 
77
    def delete_account(self, account):
 
78
        self._start_main_loop()
 
79
        account.delete()
 
80
        account.store(self._on_account_deleted, None)
 
81
        self._join_main_loop()
 
82
 
 
83
    def _join_main_loop(self):
 
84
        self._main_loop_thread.join()
 
85
        if self.error is not None:
 
86
            raise Exception(self.error.message)
 
87
 
 
88
    def _on_account_deleted(self, account, error, userdata):
 
89
        if error:
 
90
            self.error = error
 
91
        self._main_loop.quit()