Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
980c92b1
authored
Mar 08, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add test for Template.raw_data (issue
#94
)
fixes
#94
parent
05e64bb7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
circle/dashboard/forms.py
+4
-5
circle/dashboard/tests/test_views.py
+22
-0
No files found.
circle/dashboard/forms.py
View file @
980c92b1
...
...
@@ -487,15 +487,14 @@ class TemplateForm(forms.ModelForm):
return
User
.
objects
.
get
(
pk
=
self
.
instance
.
owner
.
pk
)
return
self
.
user
def
clean
(
self
):
cleaned_data
=
self
.
cleaned_data
def
clean_raw_data
(
self
):
# if raw_data has changed and the user is not superuser
if
"raw_data"
in
self
.
changed_data
and
not
self
.
user
.
is_superuser
:
old_raw_data
=
InstanceTemplate
.
objects
.
get
(
pk
=
self
.
instance
.
pk
)
.
raw_data
cleaned_data
[
'raw_data'
]
=
old_raw_data
return
cleaned_data
return
old_raw_data
else
:
return
self
.
cleaned_data
[
'raw_data'
]
def
save
(
self
,
commit
=
True
):
data
=
self
.
cleaned_data
...
...
circle/dashboard/tests/test_views.py
View file @
980c92b1
...
...
@@ -190,6 +190,28 @@ class VmDetailTest(LoginMixin, TestCase):
response
=
c
.
post
(
'/dashboard/template/1/'
,
{})
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_edit_unpermitted_template_raw_data
(
self
):
c
=
Client
()
self
.
login
(
c
,
'user1'
)
tmpl
=
InstanceTemplate
.
objects
.
get
(
id
=
1
)
tmpl
.
set_level
(
self
.
u1
,
'owner'
)
tmpl
.
disks
.
get
()
.
set_level
(
self
.
u1
,
'owner'
)
kwargs
=
tmpl
.
__dict__
.
copy
()
kwargs
.
update
(
name
=
't1'
,
lease
=
1
,
disks
=
1
,
raw_data
=
'tst1'
)
response
=
c
.
post
(
'/dashboard/template/1/'
,
kwargs
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
InstanceTemplate
.
objects
.
get
(
id
=
1
)
.
raw_data
,
tmpl
.
raw_data
)
def
test_edit_permitted_template_raw_data
(
self
):
c
=
Client
()
self
.
login
(
c
,
'superuser'
)
kwargs
=
InstanceTemplate
.
objects
.
get
(
id
=
1
)
.
__dict__
.
copy
()
kwargs
.
update
(
name
=
't2'
,
lease
=
1
,
disks
=
1
,
raw_data
=
'tst2'
)
response
=
c
.
post
(
'/dashboard/template/1/'
,
kwargs
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
InstanceTemplate
.
objects
.
get
(
id
=
1
)
.
raw_data
,
'tst2'
)
def
test_permitted_lease_delete
(
self
):
c
=
Client
()
self
.
login
(
c
,
'superuser'
)
...
...
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