<commit_before>from rest_framework import status
from rest_framework.test import APITestCase
from foodsaving.groups.factories import GroupFactory
from foodsaving.users.factories import UserFactory


class TestStoresAPIFilter(APITestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.url = '/api/groups/'

        # some user
        cls.user = UserFactory()

        # two groups with different members
        cls.member = UserFactory()
        cls.group = GroupFactory(members=[cls.member, ])
        cls.member2 = UserFactory()
        cls.group2 = GroupFactory(members=[cls.member2, ])
        cls.empty_group = GroupFactory()

    def test_filter_by_member(self):
        response = self.client.get(self.url, {'members': self.member.id})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], self.group.name)

        response = self.client.get(self.url, {'members': self.member.id})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], self.group.name)

    def test_dont_include_empty(self):
        response = self.client.get(self.url, {'include_empty': False})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 2)
        self.assertFalse(self.empty_group.id in [_['id'] for _ in response.data])

    def test_include_empty(self):
        response = self.client.get(self.url, {'include_empty': True})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 3)

    def test_search_name(self):
        response = self.client.get(self.url, {'search': self.group.name})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], self.group.name)

    def test_search_description(self):
        response = self.client.get(self.url, {'search': self.group.public_description[:10]})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], self.group.name)<commit_msg>fix: use full search text to allow for low faker entropy<commit_after>from rest_framework import status
from rest_framework.test import APITestCase
from foodsaving.groups.factories import GroupFactory
from foodsaving.users.factories import UserFactory


class TestGroupsAPIFilter(APITestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.url = '/api/groups/'

        # some user
        cls.user = UserFactory()

        # two groups with different members
        cls.member = UserFactory()
        cls.group = GroupFactory(members=[cls.member, ])
        cls.member2 = UserFactory()
        cls.group2 = GroupFactory(members=[cls.member2, ])
        cls.empty_group = GroupFactory()

    def test_filter_by_member(self):
        response = self.client.get(self.url, {'members': self.member.id})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], self.group.name)

        response = self.client.get(self.url, {'members': self.member.id})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], self.group.name)

    def test_dont_include_empty(self):
        response = self.client.get(self.url, {'include_empty': False})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 2)
        self.assertFalse(self.empty_group.id in [_['id'] for _ in response.data])

    def test_include_empty(self):
        response = self.client.get(self.url, {'include_empty': True})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 3)

    def test_search_name(self):
        response = self.client.get(self.url, {'search': self.group.name})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], self.group.name)

    def test_search_description(self):
        response = self.client.get(self.url, {'search': self.group.public_description})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], self.group.name)
{'fraction_non_alphanumeric': 0.1265186426476749, 'fraction_numerical': 0.013405948889819858, 'mean_word_length': 3.4751640112464854, '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': '6881961', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1399, 'n_words': 239}