Пример #1
0
 def test_login_signal(self, mock_user_logged_in):
     client = Client()
     User.objects.create_user('bouke', '', 'secret')
     assert client.login(username='******', password='******')
     assert mock_user_logged_in.called
     request = mock_user_logged_in.call_args[1]['request']
     assert getattr(request, 'user', None) is not None
Пример #2
0
 def test_restore_session(self):
     store = SessionStore('Python/2.7', '127.0.0.1', None)
     store['foo'] = 'bar'
     store.save()
     client = Client()
     client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
     User.objects.create_user('bouke', '', 'secret')
     assert client.login(username='******', password='******')
     self.assertEqual(client.session['foo'], 'bar')
Пример #3
0
    def login(self, username, password):
        c = Client()
        loginurl = reverse('login')
        c.post(loginurl, {
            'auth-username': username,
            'auth-password': password,
            'rattic_tfa_login_view-current_step': 'auth',
        })

        return c
Пример #4
0
    def test_login_logout(self):
        client = Client()
        User.objects.create_user('bouke', '', 'secret')
        assert client.login(username='******', password='******')
        assert settings.SESSION_COOKIE_NAME in client.cookies

        client.logout()
        assert settings.SESSION_COOKIE_NAME not in client.cookies

        # should not raise
        client.logout()
Пример #5
0
 def test_no_session(self):
     self.assertIsNone(Client().session)
Пример #6
0
 def test_invalid_login(self):
     client = Client()
     self.assertFalse(client.login())
 def test_homepage_to_login_redirect(self):
     client = Client()
     response = client.get(reverse('home'), follow=True)
     self.assertEqual(response.status_code, 200)
     self.assertTemplateUsed(response, 'home.html')
 def test_admin_disabled(self):
     client = Client()
     response = client.get('/admin/')
     self.assertEqual(response.status_code, 404)
Пример #9
0
 def setUp(self):
     self.client = Client()
     self.existing_username = "******"
     create_example_user()
     create_example_user(self.existing_username, "*****@*****.**", "password")
     login(self)
Пример #10
0
 def test_404_page(self):
     client = Client()
     response = client.get(reverse('home') + 'thisurldoesnotexist')
     self.assertEqual(response.status_code, 404)
     self.assertTemplateUsed(response, '404.html')
     self.assertTrue('rattic_icon' in response.context.keys())