<commit_before>"""accounts app unittests for forms

"""
from django.test import TestCase

from accounts.forms import LoginForm


class LoginFormTest(TestCase):
    """Tests the form which validates the email used for login.

    """
    def test_valid_email_accepted(self):
        form = LoginForm({'email': '<EMAIL>'})
        self.assertTrue(form.is_valid())

    def test_invalid_email_declined(self):
        form = LoginForm({'email': 'invalidemail'})
        self.assertFalse(form.is_valid())<commit_msg>Add more loginform tests<commit_after>"""accounts app unittests for forms

"""
import re

from django.test import TestCase, RequestFactory
from django.core import mail

from accounts.forms import LoginForm


class LoginFormTest(TestCase):
    """Tests the form which validates the email used for login.

    """
    def setUp(self):
        self.test_email = '<EMAIL>'
        self.request = RequestFactory().get('/')

    def test_valid_email_accepted(self):
        form = LoginForm({'email': self.test_email})
        self.assertTrue(form.is_valid())

    def test_invalid_email_declined(self):
        form = LoginForm({'email': 'invalidemail'})
        self.assertFalse(form.is_valid())

    def test_can_send_email(self):
        form = LoginForm({'email': self.test_email})
        if form.is_valid():
            form.save(self.request)
        self.assertEqual(len(mail.outbox), 1)

    def test_email_contains_link(self):
        form = LoginForm({'email': self.test_email})
        if form.is_valid():
            form.save(self.request)
        email = mail.outbox[0]
        url_search = re.search(r'http://.+/.+$', email.body)
        self.assertIsNotNone(url_search)
{'fraction_non_alphanumeric': 0.12470449172576832, 'fraction_numerical': 0.001182033096926714, 'mean_word_length': 3.296954314720812, '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': '4597852', 'n_tokens_mistral': 515, 'n_tokens_neox': 508, 'n_words': 113}