Beispiel #1
0
    def test_logout_stores_correct_fields_in_database(self):
        user = User(username='******')
        self.request.META['HTTP_USER_AGENT'] = 'Mozilla'

        handle_logout('any_source', self.request, user)

        log_entry = UserAccessLog.objects.filter(user_id='test_user').first()
        self.assertEqual(log_entry.action, 'logout')
        self.assertEqual(log_entry.user_id, 'test_user')
        self.assertEqual(log_entry.ip, '127.0.0.1')
        self.assertEqual(log_entry.user_agent, 'Mozilla')
        self.assertEqual(log_entry.path, '/logout')
        self.assertEqual(str(log_entry.timestamp), '2020-01-02 03:20:15')
Beispiel #2
0
    def test_no_user_is_logged_with_empty_user_id(self):
        handle_logout('any_source', self.request, user=None)

        unknown_logouts = UserAccessLog.objects.filter(user_id='')
        self.assertEqual(unknown_logouts.count(), 1)