def default_scenario_login(): """ admin is a superuser staff is a member of staff web is a standard user with no extra permissions """ super_user = make_superuser('admin') super_user.email = '*****@*****.**' super_user.save() make_user(STAFF, email='*****@*****.**', is_staff=True) make_user('web', email='*****@*****.**', first_name='William', last_name='Webber')
def default_scenario_login(): """ admin is a superuser staff is a member of staff web is a standard user with no extra permissions """ super_user = make_superuser('admin') super_user.email = '*****@*****.**' super_user.save() make_user( STAFF, email='*****@*****.**', first_name='Stan', last_name='Stafford', is_staff=True ) make_user( 'web', email='*****@*****.**', first_name='William', last_name='Webber' ) NotifyFactory()
def user_contractor(): """ fred is a farmer mike is a merchant sara is a smallholder """ make_user('fred', email='*****@*****.**') make_user('mike', email='*****@*****.**') make_user('sara', email='*****@*****.**')
def test_logout(self): user_pk = make_user('patrick').pk # check the user is not logged in self.assertNotIn(SESSION_KEY, self.client.session) # login the user self.client.login(username='******', password=TEST_PASSWORD) # check the user was logged in self.assertIn(SESSION_KEY, self.client.session) self.assertEquals(user_pk, int(self.client.session[SESSION_KEY])) # logout the user url = reverse('logout') response = self.client.post(url) # check the user was redirected to 'settings.LOGIN_REDIRECT_URL' self.assertRedirects(response, reverse('project.home')) # check the user was logged out self.assertNotIn(SESSION_KEY, self.client.session)
def test_login(self): user_pk = make_user('patrick').pk # check the user is not logged in self.assertNotIn(SESSION_KEY, self.client.session) # login the user data = { 'username': '******', 'password': TEST_PASSWORD, } url = reverse('login') response = self.client.post(url, data) # check the user was redirected self.assertEqual(302, response.status_code) # check the user was logged in self.assertIn(SESSION_KEY, self.client.session) self.assertEquals(user_pk, int(self.client.session[SESSION_KEY]))
def test_logout(self): user_pk = make_user('patrick').pk # check the user is not logged in self.assertNotIn(SESSION_KEY, self.client.session) # login the user self.client.login(username='******', password=TEST_PASSWORD) # check the user was logged in self.assertIn(SESSION_KEY, self.client.session) self.assertEquals(user_pk, self.client.session[SESSION_KEY]) # logout the user url = reverse('logout') response = self.client.post(url) # check the user was redirected to 'settings.LOGIN_REDIRECT_URL' self.assertRedirects(response, reverse('project.home')) # check the user was logged out self.assertNotIn(SESSION_KEY, self.client.session)
def test_login(self): user_pk = make_user('patrick').pk # check the user is not logged in self.assertNotIn(SESSION_KEY, self.client.session) # login the user data = { 'username': '******', 'password': TEST_PASSWORD, } url = reverse('login') response = self.client.post(url, data) # check the user was redirected self.assertEqual(302, response.status_code) # check the user was logged in self.assertIn(SESSION_KEY, self.client.session) self.assertEquals(user_pk, self.client.session[SESSION_KEY])
def test_login_next(self): """ Check that login with a 'next' parameter is working correctly """ user_pk = make_user('patrick').pk # check the user is not logged in self.assertNotIn(SESSION_KEY, self.client.session) # login the user data = { 'username': '******', 'password': TEST_PASSWORD, } url = '%s?next=/test/' % reverse('login') response = self.client.post(url, data) # check the user was redirected to the test page self.assertRedirects(response, reverse('example.test')) # check the user was logged in self.assertIn(SESSION_KEY, self.client.session) self.assertEquals(user_pk, int(self.client.session[SESSION_KEY]))
def test_login_next(self): """ Check that login with a 'next' parameter is working correctly """ user_pk = make_user('patrick').pk # check the user is not logged in self.assertNotIn(SESSION_KEY, self.client.session) # login the user data = { 'username': '******', 'password': TEST_PASSWORD, } url = '%s?next=/web/about/' % reverse('login') response = self.client.post(url, data) # check the user was redirected to the test page self.assertRedirects(response, reverse('web.about')) # check the user was logged in self.assertIn(SESSION_KEY, self.client.session) self.assertEquals(user_pk, self.client.session[SESSION_KEY])
def setUp(self): self.user = make_user("ed") make_user("sam", is_staff=True)