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
84565d6b
Commit
84565d6b
authored
May 23, 2019
by
Okhin
Browse files
Moving the search and flags filter as query items. Adding the flags to the Factory.
parent
84cf52e4
Pipeline
#2613
passed with stages
in 3 minutes and 3 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/rp/api/urls.py
View file @
84565d6b
...
...
@@ -6,6 +6,6 @@ router = routers.DefaultRouter()
router
.
register
(
r
"articles"
,
ArticleViewSet
)
router
.
register
(
r
"articles-by-tag/(?P<filter_tag>.+)"
,
ArticleTag
)
router
.
register
(
r
"articles-search/(?P<search_keywords>.+)"
,
ArticleSearch
)
#
router.register(r"articles-search/(?P<search_keywords>.+)", ArticleSearch)
urlpatterns
=
router
.
urls
apps/rp/api/views.py
View file @
84565d6b
...
...
@@ -4,12 +4,13 @@ from rest_framework import viewsets, mixins
from
rp.models
import
Article
from
.serializers
import
ArticleSerializer
from
rp.views.articles
import
ArticleFilterMixin
from
.mixins
import
get_viewset_transition_actions_mixin
ArticleMixin
=
get_viewset_transition_actions_mixin
(
Article
)
class
ArticleViewSet
(
ArticleMixin
,
viewsets
.
ModelViewSet
):
class
ArticleViewSet
(
ArticleMixin
,
ArticleFilterMixin
,
viewsets
.
ModelViewSet
):
"""
articles:
This viewset describes all the method usable on the API
...
...
apps/rp/factories.py
View file @
84565d6b
import
datetime
from
random
import
choice
import
pytz
import
factory
...
...
@@ -26,6 +27,9 @@ class ArticleFactory(factory.django.DjangoModelFactory):
datetime
.
datetime
(
2014
,
1
,
1
,
tzinfo
=
pytz
.
UTC
))
status
=
FuzzyChoice
([
s
[
0
]
for
s
in
STATUS_CHOICES
])
archive
=
choice
([
True
,
False
])
quote
=
choice
([
True
,
False
])
speak
=
choice
([
True
,
False
])
@
factory
.
post_generation
def
tags
(
self
,
create
,
extracted
,
**
kwargs
):
...
...
apps/rp/tests/test_article.py
View file @
84565d6b
...
...
@@ -10,8 +10,8 @@ from rp.views.articles import ArticleList
class
TestArticle
(
TestCase
):
def
setUp
(
self
):
self
.
article
=
ArticleFactory
()
self
.
newarticle
=
ArticleFactory
(
status
=
'NEW'
)
self
.
article
=
ArticleFactory
(
archive
=
False
,
quote
=
False
,
speak
=
False
)
self
.
newarticle
=
ArticleFactory
(
status
=
'NEW'
,
archive
=
False
,
quote
=
False
,
speak
=
False
)
def
test_init
(
self
):
assert
RpConfig
.
name
==
"rp"
...
...
@@ -104,15 +104,19 @@ class TestArticleViews(TestCase):
def
test_list_en
(
self
):
r
=
self
.
client
.
get
(
'/rp/international'
)
assert
r
.
context
[
'is_paginated'
]
assert
len
(
r
.
context
[
'object_list'
])
==
ArticleList
.
paginate_by
if
r
.
context
[
'is_paginated'
]:
assert
len
(
r
.
context
[
'object_list'
])
==
ArticleList
.
paginate_by
else
:
assert
len
(
r
.
context
[
'object_list'
])
==
0
def
test_filter_tag
(
self
):
tag
=
self
.
articles
[
0
].
tags
.
all
()[
1
]
r
=
self
.
client
.
get
(
'/rp/by-tag/{}'
.
format
(
tag
.
name
))
assert
r
.
context
[
'is_paginated'
]
assert
len
(
r
.
context
[
'object_list'
])
==
ArticleList
.
paginate_by
if
r
.
context
[
'is_paginated'
]:
assert
len
(
r
.
context
[
'object_list'
])
==
ArticleList
.
paginate_by
else
:
assert
len
(
r
.
context
[
'object_list'
])
==
0
r
=
self
.
client
.
get
(
'/rp/by-tag/zogzog'
)
assert
len
(
r
.
context
[
'object_list'
])
==
0
...
...
@@ -136,7 +140,7 @@ class TestArticleViews(TestCase):
r
=
self
.
client
.
get
(
'/rp/'
,
{
'archive'
:
'false'
})
assert
len
(
r
.
context
[
'article_list'
])
==
0
def
test_search_view_speak
d
(
self
):
def
test_search_view_speak
s
(
self
):
speak
=
ArticleFactory
(
speak
=
True
,
lang
=
'FR'
)
r
=
self
.
client
.
get
(
'/rp/'
,
{
'q'
:
''
,
'speak'
:
'true'
})
...
...
@@ -209,11 +213,16 @@ class TestArticleApi(TestCase):
def
test_api_filter_search
(
self
):
# text = ' '.join(self.articles[0].extracts.split(' ')[:10])
text
=
self
.
articles
[
0
].
title
r
=
self
.
client
.
get
(
'/api/articles
-search/{}/'
.
format
(
text
)
)
r
=
self
.
client
.
get
(
'/api/articles
/'
,
{
'q'
:
text
}
)
assert
r
.
status_code
==
200
assert
r
.
data
[
'count'
]
==
1
assert
r
.
data
[
'results'
][
0
][
'id'
]
==
self
.
articles
[
0
].
id
def
test_api_filter_flag_search
(
self
):
r
=
self
.
client
.
get
(
'/api/articles/'
,
{
'quote'
:
'both'
})
assert
r
.
status_code
==
200
assert
r
.
data
[
'count'
]
==
len
(
self
.
articles
)
def
test_api_tag_push_unauth
(
self
):
a
=
ArticleFactory
(
tags
=
[
'ZogZog'
],)
r
=
self
.
client
.
post
(
'/api/articles/'
,
...
...
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