/usr/lib/python3/dist-packages/notes_app/tests/test_quit.py is in notes-app-autopilot 1.4+14.10.20140711-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright 2013 Canonical
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
"""Tests for Notes app"""
from __future__ import absolute_import
from autopilot.platform import model
from notes_app.tests import NotesAppTestCase
import sqlite3
import json
import unittest
class UtilsMixin(object):
def focus_note_for_editing(self, index):
notes = self.main_window.get_notes()
note = notes[index]
self.pointing_device.click_object(note)
# wait for note to expand
note.height.wait_for(note.actualExpandedHeight)
# click outside of the text area
note_x, note_y, note_w, note_h = note.globalRect
self.pointing_device.move(note_x + note_w / 2, note_y + note_h - 1)
self.pointing_device.click()
return note
def assert_app_has_quit(self):
self.app.process.poll()
self.assertIsNotNone(self.app.process.returncode)
class TestQuit(NotesAppTestCase, UtilsMixin):
"""Tests save on quit"""
""" This is needed to wait for the application to start.
In the testfarm, the application may take some time to show up."""
def setUp(self):
# Setup the database before starting the app
self.setup_db()
super(TestQuit, self).setUp()
def setup_db(self):
note_data = """{ "elements" : [
{"content":"foobar","type":"text"}
]}"""
path = self.ensure_db()
conn = sqlite3.connect(path)
cursor = conn.cursor()
cursor.execute("DELETE FROM notes")
cursor.execute("INSERT INTO notes (date, note) "
"VALUES ('2013-04-07', '" + note_data + "')")
conn.commit()
conn.close()
@unittest.skipUnless(model() == "Desktop",
"Alt+F4 to close apps only works on desktop")
def test_save_before_quit(self):
# Verify that after typing something in the note and quitting will save
# the note to db
self.focus_note_for_editing(0)
self.keyboard.type("xxx", delay=self.TYPING_DELAY)
self.keyboard.press_and_release("Alt+F4")
self.assert_app_has_quit()
path = self.ensure_db()
conn = sqlite3.connect(path)
cursor = conn.cursor()
cursor.execute("SELECT note FROM NOTES")
result = cursor.fetchone()
self.assertEquals(len(result), 1)
data = json.loads(result[0])
self.assertEquals(len(data["elements"]), 1)
self.assertEquals(data["elements"][0]["content"], "foobarxxx")
class TestQuitNoNote(NotesAppTestCase, UtilsMixin):
"""Tests save on quit with no notes"""
""" This is needed to wait for the application to start.
In the testfarm, the application may take some time to show up."""
def setUp(self):
# Setup the database before starting the app
self.setup_db()
super(TestQuitNoNote, self).setUp()
def setup_db(self):
path = self.ensure_db()
conn = sqlite3.connect(path)
cursor = conn.cursor()
cursor.execute("DELETE FROM notes")
conn.commit()
conn.close()
@unittest.skipUnless(model() == "Desktop",
"Alt+F4 to close apps only works on desktop")
def test_save_before_quit(self):
# Verify that after typing something in the note and quitting will
# save the note to db
self.focus_note_for_editing(0)
self.keyboard.type("xxx", delay=self.TYPING_DELAY)
self.keyboard.press_and_release("Alt+F4")
self.assert_app_has_quit()
path = self.ensure_db()
conn = sqlite3.connect(path)
cursor = conn.cursor()
cursor.execute("SELECT note FROM NOTES")
result = cursor.fetchone()
self.assertEquals(len(result), 1)
data = json.loads(result[0])
self.assertEquals(len(data["elements"]), 1)
self.assertEquals(data["elements"][0]["content"], "xxx")
|