root/galaxy-central/test/functional/test_user_info.py

リビジョン 2, 11.8 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1from base.twilltestcase import *
2from base.test_db_util import *
3
4class TestUserInfo( TwillTestCase ):
5    def test_000_initiate_users( self ):
6        """Ensuring all required user accounts exist"""
7        self.logout()
8        self.login( email='test1@bx.psu.edu', username='regular-user1' )
9        global regular_user1
10        regular_user1 = get_user( 'test1@bx.psu.edu' )
11        assert regular_user1 is not None, 'Problem retrieving user with email "test1@bx.psu.edu" from the database'
12        global regular_user1_private_role
13        regular_user1_private_role = get_private_role( regular_user1 )
14        self.logout()
15        self.login( email='test2@bx.psu.edu', username='regular-user2' )
16        global regular_user2
17        regular_user2 = get_user( 'test2@bx.psu.edu' )
18        assert regular_user2 is not None, 'Problem retrieving user with email "test2@bx.psu.edu" from the database'
19        global regular_user2_private_role
20        regular_user2_private_role = get_private_role( regular_user2 )
21        self.logout()
22        self.login( email='test3@bx.psu.edu', username='regular-user3' )
23        global regular_user3
24        regular_user3 = get_user( 'test3@bx.psu.edu' )
25        assert regular_user3 is not None, 'Problem retrieving user with email "test3@bx.psu.edu" from the database'
26        global regular_user3_private_role
27        regular_user3_private_role = get_private_role( regular_user3 )
28        self.logout()
29        self.login( email='test@bx.psu.edu', username='admin-user' )
30        global admin_user
31        admin_user = get_user( 'test@bx.psu.edu' )
32        assert admin_user is not None, 'Problem retrieving user with email "test@bx.psu.edu" from the database'
33        global admin_user_private_role
34        admin_user_private_role = get_private_role( admin_user )
35    def test_005_create_user_info_forms( self ):
36        """Testing creating a new user info form and editing it"""
37        # Logged in as admin_user
38        # Create a the first form
39        name = "Student"
40        desc = "This is Student user info form's description"
41        form_type = get_user_info_form_definition()
42        self.create_form( name=name,
43                          desc=desc,
44                          form_type=form_type,
45                          num_fields=0,
46                          strings_displayed=[ 'Create a new form definition' ],
47                          strings_displayed_after_submit=[ name, desc, form_type ] )
48        tmp_form = get_form( name )
49        # Add fields to the form
50        field_dicts = [ dict( name='Affiliation',
51                              desc='The type of  organization you are affiliated with',
52                              type='SelectField',
53                              required='optional',
54                              selectlist=[ 'Educational', 'Research', 'Commercial' ] ),
55                        dict( name='Name of Organization',
56                              desc='',
57                              type='TextField',
58                              required='optional' ),
59                        dict( name='Contact for feedback',
60                              desc='',
61                              type='CheckboxField',
62                              required='optional' ) ]
63        self.edit_form( id=self.security.encode_id( tmp_form.current.id ),
64                        field_dicts=field_dicts,
65                        field_index=len( tmp_form.fields ),
66                        strings_displayed=[ 'Edit form definition "%s"' % name ],
67                        strings_displayed_after_submit=[ "The form '%s' has been updated with the changes." % name ] )
68        # Get the form_definition object for later tests
69        global form_one
70        form_one = get_form( name )
71        assert form_one is not None, 'Problem retrieving form named "%s" from the database' % name
72        assert len( form_one.fields ) == len( tmp_form.fields ) + len( field_dicts )
73        # Create the second form
74        name = "Researcher"
75        desc = "This is Researcher user info form's description"
76        self.create_form( name=name,
77                          desc=desc,
78                          form_type=form_type,
79                          num_fields=0,
80                          strings_displayed=[ 'Create a new form definition' ],
81                          strings_displayed_after_submit=[ name, desc, form_type ] )
82        tmp_form = get_form( name )
83        # Add fields to the form
84        field_dicts = [ dict( name='Affiliation',
85                              desc='The type of  organization you are affiliated with',
86                              type='SelectField',
87                              required='optional',
88                              selectlist=[ 'Educational', 'Research', 'Commercial' ] ),
89                        dict( name='Name of Organization',
90                              desc='',
91                              type='TextField',
92                              required='optional' ),
93                        dict( name='Contact for feedback',
94                              desc='',
95                              type='CheckboxField',
96                              required='optional' ) ]
97        self.edit_form( id=self.security.encode_id( tmp_form.current.id ),
98                        field_dicts=field_dicts,
99                        field_index=len( tmp_form.fields ),
100                        strings_displayed=[ 'Edit form definition "%s"' % name ],
101                        strings_displayed_after_submit=[ "The form '%s' has been updated with the changes." % name ] )
102        # Get the form_definition object for later tests
103        global form_two
104        form_two = get_form( name )
105        assert form_two is not None, 'Problem retrieving form named "%s" from the database' % name
106        assert len( form_two.fields ) == len( tmp_form.fields ) + len( field_dicts )
107    def test_010_user_reqistration_multiple_user_info_forms( self ):
108        """Testing user registration with multiple user info forms"""
109        # Logged in as admin_user
110        self.logout()
111        # Create a new user with 'Student' user info form.  The user_info_values will be the values
112        # filled into the fields defined in field_dicts above ( 'Educational' -> 'Affiliation,
113        # 'Penn State' -> 'Name of Organization', '1' -> 'Contact for feedback' )
114        email = 'test11@bx.psu.edu'
115        password = 'testuser'
116        username = 'test11'
117        user_info_values=[ 'Educational', 'Penn State', '1' ]
118        self.create_user_with_info( email=email,
119                                    password=password,
120                                    username=username,
121                                    user_info_select=str( form_one.id ),
122                                    user_info_values=user_info_values,
123                                    strings_displayed=[ "Create account", "User type" ] )
124        global regular_user11
125        regular_user11 = get_user( email )
126        assert regular_user11 is not None, 'Problem retrieving user with email "%s" from the database' % email
127        global regular_user11_private_role
128        regular_user11_private_role = get_private_role( regular_user11 )
129        self.logout()
130        self.login( email=regular_user11.email, username=username )
131        self.edit_user_info( strings_displayed=[ "Manage User Information",
132                                                 user_info_values[0],
133                                                 user_info_values[1],
134                                                 '<input type="checkbox" name="field_2" value="true" checked>' ] )
135    def test_015_user_reqistration_single_user_info_forms( self ):
136        """Testing user registration with a single user info form"""
137        # Logged in as regular_user_11
138        self.logout()
139        self.login( email=admin_user.email )
140        # Delete the 'Researcher' user info form
141        self.mark_form_deleted( self.security.encode_id( form_two.current.id ) )
142        # Create a new user with 'Student' user info form.  The user_info_values will be the values
143        # filled into the fields defined in field_dicts above ( 'Educational' -> 'Affiliation,
144        # 'Penn State' -> 'Name of Organization', '1' -> 'Contact for feedback' )
145        email = 'test12@bx.psu.edu'
146        password = 'testuser'
147        username = 'test12'
148        user_info_values=[ 'Educational', 'Penn State', '1' ]
149        self.create_user_with_info( email=email,
150                                    password=password,
151                                    username=username,
152                                    user_info_select=form_one.id,
153                                    user_info_values=user_info_values,
154                                    strings_displayed=[ "Create account" ] )
155        global regular_user12
156        regular_user12 = get_user( email )
157        assert regular_user12 is not None, 'Problem retrieving user with email "%s" from the database' % email
158        global regular_user12_private_role
159        regular_user12_private_role = get_private_role( regular_user12 )
160        self.logout()
161        self.login( email=regular_user12.email, username=username )
162        self.edit_user_info( strings_displayed=[ "Manage User Information",
163                                                 user_info_values[0],
164                                                 user_info_values[1],
165                                                 '<input type="checkbox" name="field_2" value="true" checked>' ] )
166    def test_020_edit_user_info( self ):
167        """Testing editing user info as a regular user"""
168        # Logged in as regular_user_12
169        # Test changing email and user name - first try an invalid user name
170        self.edit_user_info( new_email='test12_new@bx.psu.edu',
171                             new_username='test12_new',
172                             strings_displayed_after_submit=[ "Public names must be at least four characters" ] )
173        # Now try a valid user name
174        self.edit_user_info( new_email='test12_new@bx.psu.edu',
175                             new_username='test12-new',
176                             strings_displayed_after_submit=[ 'The login information has been updated with the changes' ] )
177        # Since we changed the user's account. make sure the user's private role was changed accordingly
178        if not get_private_role( regular_user12 ):
179            raise AssertionError, "The private role for %s was not correctly set when their account (email) was changed" % regular_user12.email
180        # Test changing password
181        self.edit_user_info( password='testuser',
182                             new_password='testuser#',\
183                             strings_displayed_after_submit=[ 'The password has been changed.' ] )
184        self.logout()
185        refresh( regular_user12 )
186        # Test logging in with new email and password
187        self.login( email=regular_user12.email, password='testuser#' )
188        # Test editing the user info
189        self.edit_user_info( info_values=[ 'Research', 'PSU' ],
190                             strings_displayed_after_submit=[ "The user information has been updated with the changes" ] )
191    def test_999_reset_data_for_later_test_runs( self ):
192        """Reseting data to enable later test runs to pass"""
193        # Logged in as regular_user_12
194        self.logout()
195        self.login( email=admin_user.email )
196        ##################
197        # Mark all forms deleted that have not yet been marked deleted ( form_two has )
198        ##################
199        for form in [ form_one ]:
200            self.mark_form_deleted( self.security.encode_id( form.current.id ) )
201        ###############
202        # Purge appropriate users
203        ###############
204        for user in [ regular_user11, regular_user12 ]:
205            self.mark_user_deleted( user_id=self.security.encode_id( user.id ), email=user.email )
206            refresh( user )
207            self.purge_user( self.security.encode_id( user.id ), user.email )
208            refresh( user )
209            delete_user_roles( user )
210            delete_obj( user )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。