1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2013 Canonical
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
11
from time import sleep
13
from autopilot.platform import model
14
from autopilot.matchers import Eventually
15
from testtools.matchers import Equals, NotEquals, GreaterThan
17
from ubuntu_system_settings.tests import UbuntuSystemSettingsTestCase
18
from ubuntu_system_settings.utils.i18n import ugettext as _
20
from ubuntuuitoolkit import emulators as toolkit_emulators
22
class TimeDateTestCase(UbuntuSystemSettingsTestCase,
23
dbusmock.DBusTestCase):
24
""" Tests for the Time & Date Page """
27
def setUpClass(klass):
28
klass.start_system_bus()
29
klass.dbus_con = klass.get_dbus(True)
30
(klass.p_mock,klass.obj_timedate1) = klass.spawn_server_template(
31
'timedated', {}, stdout=subprocess.PIPE)
34
""" Go to Time & Date page """
35
self.obj_timedate1.Reset()
36
super(TimeDateTestCase, self).setUp("time-date")
39
def time_date_page(self):
40
return self.main_view.select_single(objectName='timeDatePage')
44
return self.main_view.select_single(objectName='timeZone')
46
def click_tz_search_field(self):
47
self.scroll_to_and_click(self.tz_page)
48
text_field = self.main_view.select_single(objectName='selectTimeZoneField')
49
self.pointer.move_to_object(text_field)
51
def test_time_date_page(self):
52
""" Checks whether Time & Date page is available """
53
self.assertThat(self.time_date_page, NotEquals(None))
54
self.assertThat(self.time_date_page.title, Equals(_('Time & Date')))
56
def test_tz_list_initially_empty(self):
57
""" Checks that no list is displayed initially """
58
self.scroll_to_and_click(self.tz_page)
59
labelVisible = self.main_view.select_single(objectName='nothingLabel').visible
60
self.assertThat(labelVisible, Equals(True))
62
def test_searching_tz(self):
63
""" Check that searching for a valid location shows something """
64
self.click_tz_search_field()
65
self.keyboard.type('London, United Kingdom')
66
listview = self.main_view.select_single(objectName='locationsListView')
67
self.assertThat(listview.count, GreaterThan(0))
69
def test_searching_tz_not_found(self):
70
""" Check that searching for an invalid location shows nothing """
71
self.click_tz_search_field()
72
self.keyboard.type('Oh no you don\'t!')
73
listview = self.main_view.select_single(objectName='locationsListView')
74
self.assertThat(listview.count, Equals(0))
75
labelVisible = self.main_view.select_single(objectName='nothingLabel').visible
76
self.assertThat(labelVisible, Equals(True))
78
def test_manual_tz_selection(self):
79
""" Check that manually selecting a timezone sets it properly """
80
self.click_tz_search_field()
81
self.keyboard.type('London, United Kingdom')
82
listview = self.main_view.select_single(objectName='locationsListView')
83
london = listview.select_many(toolkit_emulators.Standard)[0]
84
self.pointer.click_object(london)
85
header = self.main_view.select_single(objectName='MainView_Header')
86
self.assertThat(header.title, Eventually(Equals(_('Time & Date'))))
87
self.assertThat(self.tz_page.text, Equals('Europe/London'))
89
def test_same_tz_selection(self):
90
""" Check that manually setting a timezone then setting the same one doesn't
91
take you back to the index """
92
self.test_manual_tz_selection()
93
self.click_tz_search_field()
94
# This is also in Europe/London
95
self.keyboard.type('Preston, United Kingdom')
96
listview = self.main_view.select_single(objectName='locationsListView')
97
preston = listview.select_many(toolkit_emulators.Standard)[0]
98
self.pointer.click_object(preston)
99
# The timer is 1 second, wait and see that we haven't moved pages
101
header = self.main_view.select_single(objectName='MainView_Header')
102
self.assertThat(header.title, Eventually(Equals(_('Time zone'))))