Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
rpteam
Revue de Press
Commits
47a7eedf
Commit
47a7eedf
authored
Jun 17, 2019
by
Okhin
Browse files
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
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/rp/api/serializers.py
View file @
47a7eedf
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")
...
...
apps/rp/tests/test_article.py
View file @
47a7eedf
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment