2
This test class is designed as a tutorial to help you to learn how to
3
construct a test cases for Eden. Typically a test class is designed for a
4
model and thus should help with testing the work flow.
6
To get a new test class to appear in the UI it is necessary to edit the
7
data/testModules.txt file
8
All test classes should be extended from the class SahanaTest which in turn
9
is inherited from unittest.TestCase
10
So the following import is always required
12
from sahanaTest import SahanaTest
14
class TutorialTest(SahanaTest):
16
The _sortList variable is used to keep a list of all test methods
17
that will be run by the test class.
18
The test methods will be run in the order given in this list.
20
If this variable is not provided then only methods that have the prefix test_
21
will be run and the order is not guaranteed
23
_sortList = ("simpleAuthentication",
29
This method demonstrates how to log into the Eden system using the
30
action methods provided.
32
def simpleAuthentication(self):
34
Two basic accounts have been provided by the SahanaTest class
35
These are admin@example.com and user@example.com
37
You set the details for these account by using the convenience methods
38
and then passing the member variables to the action.login function
40
self.useSahanaAdminAccount()
41
self.action.login(self._user, self._password )
43
self.useSahanaUserAccount()
44
self.action.login(self._user, self._password )
48
""" This method demonstrates how to do a simple search """
49
def simpleSearch(self):
51
First open a page with a search widget.
52
The search widget that is used is the list_filter
53
which is used to filter a list from a database.
54
Using the action.searchMatchesFound() method it is possible to
55
record the number of records ther are.
57
self.selenium.open("pr/person")
58
result = self.action.searchMatchesFound()
60
A search is done using the action.search() method
61
the search checks on the message returned,
62
expecting a message as specific as the following can be problematic
63
because it is hard to guarantee that there will not be more matches
65
self.action.search("User", "Showing 1 to 2 of 2 entries")
67
""" A search that will return just one match is done as follows """
68
self.action.searchUnique("Admin")
70
""" Finally let's clear the search criteria """
71
self.action.clearSearch()
72
""" Now having cleared the search box let's check that
73
the number of results are the same as what we started with """
74
self.assertEqual(result, self.action.searchMatchesFound())
76
""" The next method shows how to check the response from different actions """
77
def checkMessages(self):
79
Let's log in using the admin account then log out
80
after each call check on the confirmation message displayed
82
self.useSahanaAdminAccount()
83
self.action.login(self._user, self._password )
84
self.action.successMsg("Logged in")
86
self.action.successMsg("Logged out")
88
""" Now let's log in manually using the admin account
89
but with an invalid password and check on the error message displayed
92
sel.open("default/user/login")
93
sel.click("auth_user_email")
94
sel.type("auth_user_email", self._user)
95
sel.type("auth_user_password", "WrongPassword")
96
sel.click("//input[@value='Login']")
97
# The above manual codes are only needed to avoid the error checking done by action.login()
98
self.action.errorMsg("Invalid login")
102
Now that the test class has been completed it is necessary to edit the
103
data/testModules.txt file. Add the following line
104
Tutorial, tutorialTest.TutorialTest