Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3c43a38d
authored
Jul 23, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add AclUpdateView tests
parent
72464340
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
0 deletions
+74
-0
circle/dashboard/tests/test_mockedviews.py
+74
-0
No files found.
circle/dashboard/tests/test_mockedviews.py
View file @
3c43a38d
...
...
@@ -30,6 +30,7 @@ from django.utils import baseconv
from
..models
import
Profile
from
..views
import
InstanceActivityDetail
,
InstanceActivity
from
..views
import
vm_ops
,
Instance
,
UnsubscribeFormView
from
..views
import
AclUpdateView
from
..
import
views
...
...
@@ -429,6 +430,79 @@ class RenewViewTest(unittest.TestCase):
view
.
as_view
()(
request
,
pk
=
1234
)[
'location'
])
class
AclUpdateViewTest
(
unittest
.
TestCase
):
def
test_has_next_level
(
self
):
data
=
{
None
:
'user'
,
'user'
:
'operator'
,
'operator'
:
'owner'
,
'owner'
:
'owner'
}
for
k
,
v
in
data
.
items
():
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
has_level
.
return_value
=
True
inst
.
ACL_LEVELS
=
Instance
.
ACL_LEVELS
self
.
assertTrue
(
AclUpdateView
.
has_next_level
(
'dummy'
,
inst
,
k
))
inst
.
has_level
.
assert_called_with
(
'dummy'
,
v
)
def
test_set_level_mod_owner
(
self
):
with
patch
(
'dashboard.views.messages'
)
as
msg
:
request
=
FakeRequestFactory
(
POST
=
{})
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
owner
=
request
.
user
v
=
AclUpdateView
()
v
.
instance
=
inst
v
.
request
=
request
v
.
get_level
=
MagicMock
(
return_value
=
'owner'
)
v
.
check_auth
=
MagicMock
(
side_effect
=
Exception
(
''
))
v
.
set_level
(
request
.
user
,
'user'
)
v
.
get_level
.
assert_called_with
(
request
.
user
)
assert
not
v
.
check_auth
.
called
assert
msg
.
warning
.
called
def
test_set_level_permitted
(
self
):
data
=
((
'user'
,
'owner'
,
(
'user'
,
'operator'
,
'owner'
),
False
),
(
None
,
None
,
(
'user'
,
),
True
),
(
'user'
,
None
,
(
'user'
,
),
True
),
(
None
,
'user'
,
(
'user'
,
),
True
),
(
'operator'
,
'owner'
,
(
'user'
,
'operator'
),
True
),
(
None
,
'user'
,
(
'user'
,
'operator'
),
False
))
for
old_level
,
new_level
,
allowed_levels
,
fail
in
data
:
with
patch
(
'dashboard.views.messages'
)
as
msg
:
def
has_level
(
user
,
level
):
return
level
in
allowed_levels
request
=
FakeRequestFactory
(
POST
=
{})
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
has_level
.
side_effect
=
has_level
inst
.
ACL_LEVELS
=
Instance
.
ACL_LEVELS
v
=
AclUpdateView
()
v
.
instance
=
inst
v
.
request
=
request
v
.
is_owner
=
True
v
.
get_level
=
MagicMock
(
return_value
=
old_level
)
v
.
set_level
(
request
.
user
,
new_level
)
v
.
get_level
.
assert_called_with
(
request
.
user
)
assert
(
new_level
==
old_level
)
^
inst
.
has_level
.
called
assert
fail
^
inst
.
set_level
.
called
assert
fail
^
msg
.
success
.
called
def
test_readd
(
self
):
request
=
FakeRequestFactory
(
POST
=
{
'name'
:
'user0'
,
'level'
:
'user'
})
with
patch
(
'dashboard.views.messages'
)
as
msg
:
with
patch
.
object
(
AclUpdateView
,
'get_object'
)
as
go
:
view
=
AclUpdateView
.
as_view
()
inst
=
MagicMock
(
spec
=
Instance
)
go
.
return_value
=
inst
view
(
request
)
assert
msg
.
warning
.
called
def
FakeRequestFactory
(
user
=
None
,
**
kwargs
):
''' FakeRequestFactory, FakeMessages and FakeRequestContext are good for
mocking out django views; they are MUCH faster than the Django test client.
...
...
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