diff --git a/companies/factories.py b/companies/factories.py index 01880cc..c8a051b 100644 --- a/companies/factories.py +++ b/companies/factories.py @@ -31,4 +31,33 @@ class CompanyFactory(DjangoModelFactory): sync = FuzzyChoice(choices=(True, False)) class Meta: - model = 'companies.Company' \ No newline at end of file + model = 'companies.Company' + + +class ValidatedCompanyFactory(DjangoModelFactory): + + cif = FuzzyText(prefix='CIF_', length=10) + company_name = FuzzyText(prefix='COMPANY_NAME_', length=10) + short_name = FuzzyText(prefix='SHORT_NAME_', length=10) + web_link = FuzzyText(prefix='http://WEB-LINK-', suffix='.test', length=10) + shop = FuzzyChoice(choices=(True, False)) + shop_link = FuzzyText(prefix='http://SHOP-LINK-', suffix='.test', length=10) + platform = FuzzyChoice(choices=[x[1] for x in Company.PLATFORMS]) + email = FuzzyText(prefix='EMAIL_', suffix='@test.com', length=10) + logo = None + city = None + address = FuzzyText(prefix='ADDRESS_', length=10) + geo = None + phone = '+34666555444' + mobile = '+34666555333' + other_phone = '+34666555222' + description = FuzzyText(prefix='DESCRIPTION_', length=250) + shop_rss_feed = FuzzyText(prefix='http://SHOP-RSS-FEED-', suffix='.test', length=10) + sale_terms = FuzzyText(prefix='SALES_TERMS', length=250) + shipping_cost = FuzzyDecimal(low=1.00) + tags = ['cool', 'hip', 'tech/blockchain'] + sync = FuzzyChoice(choices=(True, False)) + is_validated = True + + class Meta: + model = 'companies.Company' diff --git a/companies/tests.py b/companies/tests.py index 3c78501..07189da 100644 --- a/companies/tests.py +++ b/companies/tests.py @@ -7,7 +7,7 @@ from django.test import TestCase from rest_framework.test import APITestCase from rest_framework import status -from companies.factories import CompanyFactory +from companies.factories import ValidatedCompanyFactory from companies.models import Company from core.factories import CustomUserFactory @@ -23,7 +23,7 @@ class CompanyViewSetTest(APITestCase): """Tests setup """ self.endpoint = '/api/v1/companies/' - self.factory = CompanyFactory + self.factory = ValidatedCompanyFactory self.model = Company # create user self.password = ''.join(random.choices(string.ascii_uppercase, k = 10)) @@ -302,7 +302,7 @@ class MyCompanyViewTest(APITestCase): """Tests setup """ self.endpoint = '/api/v1/my_company/' - self.factory = CompanyFactory + self.factory = ValidatedCompanyFactory self.model = Company # create user self.email = f"user@mail.com" @@ -313,10 +313,7 @@ class MyCompanyViewTest(APITestCase): def test_auth_user_gets_data(self): # create instance - user_instances = [ - self.factory(creator=self.user), - self.factory(creator=self.user), - ] + user_instances = [self.factory(creator=self.user) for i in range(5)] # Authenticate token = get_tokens_for_user(self.user) @@ -365,7 +362,7 @@ class RandomCompanySampleTest(APITestCase): """Tests setup """ self.endpoint = '/api/v1/companies/sample/' - self.factory = CompanyFactory + self.factory = ValidatedCompanyFactory self.model = Company # create user self.email = f"user@mail.com" diff --git a/companies/views.py b/companies/views.py index cb436e5..c92ab46 100644 --- a/companies/views.py +++ b/companies/views.py @@ -24,7 +24,7 @@ from utils import woocommerce class CompanyViewSet(viewsets.ModelViewSet): - queryset = Company.objects.all().order_by('-created') + queryset = Company.objects.filter(is_validated=True).order_by('-created') serializer_class = CompanySerializer permission_classes = [IsAuthenticatedOrReadOnly, IsCreator] filterset_class = CompanyTagFilter @@ -187,6 +187,6 @@ def random_company_sample(request): except: return Response({"error": "Wrong value for size, must be a number"}, status=status.HTTP_406_NOT_ACCEPTABLE) - queryset = Company.objects.all().order_by('?')[:size] + queryset = Company.objects.filter(is_validated=True).order_by('?')[:size] serializer = CompanySerializer(queryset, many=True) return Response(serializer.data)