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
87160362
Commit
87160362
authored
Apr 30, 2019
by
Okhin
Browse files
Finsihing some API tests
parent
4e7004d3
Pipeline
#2568
failed with stages
in 48 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/core/views.py
deleted
100644 → 0
View file @
4e7004d3
from
django.shortcuts
import
render
# Create your views here.
apps/rp/tests/test_article.py
View file @
87160362
from
django.test
import
TestCase
,
Client
from
django.contrib.auth.models
import
User
from
rest_framework.test
import
APIClient
from
rp.models
import
Article
from
rp.factories
import
ArticleFactory
...
...
@@ -22,8 +23,11 @@ class TestArticle(TestCase):
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"
)
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
()
...
...
@@ -70,3 +74,51 @@ class TestArticleViews(TestCase):
a
=
self
.
articles
[
0
]
r
=
self
.
client
.
get
(
'/rp/article/view/{}'
.
format
(
a
.
pk
))
assert
r
.
context
[
'object'
]
==
a
class
TestArticleApi
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
APIClient
()
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_api_get
(
self
):
r
=
self
.
client
.
get
(
'/api/articles/1/'
,
{})
assert
r
.
status_code
==
200
assert
r
.
data
[
'id'
]
==
1
def
test_api_list
(
self
):
r
=
self
.
client
.
get
(
'/api/articles/'
,
{})
assert
r
.
status_code
==
200
assert
r
.
data
[
'count'
]
==
2
*
ArticleList
.
paginate_by
def
test_api_filter_tag
(
self
):
tag
=
self
.
articles
[
0
].
tags
.
all
()[
1
]
# All articles have Tag2 as a tag
r
=
self
.
client
.
get
(
'/api/articles-by-tag/{}/'
.
format
(
tag
.
name
))
assert
r
.
status_code
==
200
assert
r
.
data
[
'count'
]
==
2
*
ArticleList
.
paginate_by
# Case sensitivity checking - tags are sensitive to case
r
=
self
.
client
.
get
(
'/api/articles-by-tag/{}/'
.
format
(
tag
.
name
.
lower
()))
assert
r
.
status_code
==
200
assert
r
.
data
[
'count'
]
==
0
# No article should have the ZogZog tag
r
=
self
.
client
.
get
(
'/api/articles-by-tag/zogzog/'
)
assert
r
.
status_code
==
200
assert
r
.
data
[
'count'
]
==
0
def
test_api_filter_search
(
self
):
text
=
'+'
.
join
(
self
.
articles
[
0
].
extracts
.
split
(
' '
)[:
10
])
r
=
self
.
client
.
get
(
'/api/articles-search/{}/'
.
format
(
text
))
print
(
r
.
data
)
assert
r
.
status_code
==
200
assert
r
.
data
[
'count'
]
==
1
assert
r
.
data
[
'results'
][
0
][
'id'
]
==
self
.
articles
[
0
].
id
Write
Preview
Supports
Markdown
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