1
# Copyright (C) 2005-2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
This is a basic test to verify that mago-ng is working as expected and can
20
be run with various testing framework
23
$ mago-ng <path_to_this_file>
25
You can code ldtp directly in there or an external module
26
The only mandatory element is 'launcher' (and window_name for now)
28
set setupOnce to False to launch/close the app for each test
30
The purpose of this example is to test the management of the authentication
34
from mago import TestCase
38
class TestAuthenticate(TestCase):
39
"""Test the authentication dialog
41
launcher = 'time-admin'
42
window_name = 'dlgTimeandDateSettings'
45
"""setUp method. Click on btn2 to popup the auth dialog """
46
super(TestAuthenticate, self).setUp()
47
ldtp.click(self.window_name, 'btn2')
49
def test_password(self):
50
"""Test authentication with a valid password
52
This test enters a valid password and check the authenticate returned
53
True, that the dialog is not there anymore and that the calendar is
54
enabled (meaning that the authentication succeeded)
56
if not self.testConfig.has_option('auth', 'password'):
57
raise self.failureException,"Password is mandatory. Set it in the configuration file"
59
password = self.testConfig.get('auth', 'password')
60
rc = self.application.authenticate(password)
62
self.assertFalse(ldtp.guiexist('dlgAuthenticate'))
63
self.assertTrue(ldtp.stateenabled(self.window_name, 'calDate'))
65
def test_cancel(self):
66
"""Test the Cancel action of the authentication dialog
68
Open the authentication dialog and cancel, then check the return status
69
and that the dialog is closed
71
rc = self.application.authenticate(cancel = True)
74
self.assertFalse(ldtp.guiexist('dlgAuthenticate'))
77
def test_wrongpassword(self):
78
"""Test authentication with a wrong password
80
The test enters a wrong password and check that authenticate returns
81
False, that the dialog is still there.
83
Then call authenticate again with cancel and check that the return
84
status is True and the dialog vanished
86
# Set an invalid password
87
rc = self.application.authenticate(password = "this password is invalid")
89
self.assertTrue(ldtp.guiexist('dlgAuthenticate'))
91
# Cancel the auth. dialog
92
rc = self.application.authenticate(cancel = True)
94
self.assertFalse(ldtp.guiexist('dlgAuthenticate'))
97
if __name__ == "__main__":