Skip to content
GitLab
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
2f289bad
Commit
2f289bad
authored
Apr 25, 2017
by
luxcem
Browse files
adds testing for article list
parent
6615d819
Changes
5
Hide whitespace changes
Inline
Side-by-side
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
Supports
Markdown
0%
Try again
or
attach a new 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