Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Debian New Member Process
nm.debian.org
Commits
fdee4676
Commit
fdee4676
authored
Jun 03, 2016
by
Enrico Zini
Browse files
Refactoed test_process_show to use mock
parent
a3b48274
Changes
1
Hide whitespace changes
Inline
Side-by-side
process/tests/test_process_show.py
View file @
fdee4676
...
@@ -10,25 +10,21 @@ from backend import const
...
@@ -10,25 +10,21 @@ from backend import const
from
backend
import
models
as
bmodels
from
backend
import
models
as
bmodels
from
backend.unittest
import
PersonFixtureMixin
,
ExpectedSets
,
TestSet
,
PageElements
from
backend.unittest
import
PersonFixtureMixin
,
ExpectedSets
,
TestSet
,
PageElements
import
process.models
as
pmodels
import
process.models
as
pmodels
from
mock
import
patch
from
.common
import
ProcessFixtureMixin
,
get_all_process_types
from
.common
import
ProcessFixtureMixin
,
get_all_process_types
class
TestProcessShow
(
ProcessFixtureMixin
,
TestCase
):
class
TestProcessShow
(
ProcessFixtureMixin
,
TestCase
):
@
classmethod
def
__add_extra_tests__
(
cls
):
for
src
,
tgt
in
get_all_process_types
():
want_am
=
"am_ok"
in
pmodels
.
Process
.
objects
.
compute_requirements
(
src
,
tgt
)
visitors
=
[
None
,
"pending"
,
"dc"
,
"dc_ga"
,
"dm"
,
"dm_ga"
,
"dd_nu"
,
"dd_u"
,
"dd_e"
,
"dd_r"
,
"activeam"
,
"fd"
,
"dam"
,
"app"
]
if
want_am
:
visitors
.
append
(
"am"
)
for
visitor
in
visitors
:
if
want_am
:
cls
.
_add_method
(
cls
.
_test_perms
,
src
,
tgt
,
visitor
,
am
=
"dd_nu"
)
else
:
cls
.
_add_method
(
cls
.
_test_perms
,
src
,
tgt
,
visitor
)
@
classmethod
@
classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
super
(
TestProcessShow
,
cls
).
setUpClass
()
super
(
TestProcessShow
,
cls
).
setUpClass
()
cls
.
persons
.
create
(
"app"
,
status
=
const
.
STATUS_DC
)
cls
.
processes
.
create
(
"app"
,
person
=
cls
.
persons
.
app
,
applying_for
=
const
.
STATUS_DD_U
,
fd_comment
=
"test"
)
cls
.
persons
.
create
(
"am"
,
status
=
const
.
STATUS_DD_NU
)
cls
.
ams
.
create
(
"am"
,
person
=
cls
.
persons
.
am
)
cls
.
visitor
=
cls
.
persons
.
dc
cls
.
page_elements
=
PageElements
()
cls
.
page_elements
=
PageElements
()
cls
.
page_elements
.
add_id
(
"view_fd_comment"
)
cls
.
page_elements
.
add_id
(
"view_fd_comment"
)
cls
.
page_elements
.
add_id
(
"view_mbox"
)
cls
.
page_elements
.
add_id
(
"view_mbox"
)
...
@@ -39,10 +35,11 @@ class TestProcessShow(ProcessFixtureMixin, TestCase):
...
@@ -39,10 +35,11 @@ class TestProcessShow(ProcessFixtureMixin, TestCase):
cls
.
page_elements
.
add_id
(
"proc_approve"
)
cls
.
page_elements
.
add_id
(
"proc_approve"
)
cls
.
page_elements
.
add_id
(
"proc_unapprove"
)
cls
.
page_elements
.
add_id
(
"proc_unapprove"
)
def
assertPageElements
(
self
,
response
,
visit_perms
):
def
assertPageElements
(
self
,
response
):
# Check page elements based on visit_perms
# Check page elements based on visit_perms
visit_perms
=
self
.
processes
.
app
.
permissions_of
(
self
.
visitor
)
wanted
=
[]
wanted
=
[]
if
visit_perms
.
visitor
and
visit_perms
.
visitor
.
is_admin
:
if
"fd_comment"
in
visit_perms
:
wanted
.
append
(
"view_fd_comment"
)
wanted
.
append
(
"view_fd_comment"
)
if
"add_log"
in
visit_perms
:
if
"add_log"
in
visit_perms
:
wanted
+=
[
"log_public"
,
"log_private"
]
wanted
+=
[
"log_public"
,
"log_private"
]
...
@@ -50,24 +47,44 @@ class TestProcessShow(ProcessFixtureMixin, TestCase):
...
@@ -50,24 +47,44 @@ class TestProcessShow(ProcessFixtureMixin, TestCase):
if
el
in
visit_perms
:
wanted
.
append
(
el
)
if
el
in
visit_perms
:
wanted
.
append
(
el
)
self
.
assertContainsElements
(
response
,
self
.
page_elements
,
*
wanted
)
self
.
assertContainsElements
(
response
,
self
.
page_elements
,
*
wanted
)
def
_test_perms
(
self
,
src
,
tgt
,
visitor
,
am
=
None
):
def
tryVisitingWithPerms
(
self
,
perms
):
self
.
persons
.
create
(
"app"
,
status
=
src
)
client
=
self
.
make_test_client
(
self
.
visitor
)
self
.
processes
.
create
(
"app"
,
person
=
self
.
persons
.
app
,
applying_for
=
tgt
,
fd_comment
=
"test"
)
with
patch
.
object
(
pmodels
.
Process
,
"permissions_of"
,
return_value
=
perms
):
if
am
is
not
None
:
response
=
client
.
get
(
self
.
processes
.
app
.
get_absolute_url
())
self
.
persons
.
create
(
"am"
,
status
=
am
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
ams
.
create
(
"am"
,
person
=
self
.
persons
.
am
)
self
.
assertPageElements
(
response
)
def
test_none
(
self
):
self
.
tryVisitingWithPerms
(
set
())
pmodels
.
AMAssignment
.
objects
.
create
(
process
=
self
.
processes
.
app
,
am
=
self
.
ams
.
am
,
assigned_by
=
self
.
persons
[
"fd"
],
assigned_time
=
now
())
self
.
tryVisitingWithPerms
(
set
())
client
=
self
.
make_test_client
(
visitor
)
def
test_add_log
(
self
):
response
=
client
.
get
(
reverse
(
"process_show"
,
args
=
[
self
.
processes
.
app
.
pk
]))
self
.
tryVisitingWithPerms
(
set
([
"add_log"
]))
self
.
assertEqual
(
response
.
status_code
,
200
)
pmodels
.
AMAssignment
.
objects
.
create
(
process
=
self
.
processes
.
app
,
am
=
self
.
ams
.
am
,
assigned_by
=
self
.
persons
[
"fd"
],
assigned_time
=
now
())
visit_perms
=
self
.
processes
.
app
.
permissions_of
(
self
.
persons
[
visitor
])
self
.
tryVisitingWithPerms
(
set
([
"add_log"
]))
self
.
assertPageElements
(
response
,
visit_perms
)
# Assign am and repeat visit
def
test_view_mbox
(
self
):
if
am
:
self
.
tryVisitingWithPerms
(
set
([
"view_mbox"
]))
pmodels
.
AMAssignment
.
objects
.
create
(
process
=
self
.
processes
.
app
,
am
=
self
.
ams
.
am
,
assigned_by
=
self
.
persons
[
"fd"
],
assigned_time
=
now
())
pmodels
.
AMAssignment
.
objects
.
create
(
process
=
self
.
processes
.
app
,
am
=
self
.
ams
.
am
,
assigned_by
=
self
.
persons
[
"fd"
],
assigned_time
=
now
())
self
.
tryVisitingWithPerms
(
set
([
"view_mbox"
]))
response
=
client
.
get
(
reverse
(
"process_show"
,
args
=
[
self
.
processes
.
app
.
pk
]))
def
test_proc_freeze
(
self
):
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
tryVisitingWithPerms
(
set
([
"proc_freeze"
]))
visit_perms
=
self
.
processes
.
app
.
permissions_of
(
self
.
persons
[
visitor
])
pmodels
.
AMAssignment
.
objects
.
create
(
process
=
self
.
processes
.
app
,
am
=
self
.
ams
.
am
,
assigned_by
=
self
.
persons
[
"fd"
],
assigned_time
=
now
())
self
.
assertPageElements
(
response
,
visit_perms
)
self
.
tryVisitingWithPerms
(
set
([
"proc_freeze"
]))
def
test_proc_unfreeze
(
self
):
self
.
tryVisitingWithPerms
(
set
([
"proc_unfreeze"
]))
pmodels
.
AMAssignment
.
objects
.
create
(
process
=
self
.
processes
.
app
,
am
=
self
.
ams
.
am
,
assigned_by
=
self
.
persons
[
"fd"
],
assigned_time
=
now
())
self
.
tryVisitingWithPerms
(
set
([
"proc_unfreeze"
]))
def
test_proc_approve
(
self
):
self
.
tryVisitingWithPerms
(
set
([
"proc_approve"
]))
pmodels
.
AMAssignment
.
objects
.
create
(
process
=
self
.
processes
.
app
,
am
=
self
.
ams
.
am
,
assigned_by
=
self
.
persons
[
"fd"
],
assigned_time
=
now
())
self
.
tryVisitingWithPerms
(
set
([
"proc_approve"
]))
def
test_proc_unapprove
(
self
):
self
.
tryVisitingWithPerms
(
set
([
"proc_unapprove"
]))
pmodels
.
AMAssignment
.
objects
.
create
(
process
=
self
.
processes
.
app
,
am
=
self
.
ams
.
am
,
assigned_by
=
self
.
persons
[
"fd"
],
assigned_time
=
now
())
self
.
tryVisitingWithPerms
(
set
([
"proc_unapprove"
]))
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