<commit_before>from ddt import data, ddt
from rest_framework import test, status

from waldur_core.structure.tests import factories, fixtures


@ddt
class DivisionListTest(test.APITransactionTestCase):
    def setUp(self):
        self.fixture = fixtures.UserFixture()
        self.division_1 = factories.DivisionFactory()
        self.division_2 = factories.DivisionFactory()
        self.url = factories.DivisionFactory.get_list_url()

    @data('staff', 'user')
    def test_authorized_user_can_list_divisions(self, user):
        self.client.force_authenticate(user=getattr(self.fixture, user))
        response = self.client.get(self.url)
        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual(len(response.data), 2)

    def test_anonymous_user_cannot_list_divisions(self):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

    def test_list_filters(self):
        """Test of divisions' list filter by name, type and parent UUID."""
        division_parent = factories.DivisionFactory()
        self.division_1.parent = division_parent
        self.division_1.save()
        rows = [
            {'name': 'name', 'valid': self.division_1.name[2:], 'invalid': 'AAA'},
            {'name': 'name_exact', 'valid': self.division_1.name, 'invalid': self.division_1.name[2:]},
            {'name': 'type', 'valid': self.division_1.type.name, 'invalid': self.division_1.type.name[2:]},
            {'name': 'parent', 'valid': division_parent.uuid.hex, 'invalid': division_parent.uuid.hex[2:]},
        ]
        self.client.force_authenticate(user=self.fixture.staff)

        for row in rows:
            response = self.client.get(self.url, data={row['name']: row['valid']})
            self.assertEqual(status.HTTP_200_OK, response.status_code)
            self.assertEqual(len(response.data), 1)

            response = self.client.get(self.url, data={row['name']: row['invalid']})
            if row['name'] == 'parent':
                self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
            else:
                self.assertEqual(status.HTTP_200_OK, response.status_code)
            self.assertEqual(len(response.data), 0)
<commit_msg>Fix leftover.<commit_after>from ddt import data, ddt
from rest_framework import test, status

from waldur_core.structure.tests import factories, fixtures


@ddt
class DivisionListTest(test.APITransactionTestCase):
    def setUp(self):
        self.fixture = fixtures.UserFixture()
        self.division_1 = factories.DivisionFactory()
        self.division_2 = factories.DivisionFactory()
        self.url = factories.DivisionFactory.get_list_url()

    @data('staff', 'user')
    def test_authorized_user_can_list_divisions(self, user):
        self.client.force_authenticate(user=getattr(self.fixture, user))
        response = self.client.get(self.url)
        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual(len(response.data), 2)

    def test_anonymous_user_cannot_list_divisions(self):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

    def test_list_filters(self):
        """Test of divisions' list filter by name, type and parent UUID."""
        division_parent = factories.DivisionFactory()
        self.division_1.parent = division_parent
        self.division_1.save()
        rows = [
            {'name': 'name', 'valid': self.division_1.name[2:], 'invalid': 'AAA'},
            {'name': 'name_exact', 'valid': self.division_1.name, 'invalid': self.division_1.name[2:]},
            {'name': 'type', 'valid': self.division_1.type.name, 'invalid': self.division_1.type.name[2:]},
            {'name': 'parent', 'valid': division_parent.uuid.hex, 'invalid': division_parent.uuid.hex[2:]},
        ]
        self.client.force_authenticate(user=self.fixture.staff)

        for row in rows:
            response = self.client.get(self.url, data={row['name']: row['valid']})
            self.assertEqual(status.HTTP_200_OK, response.status_code)
            self.assertEqual(len(response.data), 1)

            response = self.client.get(self.url, data={row['name']: row['invalid']})
            if row['name'] == 'parent':
                self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
            else:
                self.assertEqual(status.HTTP_200_OK, response.status_code)
                self.assertEqual(len(response.data), 0)

{'fraction_non_alphanumeric': 0.13191395961369623, 'fraction_numerical': 0.013608428446005268, 'mean_word_length': 3.184573002754821, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4619900', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1354, 'n_words': 235}