2
import unittest, time, re
6
class CreateTestAccount(unittest.TestCase):
10
self.selenium = testSuite.SahanaTestSuite.selenium
11
self.user = testSuite.SahanaTestSuite.user;
12
self.password = testSuite.SahanaTestSuite.password;
13
self.action = actions.Action()
15
def test_create_test_accounts(self):
18
# *** NOTE this script needs to be run by a user with Administrator privileges. END NOTE ***
19
self.action.login(self, self.user, self.password, False)
20
# This script creates a test account with the user name of admin@example.com the account is given administrator rights and can be used throughout the testing suite.
21
# The user admin@example.com will be deleted by the "Delete Test Account" test case.
22
sel.open("/eden/admin/user")
23
self.failUnless(sel.is_element_present("show-add-btn"))
24
sel.click("show-add-btn")
25
sel.type("auth_user_first_name", "Admin")
26
sel.type("auth_user_last_name", "User")
27
sel.select("auth_user_language", "label=English")
28
sel.type("auth_user_email", "admin@example.com")
29
sel.type("auth_user_password", "testing")
30
sel.click("//input[@value='Save']")
31
sel.wait_for_page_to_load("30000")
32
# Now that the user has been created search for this user using the list filter so that the "Administrator" role can be added to it.
33
# The search filter is part of the http://datatables.net/ JavaScript getting it to work with Selenium needs a bit of care.
34
# Entering text in the filter textbox doesn't always trigger off the filtering and it is not possible with this method to clear the filter.
35
# The solution is to put in a call to the DataTables API, namely the fnFilter function
36
# However, the first time that the fnFilter() is called in the testing suite it doesn't complete the processing, hence it is called twice.
37
sel.run_script("oTable = $('#list').dataTable(); oTable.fnFilter( '' );")
38
sel.run_script("oTable = $('#list').dataTable(); oTable.fnFilter( 'admin@example.com' );")
41
if re.search(r"^[\s\S]*1 entries[\s\S]*$", sel.get_text("//div[@class='dataTables_info']")): break
44
else: self.fail("time out")
45
sel.click("link=Open")
46
sel.wait_for_page_to_load("30000")
47
sel.click("//div[@id='content']/a[2]")
48
sel.wait_for_page_to_load("30000")
49
sel.click("auth_membership_group_id")
50
sel.select("auth_membership_group_id", "label=1: Administrator")
51
sel.click("//input[@value='Add']")
52
sel.wait_for_page_to_load("30000")
54
# This script creates a test account with the user name of user@example.com which is not given administrator rights and should be used throughout the testing suite.
55
# The user user@example.com will be deleted by the "Delete Test Account" test case.
56
sel.open("/eden/admin/user")
57
self.failUnless(sel.is_element_present("show-add-btn"))
58
sel.click("show-add-btn")
59
sel.type("auth_user_first_name", "Normal")
60
sel.type("auth_user_last_name", "User")
61
sel.select("auth_user_language", "label=English")
62
sel.type("auth_user_email", "user@example.com")
63
sel.type("auth_user_password", "testing")
64
sel.click("//input[@value='Save']")
65
sel.wait_for_page_to_load("30000")
67
# Log out from the current "Administrator" user and log back in for the remaining test cases as admin@example.com
68
#sel.click("link=Logout")
69
#sel.wait_for_page_to_load("30000")
70
#self.action.login(self, "admin@example.com", "testing" )
71
#sel.click("link=Logout")
72
#sel.wait_for_page_to_load("30000")
76
if __name__ == "__main__":