Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
14
Issues
14
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
rpteam
rp
Commits
87160362
Commit
87160362
authored
Apr 30, 2019
by
Okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
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
Showing
2 changed files
with
54 additions
and
5 deletions
+54
-5
apps/core/views.py
apps/core/views.py
+0
-3
apps/rp/tests/test_article.py
apps/rp/tests/test_article.py
+54
-2
No files found.
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
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