Commit a0d3c790 authored by okhin's avatar okhin 🚴

Merge branch...

Merge branch '33-la-liste-des-tags-lors-de-la-creation-d-un-article-n-est-pas-une-liste-mais-une-chaine-de-caracteres' into 'rp2'

Resolve "La liste des tags lors de la création d'un article n'est pas une liste, mais une chaine de caractères"

See merge request !46
parents 7d4b31fa 2ad327a6
Pipeline #2630 passed with stages
in 4 minutes and 17 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']]
},
format='json')
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