Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
13
Issues
13
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
rpteam
rp
Commits
4e7004d3
Commit
4e7004d3
authored
Apr 18, 2019
by
okhin
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a lot of tests for the /rp/ views
parent
8616f16a
Pipeline
#2560
passed with stages
in 3 minutes and 6 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
11 deletions
+77
-11
apps/rp/factories.py
apps/rp/factories.py
+13
-4
apps/rp/tests/test_article.py
apps/rp/tests/test_article.py
+57
-2
apps/rp/tests/test_udlistview.py
apps/rp/tests/test_udlistview.py
+2
-2
apps/rp/tests/test_votes_views.py
apps/rp/tests/test_votes_views.py
+1
-1
apps/rp/urls.py
apps/rp/urls.py
+2
-1
apps/rp/views/articles.py
apps/rp/views/articles.py
+2
-1
No files found.
apps/rp/factories.py
View file @
4e7004d3
...
...
@@ -2,9 +2,9 @@ import datetime
import
pytz
import
factory
from
factory.fuzzy
import
FuzzyDateTime
from
factory.fuzzy
import
FuzzyDateTime
,
FuzzyChoice
from
.models
import
Article
from
.models
import
Article
,
STATUS_CHOICES
class
ArticleFactory
(
factory
.
django
.
DjangoModelFactory
):
...
...
@@ -12,7 +12,7 @@ class ArticleFactory(factory.django.DjangoModelFactory):
model
=
Article
url
=
factory
.
Faker
(
"url"
)
lang
=
"
en
"
lang
=
"
EN
"
title
=
factory
.
Faker
(
"sentence"
,
nb_words
=
4
)
website
=
factory
.
Sequence
(
lambda
n
:
"Website {}"
.
format
(
n
))
...
...
@@ -25,4 +25,13 @@ class ArticleFactory(factory.django.DjangoModelFactory):
published_at
=
FuzzyDateTime
(
datetime
.
datetime
(
2014
,
1
,
1
,
tzinfo
=
pytz
.
UTC
))
status
=
"NEW"
status
=
FuzzyChoice
(
STATUS_CHOICES
)
@
factory
.
post_generation
def
tags
(
self
,
create
,
extracted
,
**
kwargs
):
if
not
create
:
return
if
extracted
:
for
tag
in
extracted
:
self
.
tags
.
add
(
tag
)
apps/rp/tests/test_article.py
View file @
4e7004d3
from
django.test
import
TestCase
from
django.test
import
TestCase
,
Client
from
django.contrib.auth.models
import
User
from
rp.models
import
Article
from
rp.factories
import
ArticleFactory
from
rp.apps
import
RpConfig
from
rp.views.articles
import
ArticleList
class
Test
Vot
e
(
TestCase
):
class
Test
Articl
e
(
TestCase
):
def
setUp
(
self
):
self
.
article
=
ArticleFactory
()
...
...
@@ -15,3 +17,56 @@ class TestVote(TestCase):
def
test_article
(
self
):
assert
type
(
self
.
article
)
==
Article
assert
str
(
self
.
article
)
==
self
.
article
.
title
class
TestArticleViews
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
self
.
articles
=
[
ArticleFactory
(
tags
=
[
'Tag 1'
,
'Tag2'
])
for
i
in
range
(
0
,
2
*
ArticleList
.
paginate_by
)]
self
.
user
=
User
.
objects
.
create
(
username
=
"test"
,
email
=
"test@example.org"
,
password
=
"test"
)
for
a
in
self
.
articles
:
a
.
save
()
def
test_list_fr
(
self
):
# ArticleFactory use english by default, so we should have
# no objects
r
=
self
.
client
.
get
(
'/rp/'
)
assert
len
(
r
.
context
[
'object_list'
])
==
0
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
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
r
=
self
.
client
.
get
(
'/rp/by-tag/zogzog'
)
assert
len
(
r
.
context
[
'object_list'
])
==
0
def
test_filter_view
(
self
):
new
=
[
article
for
article
in
self
.
articles
if
article
.
status
==
'NEW'
]
r
=
self
.
client
.
get
(
'/rp/by-tag/new'
)
assert
len
(
r
.
context
[
'object_list'
])
==
len
(
new
)
r
=
self
.
client
.
get
(
'/rp/by-tag/nosuchtag'
)
assert
len
(
r
.
context
[
'object_list'
])
==
0
def
test_search_view
(
self
):
article
=
ArticleFactory
(
title
=
u'Zog Zog chez les schtroumphs'
,
lang
=
'FR'
)
article
.
save
()
r
=
self
.
client
.
get
(
'/rp/'
,
{
'q'
:
'Zog Zog'
})
assert
len
(
r
.
context
[
'article_list'
])
==
1
r
=
self
.
client
.
get
(
'/rp/'
,
{
'q'
:
'Gargamel was here'
})
assert
len
(
r
.
context
[
'article_list'
])
==
0
def
test_detail_view
(
self
):
# Let's find a published article
self
.
client
.
force_login
(
user
=
self
.
user
)
a
=
self
.
articles
[
0
]
r
=
self
.
client
.
get
(
'/rp/article/view/{}'
.
format
(
a
.
pk
))
assert
r
.
context
[
'object'
]
==
a
apps/rp/tests/test_udlistview.py
View file @
4e7004d3
...
...
@@ -8,8 +8,8 @@ from rp.models import Article
class
ArticleListTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
article
=
ArticleFactory
()
self
.
article2
=
ArticleFactory
()
self
.
article
=
ArticleFactory
(
status
=
'NEW'
)
self
.
article2
=
ArticleFactory
(
status
=
'NEW'
)
self
.
user
=
ProfileFactory
()
.
user
self
.
user2
=
ProfileFactory
()
.
user
...
...
apps/rp/tests/test_votes_views.py
View file @
4e7004d3
...
...
@@ -12,7 +12,7 @@ from rp.api.views import ArticleViewSet
class
VoteViewTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
article
=
ArticleFactory
()
self
.
article
=
ArticleFactory
(
status
=
"NEW"
)
self
.
article_draft
=
ArticleFactory
(
status
=
"DRAFT"
)
self
.
profile
=
ProfileFactory
()
...
...
apps/rp/urls.py
View file @
4e7004d3
from
django.conf.urls
import
url
from
rp.views.articles
import
ArticleListFlux
,
ArticleEdit
,
ArticleDetailView
,
ArticleList
from
rp.views.articles
import
(
ArticleListFlux
,
ArticleEdit
,
ArticleDetailView
,
ArticleList
)
urlpatterns
=
[
url
(
...
...
apps/rp/views/articles.py
View file @
4e7004d3
...
...
@@ -8,7 +8,8 @@ from django.db.models import Count
from
django.db.models
import
Q
from
django
import
forms
from
django.contrib.auth.mixins
import
LoginRequiredMixin
,
PermissionRequiredMixin
from
django.contrib.auth.mixins
import
(
LoginRequiredMixin
,
PermissionRequiredMixin
)
from
crispy_forms.helper
import
FormHelper
from
crispy_forms.layout
import
Layout
,
Field
,
Div
,
HTML
...
...
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