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
e374c9ba
authored
Apr 02, 2014
by
Oláh István Gergely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: test set node status, cleanup: remove nodedetails set status
parent
308052b3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
39 deletions
+47
-39
circle/dashboard/templates/dashboard/confirm/ajax-node-status.html
+1
-1
circle/dashboard/tests/test_views.py
+46
-14
circle/dashboard/views.py
+0
-24
No files found.
circle/dashboard/templates/dashboard/confirm/ajax-node-status.html
View file @
e374c9ba
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
{%endblocktrans%}
{%endblocktrans%}
{% endif %}
{% endif %}
<div
class=
"pull-right"
>
<div
class=
"pull-right"
>
<form
action=
"
"
method=
"POST"
>
<form
action=
"{% url "
dashboard
.
views
.
status-node
"
pk=
object.pk
%}
"
method=
"POST"
>
{% csrf_token %}
{% csrf_token %}
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
{% trans "Cancel" %}
</button>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
{% trans "Cancel" %}
</button>
<input
type=
"hidden"
name=
"change_status"
value=
""
/>
<input
type=
"hidden"
name=
"change_status"
value=
""
/>
...
...
circle/dashboard/tests/test_views.py
View file @
e374c9ba
...
@@ -595,8 +595,7 @@ class NodeDetailTest(LoginMixin, TestCase):
...
@@ -595,8 +595,7 @@ class NodeDetailTest(LoginMixin, TestCase):
def
test_anon_node_page
(
self
):
def
test_anon_node_page
(
self
):
c
=
Client
()
c
=
Client
()
response
=
c
.
get
(
'/dashboard/node/1/'
)
response
=
c
.
get
(
'/dashboard/node/1/'
)
self
.
assertRedirects
(
response
,
'/accounts/login/'
self
.
assertEqual
(
response
.
status_code
,
302
)
'?next=/dashboard/node/1/'
)
def
test_permitted_node_delete
(
self
):
def
test_permitted_node_delete
(
self
):
c
=
Client
()
c
=
Client
()
...
@@ -608,14 +607,12 @@ class NodeDetailTest(LoginMixin, TestCase):
...
@@ -608,14 +607,12 @@ class NodeDetailTest(LoginMixin, TestCase):
c
=
Client
()
c
=
Client
()
self
.
login
(
c
,
'user1'
)
self
.
login
(
c
,
'user1'
)
response
=
c
.
post
(
'/dashboard/node/delete/1/'
)
response
=
c
.
post
(
'/dashboard/node/delete/1/'
)
self
.
assertRedirects
(
response
,
'/accounts/login/'
self
.
assertEqual
(
response
.
status_code
,
302
)
'?next=/dashboard/node/delete/1/'
)
def
test_anon_node_delete
(
self
):
def
test_anon_node_delete
(
self
):
c
=
Client
()
c
=
Client
()
response
=
c
.
post
(
'/dashboard/node/delete/1/'
)
response
=
c
.
post
(
'/dashboard/node/delete/1/'
)
self
.
assertRedirects
(
response
,
'/accounts/login/'
self
.
assertEqual
(
response
.
status_code
,
302
)
'?next=/dashboard/node/delete/1/'
)
def
test_unpermitted_set_name
(
self
):
def
test_unpermitted_set_name
(
self
):
c
=
Client
()
c
=
Client
()
...
@@ -658,8 +655,7 @@ class NodeDetailTest(LoginMixin, TestCase):
...
@@ -658,8 +655,7 @@ class NodeDetailTest(LoginMixin, TestCase):
trait_count
=
node
.
traits
.
count
()
trait_count
=
node
.
traits
.
count
()
response
=
c
.
post
(
"/dashboard/node/1/add-trait/"
,
response
=
c
.
post
(
"/dashboard/node/1/add-trait/"
,
{
'name'
:
'test1'
})
{
'name'
:
'test1'
})
self
.
assertRedirects
(
response
,
'/accounts/login/'
self
.
assertEqual
(
response
.
status_code
,
302
)
'?next=/dashboard/node/1/add-trait/'
)
self
.
assertEqual
(
len
(
Node
.
objects
.
get
(
pk
=
1
)
.
traits
.
all
()),
trait_count
)
self
.
assertEqual
(
len
(
Node
.
objects
.
get
(
pk
=
1
)
.
traits
.
all
()),
trait_count
)
def
test_anon_add_trait
(
self
):
def
test_anon_add_trait
(
self
):
...
@@ -668,8 +664,7 @@ class NodeDetailTest(LoginMixin, TestCase):
...
@@ -668,8 +664,7 @@ class NodeDetailTest(LoginMixin, TestCase):
trait_count
=
node
.
traits
.
count
()
trait_count
=
node
.
traits
.
count
()
response
=
c
.
post
(
"/dashboard/node/1/add-trait/"
,
response
=
c
.
post
(
"/dashboard/node/1/add-trait/"
,
{
'name'
:
'test2'
})
{
'name'
:
'test2'
})
self
.
assertRedirects
(
response
,
'/accounts/login/'
self
.
assertEqual
(
response
.
status_code
,
302
)
'?next=/dashboard/node/1/add-trait/'
)
self
.
assertEqual
(
len
(
Node
.
objects
.
get
(
pk
=
1
)
.
traits
.
all
()),
trait_count
)
self
.
assertEqual
(
len
(
Node
.
objects
.
get
(
pk
=
1
)
.
traits
.
all
()),
trait_count
)
def
test_permitted_add_trait
(
self
):
def
test_permitted_add_trait
(
self
):
...
@@ -679,7 +674,8 @@ class NodeDetailTest(LoginMixin, TestCase):
...
@@ -679,7 +674,8 @@ class NodeDetailTest(LoginMixin, TestCase):
trait_count
=
node
.
traits
.
count
()
trait_count
=
node
.
traits
.
count
()
response
=
c
.
post
(
"/dashboard/node/1/add-trait/"
,
{
'name'
:
'test3'
})
response
=
c
.
post
(
"/dashboard/node/1/add-trait/"
,
{
'name'
:
'test3'
})
self
.
assertRedirects
(
response
,
'/dashboard/node/1/'
)
self
.
assertRedirects
(
response
,
'/dashboard/node/1/'
)
self
.
assertEqual
(
node
.
traits
.
count
(),
trait_count
+
1
)
self
.
assertEqual
(
Node
.
objects
.
get
(
pk
=
1
)
.
traits
.
count
(),
trait_count
+
1
)
def
test_unpermitted_remove_trait
(
self
):
def
test_unpermitted_remove_trait
(
self
):
node
=
Node
.
objects
.
get
(
pk
=
1
)
node
=
Node
.
objects
.
get
(
pk
=
1
)
...
@@ -689,7 +685,7 @@ class NodeDetailTest(LoginMixin, TestCase):
...
@@ -689,7 +685,7 @@ class NodeDetailTest(LoginMixin, TestCase):
self
.
login
(
c
,
"user2"
)
self
.
login
(
c
,
"user2"
)
response
=
c
.
post
(
"/dashboard/node/1/"
,
{
'to_remove'
:
traitid
})
response
=
c
.
post
(
"/dashboard/node/1/"
,
{
'to_remove'
:
traitid
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
node
.
traits
.
count
(),
trait_count
)
self
.
assertEqual
(
Node
.
objects
.
get
(
pk
=
1
)
.
traits
.
count
(),
trait_count
)
def
test_permitted_remove_trait
(
self
):
def
test_permitted_remove_trait
(
self
):
node
=
Node
.
objects
.
get
(
pk
=
1
)
node
=
Node
.
objects
.
get
(
pk
=
1
)
...
@@ -699,7 +695,8 @@ class NodeDetailTest(LoginMixin, TestCase):
...
@@ -699,7 +695,8 @@ class NodeDetailTest(LoginMixin, TestCase):
self
.
login
(
c
,
"superuser"
)
self
.
login
(
c
,
"superuser"
)
response
=
c
.
post
(
"/dashboard/node/1/"
,
{
'to_remove'
:
traitid
})
response
=
c
.
post
(
"/dashboard/node/1/"
,
{
'to_remove'
:
traitid
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
node
.
traits
.
count
(),
trait_count
-
1
)
self
.
assertEqual
(
Node
.
objects
.
get
(
pk
=
1
)
.
traits
.
count
(),
trait_count
-
1
)
def
test_permitted_remove_trait_w_ajax
(
self
):
def
test_permitted_remove_trait_w_ajax
(
self
):
node
=
Node
.
objects
.
get
(
pk
=
1
)
node
=
Node
.
objects
.
get
(
pk
=
1
)
...
@@ -721,7 +718,42 @@ class NodeDetailTest(LoginMixin, TestCase):
...
@@ -721,7 +718,42 @@ class NodeDetailTest(LoginMixin, TestCase):
s
=
'x'
*
100
s
=
'x'
*
100
response
=
c
.
post
(
"/dashboard/node/1/add-trait/"
,
{
'name'
:
s
})
response
=
c
.
post
(
"/dashboard/node/1/add-trait/"
,
{
'name'
:
s
})
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
node
.
traits
.
count
(),
trait_count
)
self
.
assertEqual
(
Node
.
objects
.
get
(
pk
=
1
)
.
traits
.
count
(),
trait_count
)
def
test_anon_remove_trait
(
self
):
c
=
Client
()
node
=
Node
.
objects
.
get
(
pk
=
1
)
trait_count
=
node
.
traits
.
count
()
traitid
=
node
.
traits
.
get
(
name
=
'testtrait'
)
.
pk
response
=
c
.
post
(
"/dashboard/node/1/"
,
{
'to_remove'
:
traitid
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
len
(
Node
.
objects
.
get
(
pk
=
1
)
.
traits
.
all
()),
trait_count
)
def
test_anon_change_node_status
(
self
):
c
=
Client
()
node
=
Node
.
objects
.
get
(
pk
=
1
)
node_enabled
=
node
.
enabled
response
=
c
.
post
(
"/dashboard/node/1/"
,
{
'change_status'
:
''
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
node_enabled
,
Node
.
objects
.
get
(
pk
=
1
)
.
enabled
)
def
test_unpermitted_change_node_status
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
node
=
Node
.
objects
.
get
(
pk
=
1
)
node_enabled
=
node
.
enabled
response
=
c
.
post
(
"/dashboard/node/status/1/"
,
{
'change_status'
:
''
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
node_enabled
,
Node
.
objects
.
get
(
pk
=
1
)
.
enabled
)
def
test_permitted_change_node_status
(
self
):
c
=
Client
()
self
.
login
(
c
,
"superuser"
)
node
=
Node
.
objects
.
get
(
pk
=
1
)
node_enabled
=
node
.
enabled
response
=
c
.
post
(
"/dashboard/node/status/1/"
,
{
'change_status'
:
''
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
node_enabled
,
not
Node
.
objects
.
get
(
pk
=
1
)
.
enabled
)
class
VmDetailVncTest
(
LoginMixin
,
TestCase
):
class
VmDetailVncTest
(
LoginMixin
,
TestCase
):
...
...
circle/dashboard/views.py
View file @
e374c9ba
...
@@ -509,8 +509,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
...
@@ -509,8 +509,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
if
request
.
POST
.
get
(
'new_name'
):
if
request
.
POST
.
get
(
'new_name'
):
return
self
.
__set_name
(
request
)
return
self
.
__set_name
(
request
)
if
request
.
POST
.
get
(
'change_status'
)
is
not
None
:
return
self
.
__set_status
(
request
)
if
request
.
POST
.
get
(
'to_remove'
):
if
request
.
POST
.
get
(
'to_remove'
):
return
self
.
__remove_trait
(
request
)
return
self
.
__remove_trait
(
request
)
return
redirect
(
reverse_lazy
(
"dashboard.views.node-detail"
,
return
redirect
(
reverse_lazy
(
"dashboard.views.node-detail"
,
...
@@ -538,27 +536,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
...
@@ -538,27 +536,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return
redirect
(
reverse_lazy
(
"dashboard.views.node-detail"
,
return
redirect
(
reverse_lazy
(
"dashboard.views.node-detail"
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}))
kwargs
=
{
'pk'
:
self
.
object
.
pk
}))
def
__set_status
(
self
,
request
):
self
.
object
=
self
.
get_object
()
if
not
self
.
object
.
enabled
:
self
.
object
.
enable
(
user
=
request
.
user
)
else
:
self
.
object
.
disable
(
user
=
request
.
user
)
success_message
=
_
(
"Node successfully changed status!"
)
if
request
.
is_ajax
():
response
=
{
'message'
:
success_message
,
'node_pk'
:
self
.
object
.
pk
}
return
HttpResponse
(
json
.
dumps
(
response
),
content_type
=
"application/json"
)
else
:
messages
.
success
(
request
,
success_message
)
return
redirect
(
reverse_lazy
(
"dashboard.views.node-detail"
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}))
def
__remove_trait
(
self
,
request
):
def
__remove_trait
(
self
,
request
):
try
:
try
:
to_remove
=
request
.
POST
.
get
(
'to_remove'
)
to_remove
=
request
.
POST
.
get
(
'to_remove'
)
...
@@ -1419,7 +1396,6 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
...
@@ -1419,7 +1396,6 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
self
.
object
.
enable
(
user
=
request
.
user
)
self
.
object
.
enable
(
user
=
request
.
user
)
else
:
else
:
self
.
object
.
disable
(
user
=
request
.
user
)
self
.
object
.
disable
(
user
=
request
.
user
)
success_message
=
_
(
"Node successfully changed status!"
)
success_message
=
_
(
"Node successfully changed status!"
)
if
request
.
is_ajax
():
if
request
.
is_ajax
():
...
...
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