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
951dcb3b
Commit
951dcb3b
authored
May 07, 2019
by
Okhin
Browse files
Correcting managing the recover method, adding more tests and start status
parent
9aca3d39
Pipeline
#2588
passed with stages
in 3 minutes and 1 second
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/rp/models.py
View file @
951dcb3b
...
...
@@ -123,7 +123,7 @@ class Article(models.Model):
""" Publish a complete draft. """
self
.
published_at
=
datetime
.
now
()
@
transition
(
field
=
status
,
source
=
'NEW'
,
target
=
'DRAFT'
,
@
transition
(
field
=
status
,
source
=
[
'NEW'
,
'REJECTED'
],
target
=
'DRAFT'
,
permission
=
"rp.can_change_status"
)
def
recover
(
self
):
""" Force an article to be considered as _DRAFT_. """
...
...
apps/rp/tests/test_article.py
View file @
951dcb3b
from
django.test
import
TestCase
,
Client
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
,
Permission
from
rest_framework.test
import
APIClient
from
rp.models
import
Article
...
...
@@ -19,6 +19,15 @@ class TestArticle(TestCase):
assert
type
(
self
.
article
)
==
Article
assert
str
(
self
.
article
)
==
self
.
article
.
title
def
test_recover
(
self
):
article
=
ArticleFactory
(
status
=
'NEW'
)
article
.
recover
()
assert
article
.
status
==
'DRAFT'
article
=
ArticleFactory
(
status
=
'REJECTED'
)
article
.
recover
()
assert
article
.
status
==
'DRAFT'
class
TestArticleViews
(
TestCase
):
def
setUp
(
self
):
...
...
@@ -60,7 +69,8 @@ class TestArticleViews(TestCase):
assert
len
(
r
.
context
[
'object_list'
])
==
0
def
test_search_view
(
self
):
article
=
ArticleFactory
(
title
=
u
'Zog Zog chez les schtroumphs'
,
lang
=
'FR'
)
article
=
ArticleFactory
(
title
=
u
'Zog Zog chez les schtroumphs'
,
lang
=
'FR'
)
article
.
save
()
r
=
self
.
client
.
get
(
'/rp/'
,
{
'q'
:
'Zog Zog'
})
...
...
@@ -84,6 +94,9 @@ class TestArticleApi(TestCase):
self
.
user
=
User
.
objects
.
create
(
username
=
"test"
,
email
=
"test@example.org"
,
password
=
"test"
)
self
.
jedi
=
User
.
objects
.
create
(
username
=
"obiwan"
,
email
=
"o.kennoby@example.org"
,
password
=
"Thisaintthedroidyourelookin"
)
for
a
in
self
.
articles
:
a
.
save
()
...
...
@@ -146,3 +159,30 @@ class TestArticleApi(TestCase):
'tags'
:
''
})
assert
[
t
.
name
for
t
in
a
.
tags
.
all
()]
==
r
.
data
[
'tags'
]
def
test_api_recover
(
self
):
# Can we recover if we're no Jedis
self
.
client
.
force_login
(
user
=
self
.
user
)
a
=
ArticleFactory
(
status
=
'NEW'
)
r
=
self
.
client
.
post
(
'/api/articles/{}/recover/'
.
format
(
a
.
id
))
assert
r
.
status_code
==
403
# Can we recovr a NEW article and force it to DRAFT?
self
.
user
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
codename
=
'can_change_status'
))
self
.
client
.
force_login
(
user
=
self
.
user
)
a
=
ArticleFactory
(
status
=
'NEW'
)
r
=
self
.
client
.
post
(
'/api/articles/{}/recover/'
.
format
(
a
.
id
))
assert
r
.
status_code
==
200
assert
r
.
data
[
'status'
]
==
'DRAFT'
# Can we recovr a REJECTED article and force it to DRAFT?
a
=
ArticleFactory
(
status
=
'REJECTED'
)
r
=
self
.
client
.
post
(
'/api/articles/{}/recover/'
.
format
(
a
.
id
))
assert
r
.
status_code
==
200
assert
r
.
data
[
'status'
]
==
'DRAFT'
# We cannot recover a published article
a
=
ArticleFactory
(
status
=
'PUBLISHED'
)
r
=
self
.
client
.
post
(
'/api/articles/{}/recover/'
.
format
(
a
.
id
))
assert
r
.
status_code
==
403
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