Commit 84565d6b authored by okhin's avatar okhin 🚴

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
......@@ -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
......@@ -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
......
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):
......
......@@ -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_speakd(self):
def test_search_view_speaks(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/',
......
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