serialized tags working

This commit is contained in:
Sam
2021-01-26 12:00:44 +00:00
parent 4437037710
commit 2a05beec07
5 changed files with 33 additions and 13 deletions

View File

@@ -16,7 +16,6 @@ class ProductFactory(DjangoModelFactory):
sku = FuzzyText(prefix='SKU_', length=10)
name = FuzzyText(prefix='NAME_', length=10)
description = FuzzyText(prefix='DECRIPTION', length=100)
image = None
url = FuzzyText(prefix='http://WEB-LINK-', suffix='.test', length=10)
price = FuzzyDecimal(low=1.00)
shipping_cost = FuzzyDecimal(low=1.00)
@@ -26,9 +25,9 @@ class ProductFactory(DjangoModelFactory):
update_date = FuzzyDateTime(start_dt=timezone.now())
discount = FuzzyDecimal(low=0.00, high=100.00)
stock = FuzzyInteger(low=0)
# 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 )
tags = ['test-tag']
category = 'top-category' # main tag category
attributes = ['programming/python', 'testing']
identifiers = FuzzyText(prefix='IDENTIFIERS_', length=100)
class Meta:

View File

@@ -32,9 +32,9 @@ class Product(models.Model):
update_date = models.DateTimeField('Fecha de actualización de producto', null=True, blank=True)
discount = models.DecimalField('Descuento', max_digits=5, decimal_places=2, null=True, blank=True)
stock = models.PositiveIntegerField('Stock', null=True)
tags = TagField( )
category = SingleTagField() # main tag category
attributes = TagField()
tags = TagField(force_lowercase=True,max_count=5, tree=True)
category = SingleTagField(null=True) # main tag category
attributes = TagField(force_lowercase=True,max_count=5, tree=True)
identifiers = models.TextField('Identificador único de producto', null=True, blank=True)
# internal

View File

@@ -1,6 +1,5 @@
from rest_framework import serializers
from taggit_serializer.serializers import TagListSerializerField, TaggitSerializer
from products.models import Product
from utils.tag_serializers import TagListSerializerField, TaggitSerializer, SingleTagSerializerField
@@ -14,5 +13,4 @@ class ProductSerializer(TaggitSerializer, serializers.ModelSerializer):
class Meta:
model = Product
# exclude = ['created', 'updated', 'creator']
fields = '__all__'
exclude = ['created', 'updated', 'creator']

View File

@@ -118,7 +118,7 @@ class ProductViewSetTest(APITestCase):
'discount': '0.05',
'stock': 22,
'tags': ['tag1, tag2'],
# 'category': '',
'category': 'Mr',
'attributes': ['color/red', 'size/xxl'],
'identifiers': '34rf34f43c43',
}
@@ -129,7 +129,6 @@ class ProductViewSetTest(APITestCase):
# Query endpoint
response = self.client.post(self.endpoint, data=data, format='json')
import ipdb; ipdb.set_trace()
# Assert endpoint returns created status
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
@@ -188,13 +187,36 @@ class ProductViewSetTest(APITestCase):
# Create instances
instance = self.factory()
# Define request data
company = CompanyFactory()
data = {
'company': company.id,
'sku': 'qwerewq',
'name': 'qwerewq',
'description': 'qwerewq',
'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': ['tag1, tag2'],
'category': 'Mr',
'attributes': ['color/red', 'size/xxl'],
'identifiers': '34rf34f43c43',
}
# Authenticate user
token = get_tokens_for_user(self.user)
self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {token['access']}")
# Query endpoint
url = self.endpoint + f'{instance.pk}/'
response = self.client.put(url, data={}, format='json')
response = self.client.put(url, data=data, format='json')
# Assert endpoint returns OK code
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)