~robbyoconnor/sahana-eden/trunk

« back to all changes in this revision

Viewing changes to static/selenium/scripts/tutorialTest.py

  • Committer: Robert O'Connor
  • Date: 2011-04-22 07:40:01 UTC
  • mfrom: (1617.1.476 eden)
  • Revision ID: robby.oconnor@gmail.com-20110422074001-132b6j8xxobdw2i9
merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
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.
 
5
 
 
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
 
11
"""
 
12
from sahanaTest import SahanaTest
 
13
 
 
14
class TutorialTest(SahanaTest):
 
15
    """ 
 
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.
 
19
    
 
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 
 
22
    """
 
23
    _sortList = ("simpleAuthentication",
 
24
                 "simpleSearch",
 
25
                 "checkMessages",
 
26
                )
 
27
    
 
28
    """
 
29
    This method demonstrates how to log into the Eden system using the 
 
30
    action methods provided. 
 
31
    """
 
32
    def simpleAuthentication(self):
 
33
        """
 
34
        Two basic accounts have been provided by the SahanaTest class
 
35
        These are admin@example.com and user@example.com
 
36
        
 
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 
 
39
        """
 
40
        self.useSahanaAdminAccount()
 
41
        self.action.login(self._user, self._password )
 
42
 
 
43
        self.useSahanaUserAccount()
 
44
        self.action.login(self._user, self._password )
 
45
        
 
46
        self.action.logout()
 
47
 
 
48
    """ This method demonstrates how to do a simple search """
 
49
    def simpleSearch(self):
 
50
        """
 
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.  
 
56
        """
 
57
        self.selenium.open("pr/person")
 
58
        result =  self.action.searchMatchesFound()
 
59
        """
 
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
 
64
        """ 
 
65
        self.action.search("User", "Showing 1 to 2 of 2 entries")
 
66
        
 
67
        """ A search that will return just one match is done as follows """ 
 
68
        self.action.searchUnique("Admin")
 
69
        
 
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())
 
75
        
 
76
    """ The next method shows how to check the response from different actions """
 
77
    def checkMessages(self):
 
78
        """ 
 
79
        Let's log in using the admin account then log out
 
80
        after each call check on the confirmation message displayed
 
81
        """
 
82
        self.useSahanaAdminAccount()
 
83
        self.action.login(self._user, self._password )
 
84
        self.action.successMsg("Logged in")
 
85
        self.action.logout()
 
86
        self.action.successMsg("Logged out")
 
87
        
 
88
        """ Now let's log in manually using the admin account
 
89
        but with an invalid password and check on the error message displayed
 
90
        """
 
91
        sel = self.selenium
 
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")
 
99
 
 
100
         
 
101
"""
 
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
 
105
"""