<commit_before>from django.test import TestCase

# Create your tests here.<commit_msg>added login func test<commit_after>from django.test import TestCase, TransactionTestCase
from . import views
from django.test import Client
from freezegun import freeze_time
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import resolve


class LoginViewTest(TestCase):
    """
    Test for authentication
    """

    def setUp(self):
        User.objects.create_user('hiren', '<EMAIL>', 'password')
        self.c = Client()

    def test_login_url_resolves_to_login_view(self):
        found = resolve('/')
        self.assertEqual(found.func, views.login)

    def test_auth(self):
        respond = self.c.post('/', {'username': 'hiren', 'password': 'password'})
        self.assertRedirects(respond, '/accounting/')

    def test_redirect_for_unauthenticated_user_works(self):
        response = self.c.get('/accounting/')
        self.assertRedirects(response, '/?next=/accounting/')

    def test_redirect_works_for_bad_auth(self):
        respond = self.c.post('/', {'username': 'hiren', 'password': '<PASSWORD>'})
        self.assertRedirects(respond, '/')

    def test_view_returns_correct_template(self):
        response = self.c.get('/')
        self.assertTemplateUsed(response, 'login.html')

    def test_authenticated_user_redirect_to_the_app(self):
        self.c.login(username='hiren', password='password')
        response = self.c.get('/', follow=True)
        self.assertRedirects(response, '/accounting/')
{'fraction_non_alphanumeric': 0.12979539641943735, 'fraction_numerical': 0.0, 'mean_word_length': 3.785932721712538, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1143974', 'n_tokens_mistral': 463, 'n_tokens_neox': 453, 'n_words': 96}