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
2f289bad
Commit
2f289bad
authored
Apr 25, 2017
by
luxcem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds testing for article list
parent
6615d819
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
8 deletions
+137
-8
apps/core/management/commands/init_groups.py
apps/core/management/commands/init_groups.py
+1
-0
apps/rp/tests/test_article.py
apps/rp/tests/test_article.py
+1
-0
apps/rp/tests/test_udlistview.py
apps/rp/tests/test_udlistview.py
+115
-8
apps/rp/tests/test_votes_views.py
apps/rp/tests/test_votes_views.py
+19
-0
apps/rp/views/votes.py
apps/rp/views/votes.py
+1
-0
No files found.
apps/core/management/commands/init_groups.py
View file @
2f289bad
...
...
@@ -12,3 +12,4 @@ class Command(BaseCommand):
help
=
"Adds initial groups for the application (jedi and padawans)"
def
handle
(
self
,
*
args
,
**
options
):
pass
apps/rp/tests/test_article.py
View file @
2f289bad
...
...
@@ -14,3 +14,4 @@ class TestVote(TestCase):
def
test_article
(
self
):
assert
type
(
self
.
article
)
==
Article
assert
str
(
self
.
article
)
==
self
.
article
.
title
apps/rp/tests/test_udlistview.py
View file @
2f289bad
from
django.urls
import
reverse
from
django.test
import
TestCase
from
django.urls
import
reverse
from
userprofile.factories
import
ProfileFactory
from
rp.factories
import
ArticleFactory
#
from rp.models import Article
from
rp.models
import
Article
class
ArticleListTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
article
=
ArticleFactory
()
self
.
profile
=
ProfileFactory
()
self
.
user
=
self
.
profile
.
user
self
.
client
.
force_login
(
self
.
user
)
self
.
article2
=
ArticleFactory
()
self
.
user
=
ProfileFactory
().
user
self
.
user2
=
ProfileFactory
().
user
self
.
user3
=
ProfileFactory
().
user
def
test_votes
(
self
):
url_list
=
reverse
(
"rp:article-list"
)
response
=
self
.
client
.
get
(
url_list
)
def
test_empty_upvoted
(
self
):
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
get
(
reverse
(
"rp:article-list"
,
kwargs
=
{
"filter_view"
:
"flux"
}))
assert
response
.
status_code
==
200
# Get the context
context
=
response
.
context
assert
context
[
"und_votes"
][
"upvoted"
].
count
()
==
0
assert
context
[
"und_votes"
][
"downvoted"
].
count
()
==
0
def
test_upvoted
(
self
):
self
.
article
.
upvote
(
self
.
user
.
username
)
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
get
(
reverse
(
"rp:article-list"
,
kwargs
=
{
"filter_view"
:
"flux"
}))
assert
list
(
response
.
context
[
"und_votes"
][
"upvoted"
])
==
[
self
.
article
.
id
]
assert
list
(
response
.
context
[
"und_votes"
][
"downvoted"
])
==
[]
def
test_downvoted
(
self
):
self
.
article
.
downvote
(
self
.
user
.
username
)
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
get
(
reverse
(
"rp:article-list"
,
kwargs
=
{
"filter_view"
:
"flux"
}))
assert
list
(
response
.
context
[
"und_votes"
][
"upvoted"
])
==
[]
assert
list
(
response
.
context
[
"und_votes"
][
"downvoted"
])
==
[
self
.
article
.
id
]
def
test_2users
(
self
):
self
.
article
.
downvote
(
self
.
user
.
username
)
self
.
article2
.
upvote
(
self
.
user
.
username
)
self
.
article
.
upvote
(
self
.
user2
.
username
)
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
get
(
reverse
(
"rp:article-list"
,
kwargs
=
{
"filter_view"
:
"flux"
}))
assert
list
(
response
.
context
[
"und_votes"
][
"upvoted"
])
==
[
self
.
article2
.
id
]
assert
list
(
response
.
context
[
"und_votes"
][
"downvoted"
])
==
[
self
.
article
.
id
]
self
.
client
.
force_login
(
self
.
user2
)
response
=
self
.
client
.
get
(
reverse
(
"rp:article-list"
,
kwargs
=
{
"filter_view"
:
"flux"
}))
assert
list
(
response
.
context
[
"und_votes"
][
"upvoted"
])
==
[
self
.
article
.
id
]
assert
list
(
response
.
context
[
"und_votes"
][
"downvoted"
])
==
[]
def
_test_filter_view
(
self
,
filter_view
):
"""Return list of articles ids in filter_view"""
response
=
self
.
client
.
get
(
reverse
(
"rp:article-list"
,
kwargs
=
{
"filter_view"
:
filter_view
}))
return
sorted
(
response
.
context
[
"object_list"
].
values_list
(
'id'
,
flat
=
True
))
def
test_filter_view
(
self
):
self
.
article
.
upvote
(
self
.
user
.
username
)
self
.
article
.
upvote
(
self
.
user2
.
username
)
self
.
client
.
force_login
(
self
.
user
)
assert
self
.
_test_filter_view
(
"flux"
)
==
sorted
(
[
self
.
article
.
pk
,
self
.
article2
.
pk
]
)
assert
self
.
_test_filter_view
(
"published"
)
==
[]
assert
self
.
_test_filter_view
(
"draft"
)
==
[]
assert
self
.
_test_filter_view
(
"rejected"
)
==
[]
self
.
article
.
upvote
(
self
.
user3
.
username
)
assert
self
.
_test_filter_view
(
"flux"
)
==
sorted
(
[
self
.
article
.
pk
,
self
.
article2
.
pk
]
)
assert
self
.
_test_filter_view
(
"published"
)
==
[]
assert
self
.
_test_filter_view
(
"draft"
)
==
[
self
.
article
.
id
]
assert
self
.
_test_filter_view
(
"rejected"
)
==
[]
self
.
article2
.
status
=
"REJECTED"
self
.
article2
.
save
()
assert
self
.
_test_filter_view
(
"published"
)
==
[]
assert
self
.
_test_filter_view
(
"flux"
)
==
[
self
.
article
.
id
]
assert
self
.
_test_filter_view
(
"draft"
)
==
[
self
.
article
.
id
]
assert
self
.
_test_filter_view
(
"rejected"
)
==
[
self
.
article2
.
id
]
self
.
article
.
status
=
"PUBLISHED"
self
.
article
.
save
()
assert
self
.
_test_filter_view
(
"published"
)
==
[
self
.
article
.
id
]
assert
self
.
_test_filter_view
(
"flux"
)
==
[]
assert
self
.
_test_filter_view
(
"draft"
)
==
[]
assert
self
.
_test_filter_view
(
"rejected"
)
==
[
self
.
article2
.
id
]
apps/rp/tests/test_votes_views.py
View file @
2f289bad
...
...
@@ -31,3 +31,22 @@ class VoteViewTestCase(TestCase):
assert
response
.
status_code
==
200
article_db
=
Article
.
objects
.
get
(
id
=
self
.
article
.
id
)
assert
article_db
.
und_score
==
-
1
def
test_publish
(
self
):
url_publish
=
reverse
(
"api:article-publish"
,
kwargs
=
{
"pk"
:
self
.
article
.
id
})
url_reject
=
reverse
(
"api:article-reject"
,
kwargs
=
{
"pk"
:
self
.
article
.
id
})
response
=
self
.
client
.
post
(
url_publish
)
assert
response
.
status_code
==
200
article_db
=
Article
.
objects
.
get
(
id
=
self
.
article
.
id
)
assert
article_db
.
status
==
"PUBLISHED"
response
=
self
.
client
.
post
(
url_reject
)
assert
response
.
status_code
==
200
article_db
=
Article
.
objects
.
get
(
id
=
self
.
article
.
id
)
assert
article_db
.
status
==
"REJECTED"
apps/rp/views/votes.py
View file @
2f289bad
...
...
@@ -10,6 +10,7 @@ class UDList(ListView):
content_type
=
ContentType
.
objects
.
get_for_model
(
self
.
model
)
queryset
=
self
.
get_queryset
()
context
=
super
().
get_context_data
(
**
kwargs
)
context
[
"und_votes"
]
=
{
"upvoted"
:
queryset
.
filter
(
und_votes__username
=
self
.
request
.
user
.
username
,
...
...
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