From cf5d193765e3e60738d30d6bb87e041a5209d7c4 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 22 Jan 2021 13:58:32 +0000 Subject: [PATCH] added basic tests for StatsLogs --- products/factories.py | 2 +- products/tests.py | 79 +++++++++++++++++++++---------------------- stats/factories.py | 20 +++++++++++ 3 files changed, 60 insertions(+), 41 deletions(-) create mode 100644 stats/factories.py diff --git a/products/factories.py b/products/factories.py index e5873fd..efe243f 100644 --- a/products/factories.py +++ b/products/factories.py @@ -1,7 +1,7 @@ import datetime from django.utils import timezone from factory import SubFactory -from factory.fuzzy import FuzzyText, FuzzyInteger, FuzzyDateTime, FuzzyDate, FuzzyDecimal, FuzzyChoice, FuzzyDateTime +from factory.fuzzy import FuzzyText, FuzzyInteger, FuzzyDateTime, FuzzyDate, FuzzyDecimal, FuzzyChoice from factory.django import DjangoModelFactory from companies.factories import CompanyFactory diff --git a/products/tests.py b/products/tests.py index 7733e18..14fe231 100644 --- a/products/tests.py +++ b/products/tests.py @@ -1,6 +1,9 @@ import random import string import json +import datetime + +from django.utils import timezone from rest_framework.test import APITestCase from rest_framework import status @@ -99,26 +102,24 @@ class ProductViewSetTest(APITestCase): """ # Define request data data = { - 'cif': 'qwerewq', - 'company_name': 'qwerewq', - 'short_name': 'qwerewq', - 'web_link': 'http://qwerewq.com', - 'shop': True, - 'shop_link': 'http://qwerewq.com', - 'platform': 'PRESTASHOP', - 'email': 'test@email.com', - 'logo': None, - 'city': None, - 'address': 'qwer qewr 5', - 'geo': None, - 'phone': '1234', - 'mobile': '4321', - 'other_phone': '41423', - 'description': 'dfgfdgdfg', - 'shop_rss_feed': 'http://qwerewq.com', - 'sale_terms': 'tewrnmfew f ewfrfew ewewew f', - 'shipping_cost': '12.25', - 'sync': False + 'company': None, + 'sku': 'qwerewq', + 'name': 'qwerewq', + 'description': 'qwerewq', + 'image': None, + 'url': 'http://qwerewq.com', + 'price': '12.21', + 'shipping_cost': '21.12', + 'shipping_terms': 'qwerewq', + 'source': 'SYNCHRONIZED', + 'sourcing_date': datetime.datetime.now().isoformat()+'Z', + 'update_date': datetime.datetime.now().isoformat()+'Z', + 'discount': '0.05', + 'stock': 22, + # tags = models.ManyToMany(Tag, null=True, blank=True ) + # category = models.ForeignKey(Tag, null=true) # main tag category + # attributes = models.ManyToMany(Tag, null=True, blank=True ) + 'identifiers': '34rf34f43c43', } # Authenticate user @@ -145,26 +146,24 @@ class ProductViewSetTest(APITestCase): # Define request data data = { - 'cif': 'qwerewq', - 'company_name': 'qwerewq', - 'short_name': 'qwerewq', - 'web_link': 'http://qwerewq.com', - 'shop': True, - 'shop_link': 'http://qwerewq.com', - 'platform': 'PRESTASHOP', - 'email': 'test@email.com', - 'logo': None, - 'city': None, - 'address': 'qwer qewr 5', - 'geo': None, - 'phone': '1234', - 'mobile': '4321', - 'other_phone': '41423', - 'description': 'dfgfdgdfg', - 'shop_rss_feed': 'http://qwerewq.com', - 'sale_terms': 'tewrnmfew f ewfrfew ewewew f', - 'shipping_cost': '12.25', - 'sync': False + 'company': None, + 'sku': 'qwerewq', + 'name': 'qwerewq', + 'description': 'qwerewq', + 'image': None, + 'url': 'http://qwerewq.com', + 'price': '12.21', + 'shipping_cost': '21.12', + 'shipping_terms': 'qwerewq', + 'source': 'SYNCHRONIZED', + 'sourcing_date': datetime.datetime.now().isoformat()+'Z', + 'update_date': datetime.datetime.now().isoformat()+'Z', + 'discount': '0.05', + 'stock': 22, + # tags = models.ManyToMany(Tag, null=True, blank=True ) + # category = models.ForeignKey(Tag, null=true) # main tag category + # attributes = models.ManyToMany(Tag, null=True, blank=True ) + 'identifiers': '34rf34f43c43', } # Authenticate user diff --git a/stats/factories.py b/stats/factories.py new file mode 100644 index 0000000..cd4faa3 --- /dev/null +++ b/stats/factories.py @@ -0,0 +1,20 @@ +import datetime +from django.utils import timezone +from factory import SubFactory +from factory.fuzzy import FuzzyText, FuzzyInteger, FuzzyDateTime, FuzzyDate, FuzzyDecimal, FuzzyChoice +from factory.django import DjangoModelFactory + + +class StatsLogFactory(DjangoModelFactory): + + model = None + user = SubFactory('core.factories.CustomUserFactory') + anonymous = FuzzyChoice(choices=(True, False)) + ip_address = '127.0.0.1' + geo = None + contact = FuzzyChoice(choices=(True, False)) + shop = FuzzyChoice(choices=(True, False)) + + + class Meta: + model = 'stats.StatsLog' \ No newline at end of file