Merge lp:~nik90/ubuntu-clock-app/fix-alarm-tests into lp:ubuntu-clock-app/saucy

Proposed by Nekhelesh Ramananthan
Status: Merged
Approved by: Nicholas Skaggs
Approved revision: 358
Merged at revision: 346
Proposed branch: lp:~nik90/ubuntu-clock-app/fix-alarm-tests
Merge into: lp:ubuntu-clock-app/saucy
Diff against target: 1029 lines (+307/-463)
9 files modified
alarm/AddAlarmPage.qml (+11/-3)
alarm/AlarmDays.qml (+2/-0)
alarm/AlarmPage.qml (+5/-4)
tests/autopilot/ubuntu_clock_app/emulators.py (+188/-161)
tests/autopilot/ubuntu_clock_app/tests/__init__.py (+1/-1)
tests/autopilot/ubuntu_clock_app/tests/test_alarm.py (+82/-265)
tests/autopilot/ubuntu_clock_app/tests/test_clock.py (+8/-8)
tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py (+2/-2)
tests/autopilot/ubuntu_clock_app/tests/test_timer.py (+8/-19)
To merge this branch: bzr merge lp:~nik90/ubuntu-clock-app/fix-alarm-tests
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Leo Arias (community) code review Approve
Nicholas Skaggs autopilot code review Pending
Review via email: mp+205154@code.launchpad.net

Commit message

Fixes the alarm tests.

Description of the change

This MP revamps the entire alarms AP tests by ensuring that,
- All alarm emulator and test function have a proper docstring explaining what each function does.
- Added autopilot logging to the public emulator functions exposed to the alarm tests.
- Removed unnecessary import statements
- Cleaned up tests to only contain high-level statements and moved all the smaller tasks into the emulator functions.
- Added reference to bug reports where needed to make it clear why certain temporary code has been added.

BLOCKED: Do note that the tests currently fail in the jenkins machine since the TextField UITK emulator used in this MP has not yet landed in the 14.04 archive. Please ensure that this is fixed before merging MP to trunk.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

25 + containerHeight: itemHeight * 7 // Temporary fix for autopilot

Please, file a bug where you explain the problem, and put a link to it next to the comment in the code.

Remember updating the copyright. You are missing it here:
tests/autopilot/ubuntu_clock_app/emulators.py

209 + tx = x + (w / 2)
210 + ty = y + (h / 2.5)
211 + self.pointing_device.drag(tx, ty - (h / 4), tx - (w / 2), ty + (h / 2))
217 + tx = x + (w / 2)
218 + ty = y + (h / 2.5)
219 + self.pointing_device.drag(tx, ty - (h / 4), tx + (w / 2), ty + (h / 2))

I've seen some code by barry where he changes the / to //. // returns the floor division, so it sounds safer to use when we need ints, like in this case. And with it, we will get the same behaviour on python 2 and 3.
http://www.python.org/dev/peps/pep-0238/

266 + days_object = day_option_selector.select_single("StyledItem",
267 + objectName="listContainer")
266 + days_object = day_option_selector.select_single("StyledItem",
267 + objectName="listContainer")
296 + day_array.append(self.wait_select_single('CheckBox',
297 + objectName='repeatDaysSwitch' + repr(i)))
314 + done_button = self.wait_select_single('Button',
315 + objectName='confirmRepeatDaysButton')
367 + alarm = self.wait_select_single('CheckBox',
368 + objectName='listAlarmStatus{}'.format(index))

This is not properly aligned, and pep8 will complain.
I prefer:
days_object = day_option_selector.select_single(
    "StyledItem", objectName="listContainer")

But it's totally valid to break after the first argument and some people prefer it. You just have to make sure all arguments start on the same column.

278 + day_index = i

You can add a break after you found the element, so you stop the loop and don't do more unnecessary checks.
I find the for loops prettier, but that's a matter of preference:

for index, day_element in enumerate(daylist):
    if(day_element.text == day):
        day_index = index
        break

292 + day_array = []

Why do you need this date array?

for index in range(7):
    day_element = self.wait_select_single(
        toolkit_emulators.CheckBox, objectName='repeatDaysSwitch{}'.format(index))
        if index % 2 == 0:
            day_element.check()
        else:
            day_element.uncheck()

That looks a little cleaner for me ^

779 + """ Test to add a single type alarm and check if it is properly
780 + added to the alarm list.
781 + """

When the comments are of more than one line, please split them into a one line summary, and then add extra information on following paragraphs. That's from http://www.python.org/dev/peps/pep-0257/
In this case, I'd just remove the comment because you have given the test a perfect name that explains it all.

I like this very much. You have hidden all the low level details behind the public methods add_alarm, delete_alarm and toggle_alarm, and you named them using the user language. I couldn't have asked for more.

Well, I always can ask for more because I'm a PITA. Please add the logging decorator to those three public methods, so the autopilot logs show a trace of what we were doing.

Thank you!

Revision history for this message
Leo Arias (elopio) :
review: Needs Fixing (code review)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :
Download full text (3.3 KiB)

> Remember updating the copyright. You are missing it here:
> tests/autopilot/ubuntu_clock_app/emulators.py
>

fixed in rev 343

> 209 + tx = x + (w / 2)
> 210 + ty = y + (h / 2.5)
> 211 + self.pointing_device.drag(tx, ty - (h / 4), tx - (w / 2), ty + (h /
> 2))
> 217 + tx = x + (w / 2)
> 218 + ty = y + (h / 2.5)
> 219 + self.pointing_device.drag(tx, ty - (h / 4), tx + (w / 2), ty + (h /
> 2))
>
> I've seen some code by barry where he changes the / to //. // returns the
> floor division, so it sounds safer to use when we need ints, like in this
> case. And with it, we will get the same behaviour on python 2 and 3.
> http://www.python.org/dev/peps/pep-0238/

Fixed in rev 345

>
> 266 + days_object = day_option_selector.select_single("StyledItem",
> 267 + objectName="listContainer")
> 266 + days_object = day_option_selector.select_single("StyledItem",
> 267 + objectName="listContainer")
> 296 + day_array.append(self.wait_select_single('CheckBox',
> 297 + objectName='repeatDaysSwitch' + repr(i)))
> 314 + done_button = self.wait_select_single('Button',
> 315 + objectName='confirmRepeatDaysButton')
> 367 + alarm = self.wait_select_single('CheckBox',
> 368 + objectName='listAlarmStatus{}'.format(index))
>
> This is not properly aligned, and pep8 will complain.
> I prefer:
> days_object = day_option_selector.select_single(
> "StyledItem", objectName="listContainer")
>
> But it's totally valid to break after the first argument and some people
> prefer it. You just have to make sure all arguments start on the same column.

Fixed in rev 346

>
> 278 + day_index = i
>
> You can add a break after you found the element, so you stop the loop and
> don't do more unnecessary checks.
> I find the for loops prettier, but that's a matter of preference:
>
> for index, day_element in enumerate(daylist):
> if(day_element.text == day):
> day_index = index
> break
>
> 292 + day_array = []
>
> Why do you need this date array?
>
> for index in range(7):
> day_element = self.wait_select_single(
> toolkit_emulators.CheckBox,
> objectName='repeatDaysSwitch{}'.format(index))
> if index % 2 == 0:
> day_element.check()
> else:
> day_element.uncheck()
>
> That looks a little cleaner for me ^
>

Fixed in rev 347

> 779 + """ Test to add a single type alarm and check if it is properly
> 780 + added to the alarm list.
> 781 + """
>
> When the comments are of more than one line, please split them into a one line
> summary, and then add extra information on following paragraphs. That's from
> http://www.python.org/dev/peps/pep-0257/
> In this case, I'd just remove the comment because you have given the test a
> perfect name that explains it all.

Fixed in rev 349. I removed the comments since the test name is good enough.

> I like this very much. You have hidden all the low level details behind the
> public methods add_alarm, delete_alarm and toggle_alarm, and you named them
> using the user language. I couldn't have asked for more.
>
> Well, I always can ask for more because I'm a PITA. Please add the logg...

Read more...

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

elopio> nik90: oh, and I forgot one more thing. Try to be consistent on your use of 'strings' vrs "strings". I prefer the single quote.

Fixed in rev 344

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

I've not yet run it on the phone, some thoughts;

Can you explain what this temp fix is, etc? bug number?
containerHeight: itemHeight * 7 // Temporary fix for autopilot

I like the changes to page up and page down with _wait_to_stop_moving.

Yay for using _ to start function names of utility functions :-)

Probably should try and be consistent on all of your docstrings, add them for all the emulator functions.

Your ' and " are still inconsistent, since elopio mentioned it :-) My preference is probably different than his; strings are ", literal strings are '.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Thanks for your review Nicholas. I am happy that you like the changes to the emulator functions in terms of naming and other subtle changes.

>
> Can you explain what this temp fix is, etc? bug number?
> containerHeight: itemHeight * 7 // Temporary fix for autopilot
>

Fixed in rev 351. I have added a detailed comment there explaining why that fix is needed for the AP tests.

>
> Probably should try and be consistent on all of your docstrings, add them for
> all the emulator functions.
>

In this MP I want to only modify/improve the alarm tests. I do not want to change other parts of the tests. As a result, looking at the test_alarm.py and the alarm emulator functions, all of them have a docstring explaining what they. I added better docstrings for the alarm tests in rev 352.

> Your ' and " are still inconsistent, since elopio mentioned it :-) My
> preference is probably different than his; strings are ", literal strings are
> '.

As far as the alarms AP is concerned, I have made all of the consistently to using single quotes. There are inconsistencies in stopwatch, timer and clock tests. But I rather address in another MP than this one.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Yes, I agree not to inflate the merge with lots of changes in other places. This is looking REALLY good :-)

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Leo Arias (elopio) wrote :

Thanks for all your work on this.

review: Approve (code review)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'alarm/AddAlarmPage.qml'
--- alarm/AddAlarmPage.qml 2014-02-10 13:55:59 +0000
+++ alarm/AddAlarmPage.qml 2014-02-19 00:55:51 +0000
@@ -310,6 +310,7 @@
310310
311 Label {311 Label {
312 id: hourLabel312 id: hourLabel
313 objectName: "hourLabel"
313 color: "LightGreen"314 color: "LightGreen"
314 font.pixelSize: units.dp(55)315 font.pixelSize: units.dp(55)
315 anchors.verticalCenter: parent.verticalCenter316 anchors.verticalCenter: parent.verticalCenter
@@ -336,6 +337,7 @@
336337
337 Label {338 Label {
338 id: minuteLabel339 id: minuteLabel
340 objectName: "minuteLabel"
339 font.pixelSize: units.dp(41)341 font.pixelSize: units.dp(41)
340 anchors.verticalCenter: parent.verticalCenter342 anchors.verticalCenter: parent.verticalCenter
341 onTextChanged: if(addAlarmFace.state == "minuteMode") updateHoursOnMinuteRotation()343 onTextChanged: if(addAlarmFace.state == "minuteMode") updateHoursOnMinuteRotation()
@@ -489,7 +491,13 @@
489 objectName: "OccursSelector"491 objectName: "OccursSelector"
490 text: i18n.tr("Occurs")492 text: i18n.tr("Occurs")
491 visible: repeatSwitch.checked == false // Show the day selector only when the alarm is a one-type alarm493 visible: repeatSwitch.checked == false // Show the day selector only when the alarm is a one-type alarm
492 containerHeight: itemHeight * 4494
495 // TODO: To avoid a long option selector list, it would be best to only show 4 days at a time and encourage
496 // scrolling the option selector to choose other days. However this is blocked by http://pad.lv/1277059 since
497 // showing only 4 days will inhibit the alarm autopilot tests since they use a custom emulator function.
498 // -- nik90 2014-02-10
499 containerHeight: itemHeight * 7
500
493 model: [Qt.locale().standaloneDayName(0), Qt.locale().standaloneDayName(1), Qt.locale().standaloneDayName(2), Qt.locale().standaloneDayName(3), Qt.locale().standaloneDayName(4), Qt.locale().standaloneDayName(5), Qt.locale().standaloneDayName(6)]501 model: [Qt.locale().standaloneDayName(0), Qt.locale().standaloneDayName(1), Qt.locale().standaloneDayName(2), Qt.locale().standaloneDayName(3), Qt.locale().standaloneDayName(4), Qt.locale().standaloneDayName(5), Qt.locale().standaloneDayName(6)]
494502
495 selectedIndex: alarm.date.getDay();503 selectedIndex: alarm.date.getDay();
@@ -523,9 +531,9 @@
523531
524 ListItem.MultiValue {532 ListItem.MultiValue {
525 id: multipleOccurSelector533 id: multipleOccurSelector
526 anchors { left: parent.left; right: parent.right; margins: -units.gu(2) }
527 text: i18n.tr("Occurrence")
528 objectName: "OccurrenceList"534 objectName: "OccurrenceList"
535 anchors { left: parent.left; right: parent.right; margins: -units.gu(2) }
536 text: i18n.tr("Occurrence")
529 values: getValues()537 values: getValues()
530 visible: repeatSwitch.checked == true538 visible: repeatSwitch.checked == true
531 onClicked: PopupUtils.open(Qt.resolvedUrl("AlarmDays.qml"), multipleOccurSelector, {"alarm": alarm});539 onClicked: PopupUtils.open(Qt.resolvedUrl("AlarmDays.qml"), multipleOccurSelector, {"alarm": alarm});
532540
=== modified file 'alarm/AlarmDays.qml'
--- alarm/AlarmDays.qml 2014-02-01 15:30:26 +0000
+++ alarm/AlarmDays.qml 2014-02-19 00:55:51 +0000
@@ -73,6 +73,7 @@
73 }73 }
7474
75 control: Switch {75 control: Switch {
76 objectName: "repeatDaysSwitch" + index
76 checked: (alarm.daysOfWeek & flag) == flag77 checked: (alarm.daysOfWeek & flag) == flag
77 onCheckedChanged: {78 onCheckedChanged: {
78 if (checked)79 if (checked)
@@ -87,6 +88,7 @@
8788
88 Button {89 Button {
89 text: "Done"90 text: "Done"
91 objectName: "confirmRepeatDaysButton"
90 onClicked: PopupUtils.close(root);92 onClicked: PopupUtils.close(root);
91 }93 }
92}94}
9395
=== modified file 'alarm/AlarmPage.qml'
--- alarm/AlarmPage.qml 2014-02-11 15:45:26 +0000
+++ alarm/AlarmPage.qml 2014-02-19 00:55:51 +0000
@@ -202,9 +202,10 @@
202 currentIndex: -1202 currentIndex: -1
203203
204 delegate: ListItem.Base {204 delegate: ListItem.Base {
205 objectName: "alarm" + index
205 Label {206 Label {
206 id: alarmTime207 id: alarmTime
207 objectName: "listAlarmTime"208 objectName: "listAlarmTime" + index
208 fontSize: "large";209 fontSize: "large";
209 text: Utils.convertTime(date.getHours(), date.getMinutes(), 0, appSetting.contents.timeFormat)210 text: Utils.convertTime(date.getHours(), date.getMinutes(), 0, appSetting.contents.timeFormat)
210 anchors { verticalCenter: parent.verticalCenter; right: alarmStatus.left; rightMargin: units.gu(2) }211 anchors { verticalCenter: parent.verticalCenter; right: alarmStatus.left; rightMargin: units.gu(2) }
@@ -213,7 +214,7 @@
213214
214 Label {215 Label {
215 id: alarmLabel216 id: alarmLabel
216 objectName: "listAlarmLabel"217 objectName: "listAlarmLabel" + index
217 fontSize: "large";218 fontSize: "large";
218 text: message219 text: message
219 elide: Text.ElideRight220 elide: Text.ElideRight
@@ -230,7 +231,7 @@
230231
231 Label {232 Label {
232 id: alarmSubtitle233 id: alarmSubtitle
233 objectName: "listAlarmSubtitle"234 objectName: "listAlarmSubtitle" + index
234 fontSize: "small";235 fontSize: "small";
235 text: format_day_string(daysOfWeek, type)236 text: format_day_string(daysOfWeek, type)
236 anchors { left: alarmLabel.left; top: alarmLabel.bottom }237 anchors { left: alarmLabel.left; top: alarmLabel.bottom }
@@ -239,7 +240,7 @@
239240
240 Switch {241 Switch {
241 id: alarmStatus242 id: alarmStatus
242 objectName: "listAlarmStatus"243 objectName: "listAlarmStatus" + index
243 checked: model.enabled244 checked: model.enabled
244 anchors { right: parent.right; verticalCenter: alarmTime.verticalCenter }245 anchors { right: parent.right; verticalCenter: alarmTime.verticalCenter }
245 onClicked: {246 onClicked: {
246247
=== modified file 'tests/autopilot/ubuntu_clock_app/emulators.py'
--- tests/autopilot/ubuntu_clock_app/emulators.py 2014-02-05 15:18:08 +0000
+++ tests/autopilot/ubuntu_clock_app/emulators.py 2014-02-19 00:55:51 +0000
@@ -1,6 +1,6 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#2#
3# Copyright (C) 2013 Canonical Ltd.3# Copyright (C) 2013, 2014 Canonical Ltd.
4#4#
5# This program is free software; you can redistribute it and/or modify5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published by6# it under the terms of the GNU Lesser General Public License as published by
@@ -17,21 +17,26 @@
17# Authored by: Nekhelesh Ramananthan <krnekhelesh@gmail.com>17# Authored by: Nekhelesh Ramananthan <krnekhelesh@gmail.com>
18# Nicholas Skaggs <nicholas.skaggs@canonical.com>18# Nicholas Skaggs <nicholas.skaggs@canonical.com>
1919
20import logging
21from time import sleep
22
23from autopilot import logging as autopilot_logging
20from ubuntuuitoolkit import emulators as toolkit_emulators24from ubuntuuitoolkit import emulators as toolkit_emulators
21from autopilot.matchers import Eventually25
22from testtools.matchers import Not, Is, Equals26logger = logging.getLogger(__name__)
23from time import sleep27
28
29class ClockEmulatorException(toolkit_emulators.ToolkitEmulatorException):
30 """Exception raised when there is an error with the emulator."""
31
2432
25class MainView(toolkit_emulators.MainView):33class MainView(toolkit_emulators.MainView):
2634
27 # Common Emulator Functions35 # Common Emulator Functions
28 def _drag_page(self, page, test_case, direction):36 def _drag_page(self, page, direction):
29 """Function to drag the page up/down"""37 """Function to drag the page up/down"""
30 page = self.wait_select_single(page)38 page = self.wait_select_single(page)
31 animating = lambda: page.select_single("QQuickFlickable").moving39 self._wait_to_stop_moving(page)
32
33 #make sure we're not already moving :-)
34 test_case.assertThat(animating, Eventually(Equals(False)))
3540
36 x, y, w, h = page.globalRect41 x, y, w, h = page.globalRect
37 tx = x + (w / 2)42 tx = x + (w / 2)
@@ -42,15 +47,15 @@
42 else:47 else:
43 self.pointing_device.drag(tx, ty, tx, ty - h / 3)48 self.pointing_device.drag(tx, ty, tx, ty - h / 3)
4449
45 test_case.assertThat(animating, Eventually(Equals(False)))50 self._wait_to_stop_moving(page)
4651
47 def drag_page_up(self, page, test_case):52 def drag_page_up(self, page):
48 """Drag the given page up."""53 """Drag the given page up."""
49 self._drag_page(page, test_case, "up")54 self._drag_page(page, "up")
5055
51 def drag_page_down(self, page, test_case):56 def drag_page_down(self, page):
52 """Drag the given page down."""57 """Drag the given page down."""
53 self._drag_page(page, test_case, "down")58 self._drag_page(page, "down")
5459
55 def longpress_object(self, obj):60 def longpress_object(self, obj):
56 """Function to longpress an object"""61 """Function to longpress an object"""
@@ -59,6 +64,9 @@
59 sleep(2)64 sleep(2)
60 self.pointing_device.release()65 self.pointing_device.release()
6166
67 def _wait_to_stop_moving(self, page):
68 page.select_single("QQuickFlickable").moving.wait_for(False)
69
62 # CLOCK Page Emulator Functions70 # CLOCK Page Emulator Functions
63 def get_clock_page(self):71 def get_clock_page(self):
64 """Return the page containing the main clock."""72 """Return the page containing the main clock."""
@@ -108,7 +116,7 @@
108116
109 def get_timer_name_preset(self):117 def get_timer_name_preset(self):
110 """Returns the TextField where insert the name of the preset"""118 """Returns the TextField where insert the name of the preset"""
111 return self.wait_select_single("LabelDots", objectName="namePreset")119 return self.wait_select_single(LabelDots, objectName="namePreset")
112120
113 def get_timer_minute_hand(self):121 def get_timer_minute_hand(self):
114 """Returns the hour hand of clock in timer tab"""122 """Returns the hour hand of clock in timer tab"""
@@ -167,156 +175,175 @@
167 # ALARM Page Emulator Functions175 # ALARM Page Emulator Functions
168 def get_addalarm_page(self):176 def get_addalarm_page(self):
169 """Returns the add alarm page object"""177 """Returns the add alarm page object"""
170 return self.select_single("Page", objectName="addAlarmPage")178 return self.select_single('Page', objectName='addAlarmPage')
171179
172 def get_alarm_page(self):180 def get_alarm_page(self):
173 """Returns the alarm page object"""181 """Returns the alarm page object"""
174 return self.select_single("AlarmPage")182 return self.select_single('AlarmPage')
175183
176 def get_alarm_name_label(self):184 @autopilot_logging.log_action(logger.info)
177 """Returns the TextField where insert the name of the preset"""185 def add_alarm(self, name, alarm_type, day):
178 return self.select_single("LabelDots", objectName="addAlarmName")186 """Function to add an alarm"""
179187 self._click_add_alarm_button()
180 def get_label_alarm(self):188 self._set_alarm_time()
181 """Return the label with the alarm"""189 self.drag_page_up('AddAlarmPage')
182 return self.select_single("Label", objectName="labelAlarmSetup")190 self._set_alarm_name(name)
191 self._click_alarm_hour_label()
192 self._set_alarm_type(alarm_type)
193 self.drag_page_up('AddAlarmPage')
194 self._set_alarm_trigger_day(day, alarm_type)
195 self._click_save_alarm_button()
196
197 def _click_add_alarm_button(self):
198 """Internal function to click add alarm toolbar button"""
199 toolbar = self.open_toolbar()
200 toolbar.click_button('addAlarmButton')
201
202 def _set_alarm_name(self, name):
203 """Internal funcion to set alarm name"""
204 name_alarm = self.wait_select_single(
205 LabelDots, objectName='addAlarmName')
206 name_alarm.write(name)
207
208 def _set_alarm_time(self):
209 """Internal function to set alarm time"""
210 self._click_alarm_hour_label()
211 hour = self._get_alarm_hour_hand()
212
213 x, y, w, h = hour.globalRect
214 tx = x + (w // 2)
215 ty = y + (h // 2.5)
216 self.pointing_device.drag(
217 tx, ty - (h // 4), tx - (w // 2), ty + (h // 2))
218
219 self._click_alarm_minute_label()
220 minute = self._get_alarm_minute_hand()
221
222 x, y, w, h = minute.globalRect
223 tx = x + (w // 2)
224 ty = y + (h // 2.5)
225 self.pointing_device.drag(
226 tx, ty - (h // 4), tx + (w // 2), ty + (h // 2))
227
228 def _click_alarm_hour_label(self):
229 """Internal function to click alarm hour label"""
230 hour_label = self.wait_select_single(
231 'Label', objectName='hourLabel')
232 self.pointing_device.click_object(hour_label)
233
234 def _click_alarm_minute_label(self):
235 """Internal function to click alarm minute label"""
236 minute_label = self.wait_select_single(
237 'Label', objectName='minuteLabel')
238 self.pointing_device.click_object(minute_label)
239
240 def _get_alarm_hour_hand(self):
241 """Returns the hour hand of clock in add alarm page"""
242 return self.select_single("AddAlarmPage").wait_select_single(
243 'DialerHand', objectName='hourHand')
244
245 def _get_alarm_minute_hand(self):
246 """Returns the minute hand of clock in add alarm page"""
247 return self.select_single("AddAlarmPage").wait_select_single(
248 'DialerHand', objectName='minuteHand')
249
250 def _set_alarm_type(self, alarm_type):
251 """Internal function to set the alarm type"""
252 alarm_type_checkbox = self.wait_select_single(
253 toolkit_emulators.CheckBox, objectName='RepeatSelector')
254 if alarm_type == 'Single':
255 alarm_type_checkbox.uncheck()
256 else:
257 alarm_type_checkbox.check()
258
259 def _set_alarm_trigger_day(self, day, alarm_type):
260 """Internal function to set the day the alarm triggers on"""
261 if alarm_type == 'Single':
262 self._set_single_alarm_day(day)
263 else:
264 self._set_recurring_alarm_day()
265
266 def _set_single_alarm_day(self, day):
267 """Internal function to set the alarm day of a single type alarm"""
268 # TODO: we need a proper UITK emulator for optionSelector
269 # http://pad.lv/1277059 --nik90 2014-02-06
270 day_option_selector = self.select_single(
271 'OptionSelector', objectName='OccursSelector')
272 days_object = day_option_selector.select_single(
273 'StyledItem', objectName='listContainer')
274 dayslist = days_object.select_many('Label', visible=True)
275
276 # Click on days option selector to expand it
277 self.pointing_device.click_object(dayslist[0])
278
279 for index, day_element in enumerate(dayslist):
280 if(day_element.text == day):
281 day_index = index
282 break
283 else:
284 raise ClockEmulatorException('Unknown day: {}'.format(day))
285
286 self.drag_page_up('AddAlarmPage')
287 self.pointing_device.click_object(dayslist[day_index])
288
289 def _set_recurring_alarm_day(self):
290 """Internal function to set the alarm days of a recurring alarm"""
291 self._open_recurring_alarm_dialog()
292
293 # Get all the day objects in the column and enable only those
294 # days whose index is an even number and disable the others
295 for index in range(7):
296 day_element = self.wait_select_single(
297 toolkit_emulators.CheckBox,
298 objectName='repeatDaysSwitch{}'.format(index))
299 if index % 2 == 0:
300 day_element.check()
301 else:
302 day_element.uncheck()
303
304 self._click_confirm_recurring_alarm_days()
305
306 def _open_recurring_alarm_dialog(self):
307 """Internal function to open the recurring alarm dialogue"""
308 recurring_option = self.wait_select_single(
309 toolkit_emulators.MultiValue, objectName='OccurrenceList')
310 self.pointing_device.click_object(recurring_option)
311
312 def _click_confirm_recurring_alarm_days(self):
313 """Internal function to click Done button in recurring alarms dialog"""
314 done_button = self.wait_select_single(
315 'Button', objectName='confirmRepeatDaysButton')
316 self.pointing_device.click_object(done_button)
317
318 def _click_save_alarm_button(self):
319 """Click the save alarm button"""
320 toolbar = self.open_toolbar()
321 toolbar.click_button('saveAlarmButton')
183322
184 def get_num_of_alarms(self):323 def get_num_of_alarms(self):
185 """Returns the number of alarms in the alarm page."""324 """Return the number of saved alarms"""
186 listview = self.select_single("QQuickListView",325 return int(self.wait_select_single(
187 objectName="listSavedAlarm")326 toolkit_emulators.QQuickListView,
188 #each alarm has 3 labels327 objectName='listSavedAlarm').count)
189 return len(listview.select_many("Label", visible=True)) / 3328
190329 @autopilot_logging.log_action(logger.info)
191 #TODO: QQuickListView.count does not work as expected330 def delete_alarm(self, index):
192 #fix once this is working properly and use it331 """Deletes an alarm at the specified index"""
193332 alarm = self.wait_select_single(
194 #TODO: all of the get_first functions need to333 toolkit_emulators.Base, objectName='alarm{}'.format(index))
195 #be refactored where possible to get X item, not334 self.drag_page_up('AlarmPage')
196 #just the first335 alarm.swipe_to_delete()
197336 alarm.confirm_removal()
198 def get_first_alarm_list_item(self):337
199 """Returns the first alarm list item in the alarm page."""338 @autopilot_logging.log_action(logger.info)
200 listview = self.select_single("QQuickListView",339 def toggle_alarm(self, index):
201 objectName="listSavedAlarm")340 """Toggles an alarm on/off"""
202 return listview.select_many("Base")[0]341 alarm = self.wait_select_single(
203342 toolkit_emulators.CheckBox,
204 def toggle_first_alarm(self, test_case):343 objectName='listAlarmStatus{}'.format(index))
205 """Toggles the alarm on and off in the alarm page."""344 self.drag_page_up('AlarmPage')
206 alarm = self.select_single("CheckBox",
207 objectName="listAlarmStatus")
208 self.pointing_device.click_object(alarm)345 self.pointing_device.click_object(alarm)
209346
210 test_case.assertThat(lambda: self.get_alarm_page().select_single(347
211 "QQuickFlickable").moving,348class LabelDots(toolkit_emulators.TextField):
212 Eventually(Equals(False)))349 """Autopilot helper for the LabelDots component."""
213
214 def get_first_alarm_time(self):
215 """Gets the first alarm time in the alarm page."""
216 alarm = self.get_first_alarm_list_item()
217 return alarm.select_single("Label",
218 objectName="listAlarmTime").text
219
220 def get_first_alarm_subtitle(self):
221 """Gets the first alarm subtitle in the alarm page."""
222 alarm = self.get_first_alarm_list_item()
223 return alarm.select_single("Label",
224 objectName="listAlarmSubtitle").text
225
226 def get_first_alarm_label(self):
227 """Gets the first alarm label in the alarm page."""
228 alarm = self.get_first_alarm_list_item()
229 return alarm.select_single("Label",
230 objectName="listAlarmLabel").text
231
232 def get_first_alarm_status(self):
233 """Gets the first alarm checkbox status in the alarm page."""
234 alarm = self.get_first_alarm_list_item()
235 return alarm.select_single("CheckBox",
236 objectName="listAlarmStatus").checked
237
238 def get_alarm_minute_hand(self):
239 """Returns the hour hand of clock in alarm tab"""
240 return self.select_single("AlarmPage").select_single("DialerHand",
241 objectName="minuteHand")
242
243 def get_alarm_hour_hand(self):
244 """Returns the hour hand of clock in alarm tab"""
245 return self.select_single("AlarmPage").select_single("DialerHand",
246 objectName="hourHand")
247
248 def set_alarm_week(self, day, test_case):
249 #TODO: add support for setting days of week
250 dayselectDialog = self.select_single("Dialog",
251 objectName="alarmDaysDialog")
252
253 return dayselectDialog
254
255 def _retry_selector_assert(self, clickobj, selector, status, test_case):
256 test_case.assertThat(lambda: self.get_alarm_page().select_single(
257 "QQuickFlickable").moving,
258 Eventually(Equals(False)))
259 timeout = 0
260 test_case.assertThat(lambda: selector.select_single(
261 "OptionSelectorDelegate", selected=True),
262 Eventually(Not(Is(None))))
263
264 option = selector.select_single("OptionSelectorDelegate",
265 selected=True).state
266 while option != status and timeout < 10:
267 self.pointing_device.click_object(clickobj)
268 option = selector.select_single("OptionSelectorDelegate",
269 selected=True).state
270 sleep(1)
271 timeout += 1
272
273 test_case.assertThat(lambda: self.get_alarm_page().select_single(
274 "QQuickFlickable").moving,
275 Eventually(Equals(False)))
276
277 def set_alarm_day(self, day, test_case):
278 select = self.select_single("OptionSelector",
279 objectName="OccursSelector")
280 occur = select.select_single("StyledItem", objectName="listContainer")
281 #optionslist = occur.select_single("OptionSelectorDelegate",
282 # selected=True)
283 occurlist = occur.select_many("Label", visible=True)
284
285 self.pointing_device.click_object(select)
286 self._retry_selector_assert(select, occur,
287 "dividerExpanded", test_case)
288
289 self.drag_page_up("AlarmPage", test_case)
290 self.pointing_device.click_object(occurlist[day])
291 self._retry_selector_assert(select, occur,
292 "dividerCollapsed", test_case)
293
294 #check index
295 #TODO: clock doesn't put things in in the proper order atm
296 #test_case.assertThat(lambda: self.select_single("OptionSelector",
297 # objectName="OccursSelector").selectedIndex+1,
298 # Eventually(Equals(day)))
299
300 def set_alarm_frequency(self, occurence, test_case):
301 select = self.select_single("OptionSelector",
302 objectName="RepeatSelector")
303 repeat = select.select_single("StyledItem",
304 objectName="listContainer")
305 #optionslist = occur.select_single("OptionSelectorDelegate",
306 # selected=True)
307 repeatlist = repeat.select_many("Label", visible=True)
308
309 self.pointing_device.click_object(repeat)
310 self._retry_selector_assert(select, repeat,
311 "dividerExpanded", test_case)
312
313 self.drag_page_up("AlarmPage", test_case)
314 self.pointing_device.click_object(repeatlist[occurence])
315 self._retry_selector_assert(select, repeat,
316 "dividerCollapsed", test_case)
317
318 #check index
319 test_case.assertThat(lambda: self.select_single(
320 "OptionSelector", objectName="RepeatSelector").selectedIndex+1,
321 Eventually(Equals(occurence)))
322
323350
=== modified file 'tests/autopilot/ubuntu_clock_app/tests/__init__.py'
--- tests/autopilot/ubuntu_clock_app/tests/__init__.py 2014-02-10 22:41:51 +0000
+++ tests/autopilot/ubuntu_clock_app/tests/__init__.py 2014-02-19 00:55:51 +0000
@@ -118,4 +118,4 @@
118118
119 @property119 @property
120 def main_view(self):120 def main_view(self):
121 return self.app.select_single(emulators.MainView)121 return self.app.wait_select_single(emulators.MainView)
122122
=== modified file 'tests/autopilot/ubuntu_clock_app/tests/test_alarm.py'
--- tests/autopilot/ubuntu_clock_app/tests/test_alarm.py 2014-01-21 15:10:14 +0000
+++ tests/autopilot/ubuntu_clock_app/tests/test_alarm.py 2014-02-19 00:55:51 +0000
@@ -1,6 +1,6 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#2#
3# Copyright (C) 2013 Canonical Ltd3# Copyright (C) 2013, 2014 Canonical Ltd
4#4#
5# This program is free software: you can redistribute it and/or modify5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3 as6# it under the terms of the GNU General Public License version 3 as
@@ -15,284 +15,101 @@
15# along with this program. If not, see <http://www.gnu.org/licenses/>.15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#16#
17# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>17# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
18# Nekhelesh Ramananthan <krnekhelesh@gmail.com>
1819
19"""Tests for the Clock App - Alarm"""20"""Tests for the Clock App - Alarm"""
2021
21from __future__ import absolute_import22from __future__ import absolute_import
2223
23from testtools.matchers import Equals, NotEquals, Is, Not24import datetime
25import unittest
26
24from autopilot.matchers import Eventually27from autopilot.matchers import Eventually
25import time28from testtools.matchers import Equals, NotEquals
26import datetime
27from ubuntu_clock_app.tests import ClockAppTestCase29from ubuntu_clock_app.tests import ClockAppTestCase
28import unittest
2930
3031
31class TestAlarm(ClockAppTestCase):32class TestAlarm(ClockAppTestCase):
32 """Tests the alarm page features"""33 """Tests the alarm page features"""
3334
34 """ This is needed to wait for the application to start.
35 In the testfarm, the application may take some time to show up."""
36
37 #TODO: alarms shares similarities with stopwatch
38 #the utility functions could be shared between them
39 #ie, the emulator functions
40 def setUp(self):35 def setUp(self):
36 """ This is needed to wait for the application to start.
37
38 In the testfarm, the application may take some time to show up.
39
40 """
41 super(TestAlarm, self).setUp()41 super(TestAlarm, self).setUp()
42 self.assertThat(42 self.assertThat(
43 self.main_view.visible, Eventually(Equals(True)))43 self.main_view.visible, Eventually(Equals(True)))
4444
45 #move to alarm tab45 # move to alarm tab
46 self.main_view.switch_to_tab("AlarmTab")46 self.main_view.switch_to_tab('AlarmTab')
4747
48 def select_name_alarm_label(self):48 def test_add_single_type_alarm_must_add_to_alarm_list(self):
49 label = self.main_view.get_alarm_name_label()49 """Test to check if a single type alarm is saved properly
50 timeout = 050
51 while not label.focus and timeout < 10:51 This test saves a single type alarm and verifies if it is added to the
52 self.pointing_device.click_object(label)52 alarm list in the alarm page.
53 time.sleep(1)53
54 timeout += 154 """
55 return label55 # The alarm day is always set to tomorrow to ensure that it is
5656 # not rejected by the clock app since the clock app does not
57 @unittest.skip("Pending development, bug 1269064")57 # allow alarms to be created before the current time of the same
58 def test_longpress_new_alarm(self):58 # day. This limitation will be removed later.
59 """Test longpress on alarm and back button"""59 # -- nik90 2014-02-06
60 #TODO: needs this merge60 now = datetime.datetime.now() + datetime.timedelta(days=1)
61 #https://code.launchpad.net/~elopio/61 tomorrow_day = now.strftime("%A")
62 #ubuntu-ui-toolkit/fix1239751_go_back/+merge/19100262 old_alarm_count = self.main_view.get_num_of_alarms()
63 #thus is disabled for now until landing63 self.main_view.add_alarm('Single Test', 'Single', tomorrow_day)
6464
65 self.assertThat(self.main_view.get_label_alarm,65 # Check if the alarm count has increased
66 Eventually(Not(Is(None))))66 self.assertThat(self.main_view.get_num_of_alarms,
67 self.main_view.longpress_object(self.main_view.get_label_alarm())67 Eventually(NotEquals(old_alarm_count)))
6868
69 self.assertThat(self.main_view.get_addalarm_page,69 #TODO: Check if the newly saved alarm has the properties set by
70 Eventually(Not(Is(None))))70 # add_alarm method
7171
72 toolbar = self.main_view.open_toolbar()72 def test_add_recurring_type_alarm_must_add_to_alarm_list(self):
7373 """ Test to check if a recurring alarm is saved properly
74 # Click the add alarm button74
75 toolbar.go_back()75 Recurring alarms are triggered on more than one day. This test saves a
7676 recurring alarm and check if it has been saved and is added to the
77 self.assertThat(self.main_view.get_alarm_page,77 alarm list in the alarm page.
78 Eventually(Not(Is(None))))78
7979 """
80 @unittest.skip("Pending development, bug 1269064")80 old_alarm_count = self.main_view.get_num_of_alarms()
81 def test_add_remove_alarm(self):81 self.main_view.add_alarm('Recurring Test', 'Recurring', 'Null')
82 """Test to check if button to add and remove an alarm working"""82
8383 # Check if the alarm count has increased
84 #test once84 self.assertThat(self.main_view.get_num_of_alarms,
85 #use tomorrow as day85 Eventually(NotEquals(old_alarm_count)))
86 day = datetime.datetime.today().weekday() + 186
87 if day > 7:87 def test_delete_alarm_must_delete_from_alarm_list(self):
88 day = 088 """Test to delete an alarm and check if it has been properly removed"""
89 self.add_alarm(day, 1)89 # FIXME: Instead of always deleting the first alarm, run the alarm
90 self.delete_alarm()90 # which was created. To do this in a nice way, we should use the
9191 # QQuickListView but it has a bug that makes it fail in this case:
92 #test daily92 # http://pad.lv/1275060 --elopio - 2014-01-31
93 self.add_alarm(4, 2)93
94 self.delete_alarm()94 # (set-up) Create a recurring alarm
9595 self.main_view.add_alarm('Recurring Test', 'Recurring', 'Null')
96 #test weekly96
97 #self.add_alarm(1, 3)97 old_alarm_count = self.main_view.get_num_of_alarms()
98 #self.delete_alarm()98 self.main_view.delete_alarm(index=0)
9999
100 def add_alarm(self, day, occurence):100 # Check that the alarm is deleted
101 #setTime = "16:20"101 self.assertThat(self.main_view.get_num_of_alarms,
102102 Eventually(Equals(old_alarm_count - 1)))
103 # Show the toolbar103
104 toolbar = self.main_view.open_toolbar()104 @unittest.skip("Pending development, bug 1272337")
105105 def test_toggle_alarm_status_must_enable_or_disable_alarm(self):
106 # Click the add alarm button106 """Test to toggle an alarm and check it has been done properly"""
107 toolbar.click_button("addAlarmButton")107 # FIXME: This test is skipped due to an upstream bug in EDS which
108108 # causes the alarm status to not be properly toggled. This could
109 self.assertThat(lambda: self.main_view.get_alarm_page().select_single(109 # result in flaky test.
110 "QQuickFlickable").moving,110 # http://pad.lv/1272337 -- nik90 - 2014-02-07
111 Eventually(Equals(False)))111
112112 # (set-up) Create a recurring alarm
113 #TODO: these should be broken out for reuse in timer as well113 self.main_view.add_alarm('Recurring Test', 'Recurring', 'Null')
114 #as well as allowing for various times114
115 # Set hour115 self.main_view.toggle_alarm(index=0)
116 self.assertThat(self.main_view.get_alarm_hour_hand,
117 Eventually(Not(Is(None))))
118 hour = self.main_view.get_alarm_hour_hand()
119
120 x, y, w, h = hour.globalRect
121 tx = x + (w / 2)
122 ty = y + (h / 2)
123 self.pointing_device.drag(tx, ty - (h / 4), tx - (w / 2), ty + (h / 2))
124
125 self.assertThat(lambda: self.main_view.get_alarm_page().select_single(
126 "QQuickFlickable").moving,
127 Eventually(Equals(False)))
128
129 # Set minute
130 self.assertThat(self.main_view.get_alarm_minute_hand,
131 Eventually(Not(Is(None))))
132 minute = self.main_view.get_alarm_minute_hand()
133
134 x, y, w, h = minute.globalRect
135 tx = x + (w / 2)
136 ty = y + (h / 2.5)
137 self.pointing_device.drag(tx, ty - (h / 4), tx + (w / 2), ty + (h / 2))
138
139 self.assertThat(lambda: self.main_view.get_alarm_page().select_single(
140 "QQuickFlickable").moving,
141 Eventually(Equals(False)))
142
143 #TODO: Choosing the same day hides the day
144 #https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1240629
145
146 self.edit_alarm(day, occurence)
147
148
149 #TODO: fix time check.. time doesn't always set properly
150 #and will randomly fail the test
151 #self.assertThat(self.main_view.get_first_alarm_time,
152 # Eventually(Equals(setTime)))
153
154 def edit_alarm(self, day, occurence):
155 setName = "test" + str(int(time.time()))
156 setStatus = True
157
158 # Write in the label
159 self.main_view.drag_page_up("AlarmPage", self)
160 self.assertThat(self.main_view.get_alarm_name_label,
161 Eventually(Not(Is(None))))
162 label = self.select_name_alarm_label()
163 self.assertThat(label.focus, Eventually(Equals(True)))
164 self.keyboard.press('Ctrl+a')
165 self.assertThat(label.focus, Eventually(Equals(True)))
166
167 #set unique alarm name
168 self.keyboard.type(setName)
169 self.assertThat(label.text, Eventually(Equals(setName)))
170
171 #set alarm day and frequency
172 self.main_view.set_alarm_frequency(occurence, self)
173
174 #depending on occurrence, we set the day differently
175 if occurence == 1:
176 #one time, use day passed in
177 self.main_view.set_alarm_day(day, self)
178 elif occurence == 2:
179 #daily, ignore day
180 pass
181 elif occurence == 3:
182 #weekly, pass day into dialog
183 #TODO: support weekly dialog
184 self.main_view.set_alarm_week(day, self)
185
186 #grab current alarm number
187 self.assertThat(self.main_view.get_num_of_alarms,
188 Eventually(Not(Is(None))))
189 num_of_alarms_old = self.main_view.get_num_of_alarms()
190
191 # Press "Save" toolbar button
192 toolbar = self.main_view.open_toolbar()
193 toolbar.click_button("saveAlarmButton")
194
195 #assert alarm is added
196 self.assertThat(self.main_view.get_num_of_alarms,
197 Eventually(NotEquals(num_of_alarms_old)))
198
199 #check label, time, subtitle, name
200 #TODO: decipher proper subtitles and check for them
201 #self.assertThat(self.main_view.get_first_alarm_subtitle,
202 # Eventually(Equals( ? )))
203
204 self.assertThat(self.main_view.get_first_alarm_label,
205 Eventually(Not(Is(None))))
206
207 self.assertThat(self.main_view.get_first_alarm_label,
208 Eventually(Equals(setName)))
209
210 self.assertThat(self.main_view.get_first_alarm_status,
211 Eventually(Equals(setStatus)))
212
213 def delete_alarm(self):
214 """Test if the swipe of a alarm deletes it"""
215 #TODO: fix this with https://code.launchpad.net/~renatofilho/
216 #ubuntu-ui-toolkit/fix-1236464/+merge/190496
217 #once it lands
218 self.assertThat(self.main_view.get_num_of_alarms,
219 Eventually(Not(Is(None))))
220 num_of_alarms_old = self.main_view.get_num_of_alarms()
221
222 self.main_view.drag_page_up("AlarmPage", self)
223
224 # Delete the alarm
225 self.assertThat(self.main_view.get_first_alarm_list_item,
226 Eventually(Not(Is(None))))
227 timeout = 0
228 while self.main_view.get_num_of_alarms() != num_of_alarms_old - 1 \
229 and timeout < 10:
230 first_alarm = self.main_view.get_first_alarm_list_item()
231 x, y, w, h = first_alarm.globalRect
232 tx = x + (w / 8)
233 ty = y + (h / 2)
234 self.pointing_device.drag(tx, ty, w - w / 8, ty)
235 time.sleep(1)
236 timeout += 1
237
238 # Check has been deleted
239 self.assertThat(
240 self.main_view.get_num_of_alarms,
241 Eventually(Equals(num_of_alarms_old - 1)))
242
243 @unittest.skip("Pending development, bug 1269064")
244 def test_toggle_and_edit_alarm(self):
245 """Tests if a alarm can be toggled on and off and edited"""
246
247 # Create a new alarm
248 self.add_alarm(1, 2)
249
250 self.main_view.drag_page_up("AlarmPage", self)
251
252 # Click to select the alarm
253 self.assertThat(self.main_view.get_first_alarm_list_item,
254 Eventually(Not(Is(None))))
255 first_alarm = self.main_view.get_first_alarm_list_item()
256
257 #grab current values
258 self.assertThat(self.main_view.get_first_alarm_label,
259 Eventually(Not(Is(None))))
260
261 oldName = self.main_view.get_first_alarm_label()
262 oldStatus = self.main_view.get_first_alarm_status()
263
264 # Perform edit
265 self.pointing_device.click_object(first_alarm)
266
267 #TODO: objects aren't quite the same :-(
268 #self.edit_alarm(1, 1)
269 #just save it instead
270 toolbar = self.main_view.open_toolbar()
271 toolbar.click_button("saveAlarmButton")
272
273 #verify everything is still good
274 self.assertThat(self.main_view.get_first_alarm_label,
275 Eventually(Not(Is(None))))
276
277 self.assertThat(self.main_view.get_first_alarm_label,
278 Eventually(Equals(oldName)))
279
280 self.assertThat(self.main_view.get_first_alarm_status,
281 Eventually(Equals(oldStatus)))
282
283 # Click to switch off the alarm
284 self.assertThat(self.main_view.get_first_alarm_status,
285 Eventually(Equals(True)))
286
287 self.main_view.toggle_first_alarm(self)
288
289 self.assertThat(self.main_view.get_first_alarm_status,
290 Eventually(Equals(False)))
291
292 # Click to switch on the alarm
293 self.main_view.toggle_first_alarm(self)
294
295 self.assertThat(self.main_view.get_first_alarm_status,
296 Eventually(Equals(True)))
297
298 self.delete_alarm()
299116
=== modified file 'tests/autopilot/ubuntu_clock_app/tests/test_clock.py'
--- tests/autopilot/ubuntu_clock_app/tests/test_clock.py 2014-02-05 15:28:52 +0000
+++ tests/autopilot/ubuntu_clock_app/tests/test_clock.py 2014-02-19 00:55:51 +0000
@@ -48,7 +48,7 @@
48 super(TestClock, self).tearDown()48 super(TestClock, self).tearDown()
4949
50 def add_local_world_city(self):50 def add_local_world_city(self):
51 # Open clock toolbar 51 # Open clock toolbar
52 self.main_view.open_toolbar()52 self.main_view.open_toolbar()
5353
54 # Click add city toolbar button54 # Click add city toolbar button
@@ -74,21 +74,21 @@
74 def test_add_local_world_city(self):74 def test_add_local_world_city(self):
75 """Test to check if adding a local listed world city works"""75 """Test to check if adding a local listed world city works"""
7676
77 # Add a local world city 77 # Add a local world city
78 city_name = self.add_local_world_city()78 city_name = self.add_local_world_city()
79 79
80 saved_city_name = self.main_view.get_city_name(self.main_view.grab_first_saved_city())80 saved_city_name = self.main_view.get_city_name(self.main_view.grab_first_saved_city())
81 self.assertThat(saved_city_name, Eventually(Equals(city_name))) 81 self.assertThat(saved_city_name, Eventually(Equals(city_name)))
82 82
83 def test_delete_local_world_city(self):83 def test_delete_local_world_city(self):
84 """Test to check if deleting a saved local world city works"""84 """Test to check if deleting a saved local world city works"""
8585
86 # Add a local world city 86 # Add a local world city
87 city_name = self.add_local_world_city()87 city_name = self.add_local_world_city()
8888
89 # Close toolbar and drag page up to see the saved world city list 89 # Close toolbar and drag page up to see the saved world city list
90 self.main_view.close_toolbar()90 self.main_view.close_toolbar()
91 self.main_view.drag_page_up("ClockPage", self)91 self.main_view.drag_page_up("ClockPage")
9292
93 # Get the saved world city and swipe to delete93 # Get the saved world city and swipe to delete
94 old_saved_city_count = self.main_view.get_saved_cities_list().count94 old_saved_city_count = self.main_view.get_saved_cities_list().count
9595
=== modified file 'tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py'
--- tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py 2013-12-17 22:17:08 +0000
+++ tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py 2014-02-19 00:55:51 +0000
@@ -49,7 +49,7 @@
49 def start_stop_stopwatch(self):49 def start_stop_stopwatch(self):
50 """Function to start/stop the stopwatch"""50 """Function to start/stop the stopwatch"""
51 start_stop_button = self.main_view.get_stopwatch_button()51 start_stop_button = self.main_view.get_stopwatch_button()
52 self.pointing_device.click_object(start_stop_button) 52 self.pointing_device.click_object(start_stop_button)
5353
54 def test_start_stop_reset_stopwatch(self):54 def test_start_stop_reset_stopwatch(self):
55 """Test to check the proper functioning of the start/stop/reset of stopwatch"""55 """Test to check the proper functioning of the start/stop/reset of stopwatch"""
@@ -105,7 +105,7 @@
105 self.create_lap()105 self.create_lap()
106106
107 num_of_laps_old = self.main_view.get_num_of_laps()107 num_of_laps_old = self.main_view.get_num_of_laps()
108 self.main_view.drag_page_up("StopwatchPage", self)108 self.main_view.drag_page_up("StopwatchPage")
109109
110 # Delete stopwatch lap110 # Delete stopwatch lap
111 first_lap = self.main_view.get_first_laps_list_item()111 first_lap = self.main_view.get_first_laps_list_item()
112112
=== modified file 'tests/autopilot/ubuntu_clock_app/tests/test_timer.py'
--- tests/autopilot/ubuntu_clock_app/tests/test_timer.py 2014-01-21 15:32:01 +0000
+++ tests/autopilot/ubuntu_clock_app/tests/test_timer.py 2014-02-19 00:55:51 +0000
@@ -44,17 +44,8 @@
44 # Move to Timer tab44 # Move to Timer tab
45 self.main_view.switch_to_tab("TimerTab")45 self.main_view.switch_to_tab("TimerTab")
4646
47 def select_name_preset_label(self):
48 label = self.main_view.get_timer_name_preset()
49 timeout = 0
50 while not label.focus and timeout < 10:
51 self.pointing_device.click_object(label)
52 sleep(1)
53 timeout += 1
54 return label
55
56 def delete_first_preset(self):47 def delete_first_preset(self):
57 self.main_view.drag_page_up("TimerPage", self)48 self.main_view.drag_page_up("TimerPage")
5849
59 # Delete the preset50 # Delete the preset
60 first_preset = self.main_view.get_first_preset_list_item()51 first_preset = self.main_view.get_first_preset_list_item()
@@ -69,13 +60,11 @@
69 self.main_view.get_toolbar().click_button('addPresetButton')60 self.main_view.get_toolbar().click_button('addPresetButton')
7061
71 # Set Timer label as "test"62 # Set Timer label as "test"
72 self.main_view.drag_page_up("TimerPage", self)63 self.main_view.drag_page_up("TimerPage")
73 label = self.select_name_preset_label()64 label = self.main_view.get_timer_name_preset()
74 self.assertThat(label.focus, Eventually(Equals(True)))65 label.write("AutopilotTimer")
75 self.keyboard.type("test")66 self.assertThat(label.text, Eventually(Equals("AutopilotTimer")))
76 self.assertThat(label.text, Eventually(Equals("test")))67 self.main_view.drag_page_down("TimerPage")
77
78 self.main_view.drag_page_down("TimerPage", self)
7968
80 if setTime:69 if setTime:
81 # Set timer minute70 # Set timer minute
@@ -124,14 +113,14 @@
124 # Create a new preset113 # Create a new preset
125 self.add_preset()114 self.add_preset()
126115
127 self.main_view.drag_page_up("TimerPage", self)116 self.main_view.drag_page_up("TimerPage")
128117
129 # Click to select the preset118 # Click to select the preset
130 # FIXME: Instead of always running the first preset, run the preset which was created119 # FIXME: Instead of always running the first preset, run the preset which was created
131 first_preset = self.main_view.get_first_preset_list_item()120 first_preset = self.main_view.get_first_preset_list_item()
132 self.pointing_device.click_object(first_preset)121 self.pointing_device.click_object(first_preset)
133122
134 self.main_view.drag_page_down("TimerPage", self)123 self.main_view.drag_page_down("TimerPage")
135124
136 # Click to start the preset125 # Click to start the preset
137 label = self.main_view.get_label_timer()126 label = self.main_view.get_label_timer()

Subscribers

People subscribed via source and target branches