def testViewLoadsWithLogin(self): """ Account Settings - View loads with login. Verify that the view loads when logged in and that all the provided information is present and correct. """ # Log in self.client.login(username = self.user.username, password = Factory.default_password) # Make the GET request response = self.client.get('/account-settings', follow = True) # Verify the correct template was used self.assertTemplateUsed(response, 'user/settings.html') # Verify both the epxected forms were passed to the template self.assertTrue('user_form' in response.context) self.assertTrue('info_form' in response.context) # Expected form values settings_form = Factory.create_user_settings_post_dict(self.user, self.info) # Validate field values in user_form user_form = response.context['user_form'] self.validate_form(user_form, settings_form, ()) # Validate field values in info_form info_form = response.context['info_form'] self.validate_form(info_form, settings_form, ())
def testUsernameNotUnique(self): """ Account Settings - Username not unique. Verify that attempting to change to a username already in use rerenders the page with a form error. """ # Create a second user user2, user2_info = Factory.create_user() # Log in as the first user self.client.login(username = self.user, password = Factory.default_password) # Get the post info and change username settings_form = Factory.create_user_settings_post_dict(self.user, self.info) settings_form['username'] = user2.username # Make the POST request response = self.client.post('/account-settings', settings_form, follow = True) # Verify the correct template was used self.assertTemplateUsed(response, 'user/settings.html') # Verify both the epxected forms were passed to the template self.assertTrue('user_form' in response.context) self.assertTrue('info_form' in response.context) # Validate field values in user_form user_form = response.context['user_form'] self.validate_form(user_form, settings_form, ('username')) # Validate field values in info_form info_form = response.context['info_form'] self.validate_form(info_form, settings_form, ()) self.assertTrue('organization' in response.context) self.assertEqual(response.context['organization'].name, self.organization.name) self.assertTrue('session' in response.context) self.assertEqual(response.context['session'].name, self.session.name)
def testGenderNotValid(self): """ Account Settings - Gender not valid. Verify that submitting a POST request with an invalid gender choice rerenders the page with a form error. """ # Log in self.client.login(username = self.user.username, password = Factory.default_password) # Get the post dict and change gender choice settings_form = Factory.create_user_settings_post_dict(self.user, self.info) settings_form['gender'] = 'i' # Make the POST request response = self.client.post('/account-settings', settings_form, follow = True) # Verify the correct template was used self.assertTemplateUsed(response, 'user/settings.html') # Verify both the epxected forms were passed to the template self.assertTrue('user_form' in response.context) self.assertTrue('info_form' in response.context) # Validate field values in user_form user_form = response.context['user_form'] self.validate_form(user_form, settings_form, ()) # Validate field values in info_form info_form = response.context['info_form'] self.validate_form(info_form, settings_form, ('gender')) self.assertTrue('organization' in response.context) self.assertEqual(response.context['organization'].name, self.organization.name) self.assertTrue('session' in response.context) self.assertEqual(response.context['session'].name, self.session.name)
def testGradDateNotValid(self): """ Account Settings - graduation_date not valid. Verify that submitting an invalid graduation_date kicks back an error """ # Log in self.client.login(username = self.user.username, password = Factory.default_password) # Create the post dict and set graduation_date settings_form = Factory.create_user_settings_post_dict(self.user, self.info) settings_form['graduation_date'] = -1 # Make the POST request response = self.client.post('/account-settings', settings_form, follow = True) # Verify the correct template was used self.assertTemplateUsed(response, 'user/settings.html') # Verify both the epxected forms were passed to the template self.assertTrue('user_form' in response.context) self.assertTrue('info_form' in response.context) # Validate field values in user_form user_form = response.context['user_form'] self.validate_form(user_form, settings_form, ()) # Validate field values in info_form info_form = response.context['info_form'] self.validate_form(info_form, settings_form, ('graduation_date')) self.assertTrue('organization' in response.context) self.assertEqual(response.context['organization'].name, self.organization.name) self.assertTrue('session' in response.context) self.assertEqual(response.context['session'].name, self.session.name)