<commit_before>from django.contrib import auth
from rest_framework import status
from rest_framework.test import APITestCase
from foodsaving.users.factories import UserFactory


class TestUserAuthAPI(APITestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.user = UserFactory()
        cls.disabled_user = UserFactory(is_active=False)
        cls.url = '/api/auth/'

    def test_login(self):
        data = {'email': self.user.email, 'password': self.user.display_name}
        response = self.client.post(self.url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data['email'], self.user.email)
        user = auth.get_user(self.client)
        self.assertTrue(user.is_authenticated())

    def test_no_credentials(self):
        data = {}
        response = self.client.post(self.url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'email': ['This field is required.'],
                                         'password': ['<PASSWORD>.']})

    def test_wrong_credentials(self):
        data = {'email': self.user.email, 'password': '<PASSWORD>'}
        response = self.client.post(self.url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data['non_field_errors'], ['Unable to login with provided credentials.', ])

    def test_login_as_disabled_user_fails(self):
        data = {'email': self.disabled_user.email, 'password': self.disabled_user.display_name}
        response = self.client.post(self.url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        user = auth.get_user(self.client)
        self.assertFalse(user.is_authenticated())

    def test_status_not_logged_in(self):
        response = self.client.get('/api/auth/status/')
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
        self.assertEqual(response.data['error'], 'not_authed')<commit_msg>Add failing test<commit_after>from django.contrib import auth
from rest_framework import status
from rest_framework.test import APITestCase

from foodsaving.users.factories import UserFactory


class TestUserAuthAPI(APITestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.user = UserFactory()
        cls.disabled_user = UserFactory(is_active=False)
        cls.url = '/api/auth/'

    def test_login(self):
        data = {'email': self.user.email, 'password': self.user.display_name}
        response = self.client.post(self.url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data['email'], self.user.email)
        user = auth.get_user(self.client)
        self.assertTrue(user.is_authenticated())

    def test_no_credentials(self):
        data = {}
        response = self.client.post(self.url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'email': ['This field is required.'],
                                         'password': ['<PASSWORD>.']})

    def test_wrong_credentials(self):
        data = {'email': self.user.email, 'password': '<PASSWORD>'}
        response = self.client.post(self.url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data['non_field_errors'], ['Unable to login with provided credentials.', ])

    def test_login_as_disabled_user_fails(self):
        data = {'email': self.disabled_user.email, 'password': self.disabled_user.display_name}
        response = self.client.post(self.url, data, format='json')
        self.assertEqual(response.data['non_field_errors'], ['User account is disabled', ])
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        user = auth.get_user(self.client)
        self.assertFalse(user.is_authenticated())

    def test_status_not_logged_in(self):
        response = self.client.get('/api/auth/status/')
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
        self.assertEqual(response.data['error'], 'not_authed')
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.006843065693430657, 'mean_word_length': 3.465376782077393, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5612836', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1269, 'n_words': 220}