Commit 47a7eedf authored by okhin's avatar okhin 🚴

Let's jsonify the Tag serializers - and let's work a little bit around with formatting

parent 7d4b31fa
Pipeline #2627 passed with stages
in 3 minutes and 8 seconds
import json
from rest_framework import serializers
from taggit.models import Tag
......@@ -11,6 +13,9 @@ class TagListSerializer(serializers.ModelSerializer):
model = Tag
fields = ('name', )
def to_representation(self, value):
return json.dumps({'name': value.name})
class ArticleSerializer(serializers.ModelSerializer):
#: List of short tags to describe the article (eg. "Privacy", "Copyright")
......
import json
from django.test import TestCase, Client
from django.contrib.auth.models import User, Permission
from rest_framework.test import APIClient
......@@ -237,25 +239,26 @@ class TestArticleApi(TestCase):
a = ArticleFactory(tags=['ZogZog'],)
r = self.client.post('/api/articles/',
{'url': a.url, 'title': a.title,
'tags': ','.join([t.name for t in a.tags.all()])
})
'tags': a.tags.all().values('name')},
format='json')
assert r.status_code == 401
def test_api_tag_push_auth(self):
self.client.force_login(user=self.user)
a = ArticleFactory(tags=['ZogZog'], status='NEW')
a = ArticleFactory(tags=['ZogZog', 'Blip Blop'], status='NEW')
r = self.client.post('/api/articles/',
{'url': a.url, 'title': a.title,
'tags': ','.join([t.name for t in a.tags.all()])
})
'tags': a.tags.all().values('name')},
format='json')
assert r.status_code == 201
assert list(a.tags.all().values('name')) == [json.loads(t) for t in r.data['tags']]
# Need to test if we keep the tags
r = self.client.post('/api/articles/',
{'url': a.url, 'title': a.title,
'tags': ''
})
assert [t.name for t in a.tags.all()] == [t['name'] for t in r.data['tags']]
assert list(a.tags.all().values('name')) == [json.loads(t) for t in r.data['tags']]
def test_api_recover(self):
# Can we recover if we're no Jedis
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment