<commit_before>from django.test import TestCase
from django.core.urlresolvers import reverse


from registration.models import RegistrationProfile


class RegistrationTestCase(TestCase):

    valid_user_data = {'username': 'somename',
                       'email': '<EMAIL>',
                       'password1': '<PASSWORD>',
                       'password2': '<PASSWORD>'}

    def test_get_displays_empty_form(self):
        # TODO: fix typo in url name in urls.py
        registration_url = reverse('registation')

        response = self.client.get(registration_url)
        assert response.status_code == 200

        form = response.context['form']
        assert form is not None

        initial_data = form.initial
        assert len(initial_data) == 0

    def test_submit_empty_form(self):
        # TODO: fix typo in url name in urls.py
        registration_url = reverse('registation')

        # shall not raise an exception
        response = self.client.post(registration_url, {})

        assert RegistrationProfile.objects.count() == 0

        form = response.context['form']
        assert form is not None, 'We expect the form to be displayed again if the submission failed'

        self.assertFormError(
            response,
            'form',
            'email',
            'Dieses Feld ist zwingend erforderlich.')

    def test_submit_valid_form(self):
        # TODO: fix typo in url name in urls.py
        registration_url = reverse('registation')

        response = self.client.post(registration_url,
                                    self.valid_user_data,
                                    follow=True)

        registration_complete_url = reverse('registration_complete')

        self.assertRedirects(response, registration_complete_url)
        self.assertContains(
            response, 'Eine Aktivierungsmail wurde Dir soeben zugesendet.')

        new_user = RegistrationProfile.objects.first()
        assert new_user is not None
        assert new_user.user.username == "somename"

    def test_username_exists_already(self):
        # TODO: fix typo in url name in urls.py
        registration_url = reverse('registation')

        # register first user
        self.client.post(registration_url, self.valid_user_data)

        # try to register user again (=same username)
        response = self.client.post(registration_url,
                                    self.valid_user_data)

        assert RegistrationProfile.objects.count() == 1

        form = response.context['form']
        assert form is not None, 'We expect the form to be displayed again if the submission failed'

        self.assertFormError(
            response,
            'form',
            'username',
            'Dieser Benutzername ist bereits vergeben.')<commit_msg>introduced test to check for non-matching passwords<commit_after>from django.test import TestCase
from django.core.urlresolvers import reverse


from registration.models import RegistrationProfile


class RegistrationTestCase(TestCase):

    valid_user_data = {'username': 'somename',
                       'email': '<EMAIL>',
                       'password1': '<PASSWORD>',
                       'password2': '<PASSWORD>'}

    def test_get_displays_empty_form(self):
        # TODO: fix typo in url name in urls.py
        registration_url = reverse('registation')

        response = self.client.get(registration_url)
        assert response.status_code == 200

        form = response.context['form']
        assert form is not None

        initial_data = form.initial
        assert len(initial_data) == 0

    def test_submit_empty_form(self):
        # TODO: fix typo in url name in urls.py
        registration_url = reverse('registation')

        # shall not raise an exception
        response = self.client.post(registration_url, {})

        assert RegistrationProfile.objects.count() == 0

        form = response.context['form']
        assert form is not None, 'We expect the form to be displayed again if the submission failed'

        self.assertFormError(
            response,
            'form',
            'email',
            'Dieses Feld ist zwingend erforderlich.')

    def test_submit_valid_form(self):
        # TODO: fix typo in url name in urls.py
        registration_url = reverse('registation')

        response = self.client.post(registration_url,
                                    self.valid_user_data,
                                    follow=True)

        registration_complete_url = reverse('registration_complete')

        self.assertRedirects(response, registration_complete_url)
        self.assertContains(
            response, 'Eine Aktivierungsmail wurde Dir soeben zugesendet.')

        new_user = RegistrationProfile.objects.first()
        assert new_user is not None
        assert new_user.user.username == "somename"

    def test_username_exists_already(self):
        # TODO: fix typo in url name in urls.py
        registration_url = reverse('registation')

        # register first user
        self.client.post(registration_url, self.valid_user_data)

        # try to register user again (=same username)
        response = self.client.post(registration_url,
                                    self.valid_user_data)

        assert RegistrationProfile.objects.count() == 1

        form = response.context['form']
        assert form is not None, 'We expect the form to be displayed again if the submission failed'

        self.assertFormError(
            response,
            'form',
            'username',
            'Dieser Benutzername ist bereits vergeben.')

    def test_passwords_dont_match(self):
        # TODO: fix typo in url name in urls.py
        registration_url = reverse('registation')

        user_data = {'username': 'somename',
                     'email': '<EMAIL>',
                     'password1': '<PASSWORD>',
                     'password2': '<PASSWORD>'}

        response = self.client.post(registration_url, user_data)

        assert RegistrationProfile.objects.count() == 0

        form = response.context['form']
        assert form is not None, 'We expect the form to be displayed again if the submission failed'

        self.assertFormError(
            response,
            'form',
            None,
            'Die zwei Passwoerter sind nicht gleich!')
{'fraction_non_alphanumeric': 0.08247099404201944, 'fraction_numerical': 0.0029789902790843524, 'mean_word_length': 2.1673286991062564, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3092196', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1604, 'n_words': 457}