serialized tags working
This commit is contained in:
@@ -45,6 +45,7 @@ INSTALLED_APPS = [
|
|||||||
'django_filters',
|
'django_filters',
|
||||||
'corsheaders',
|
'corsheaders',
|
||||||
'taggit_serializer',
|
'taggit_serializer',
|
||||||
|
'tagulous',
|
||||||
|
|
||||||
# local apps
|
# local apps
|
||||||
'core',
|
'core',
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ class ProductFactory(DjangoModelFactory):
|
|||||||
sku = FuzzyText(prefix='SKU_', length=10)
|
sku = FuzzyText(prefix='SKU_', length=10)
|
||||||
name = FuzzyText(prefix='NAME_', length=10)
|
name = FuzzyText(prefix='NAME_', length=10)
|
||||||
description = FuzzyText(prefix='DECRIPTION', length=100)
|
description = FuzzyText(prefix='DECRIPTION', length=100)
|
||||||
image = None
|
|
||||||
url = FuzzyText(prefix='http://WEB-LINK-', suffix='.test', length=10)
|
url = FuzzyText(prefix='http://WEB-LINK-', suffix='.test', length=10)
|
||||||
price = FuzzyDecimal(low=1.00)
|
price = FuzzyDecimal(low=1.00)
|
||||||
shipping_cost = FuzzyDecimal(low=1.00)
|
shipping_cost = FuzzyDecimal(low=1.00)
|
||||||
@@ -26,9 +25,9 @@ class ProductFactory(DjangoModelFactory):
|
|||||||
update_date = FuzzyDateTime(start_dt=timezone.now())
|
update_date = FuzzyDateTime(start_dt=timezone.now())
|
||||||
discount = FuzzyDecimal(low=0.00, high=100.00)
|
discount = FuzzyDecimal(low=0.00, high=100.00)
|
||||||
stock = FuzzyInteger(low=0)
|
stock = FuzzyInteger(low=0)
|
||||||
# tags = models.ManyToMany(Tag, null=True, blank=True )
|
tags = ['test-tag']
|
||||||
# category = models.ForeignKey(Tag, null=true) # main tag category
|
category = 'top-category' # main tag category
|
||||||
# attributes = models.ManyToMany(Tag, null=True, blank=True )
|
attributes = ['programming/python', 'testing']
|
||||||
identifiers = FuzzyText(prefix='IDENTIFIERS_', length=100)
|
identifiers = FuzzyText(prefix='IDENTIFIERS_', length=100)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ class Product(models.Model):
|
|||||||
update_date = models.DateTimeField('Fecha de actualización de producto', null=True, blank=True)
|
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)
|
discount = models.DecimalField('Descuento', max_digits=5, decimal_places=2, null=True, blank=True)
|
||||||
stock = models.PositiveIntegerField('Stock', null=True)
|
stock = models.PositiveIntegerField('Stock', null=True)
|
||||||
tags = TagField( )
|
tags = TagField(force_lowercase=True,max_count=5, tree=True)
|
||||||
category = SingleTagField() # main tag category
|
category = SingleTagField(null=True) # main tag category
|
||||||
attributes = TagField()
|
attributes = TagField(force_lowercase=True,max_count=5, tree=True)
|
||||||
identifiers = models.TextField('Identificador único de producto', null=True, blank=True)
|
identifiers = models.TextField('Identificador único de producto', null=True, blank=True)
|
||||||
|
|
||||||
# internal
|
# internal
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from taggit_serializer.serializers import TagListSerializerField, TaggitSerializer
|
|
||||||
from products.models import Product
|
from products.models import Product
|
||||||
|
|
||||||
from utils.tag_serializers import TagListSerializerField, TaggitSerializer, SingleTagSerializerField
|
from utils.tag_serializers import TagListSerializerField, TaggitSerializer, SingleTagSerializerField
|
||||||
@@ -14,5 +13,4 @@ class ProductSerializer(TaggitSerializer, serializers.ModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Product
|
model = Product
|
||||||
# exclude = ['created', 'updated', 'creator']
|
exclude = ['created', 'updated', 'creator']
|
||||||
fields = '__all__'
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ class ProductViewSetTest(APITestCase):
|
|||||||
'discount': '0.05',
|
'discount': '0.05',
|
||||||
'stock': 22,
|
'stock': 22,
|
||||||
'tags': ['tag1, tag2'],
|
'tags': ['tag1, tag2'],
|
||||||
# 'category': '',
|
'category': 'Mr',
|
||||||
'attributes': ['color/red', 'size/xxl'],
|
'attributes': ['color/red', 'size/xxl'],
|
||||||
'identifiers': '34rf34f43c43',
|
'identifiers': '34rf34f43c43',
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,6 @@ class ProductViewSetTest(APITestCase):
|
|||||||
|
|
||||||
# Query endpoint
|
# Query endpoint
|
||||||
response = self.client.post(self.endpoint, data=data, format='json')
|
response = self.client.post(self.endpoint, data=data, format='json')
|
||||||
import ipdb; ipdb.set_trace()
|
|
||||||
# Assert endpoint returns created status
|
# Assert endpoint returns created status
|
||||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
|
|
||||||
@@ -188,13 +187,36 @@ class ProductViewSetTest(APITestCase):
|
|||||||
# Create instances
|
# Create instances
|
||||||
instance = self.factory()
|
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
|
# Authenticate user
|
||||||
token = get_tokens_for_user(self.user)
|
token = get_tokens_for_user(self.user)
|
||||||
self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {token['access']}")
|
self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {token['access']}")
|
||||||
|
|
||||||
# Query endpoint
|
# Query endpoint
|
||||||
url = self.endpoint + f'{instance.pk}/'
|
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
|
# Assert endpoint returns OK code
|
||||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||||
|
|||||||
Reference in New Issue
Block a user