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
Commit
0922e15c
authored
Mar 05, 2015
by
Csók Tamás
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
solved countless issues and made tests more reliable
parent
d27ab5b9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
327 additions
and
199 deletions
+327
-199
circle/dashboard/tests/selenium/test_vm_controlls.py
+327
-199
No files found.
circle/dashboard/tests/selenium/test_vm_controlls.py
View file @
0922e15c
...
@@ -23,16 +23,18 @@ import urlparse
...
@@ -23,16 +23,18 @@ import urlparse
import
re
import
re
import
time
import
time
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support
import
expected_conditions
as
EC
from
selenium.webdriver.support
import
expected_conditions
as
ec
from
selenium.webdriver.support.select
import
Select
from
selenium.webdriver.support.select
import
Select
from
selenium.webdriver.common.by
import
By
from
selenium.webdriver.common.by
import
By
from
datetime
import
datetime
from
datetime
import
datetime
from
selenium.common.exceptions
import
NoSuchElementException
random_pass
=
""
.
join
([
random
.
choice
(
random_pass
=
""
.
join
([
random
.
choice
(
'0123456789abcdefghijklmnopqrstvwxyz'
)
for
n
in
xrange
(
10
)])
'0123456789abcdefghijklmnopqrstvwxyz'
)
for
n
in
xrange
(
10
)])
random_accents
=
random_pass
+
""
.
join
([
random
.
choice
(
random_accents
=
random_pass
+
""
.
join
([
random
.
choice
(
u"áéíöóúűÁÉÍÖÓÜÚŰ"
)
for
n
in
xrange
(
5
)])
u"áéíöóúűÁÉÍÖÓÜÚŰ"
)
for
n
in
xrange
(
5
)])
wait_max_sec
=
10
wait_max_sec
=
10
host
=
'https:127.0.0.1'
host
=
'https:127.0.0.1'
client_name
=
'test_
%
s'
%
random_accents
class
UtilityMixin
(
object
):
class
UtilityMixin
(
object
):
...
@@ -67,7 +69,7 @@ class UtilityMixin(object):
...
@@ -67,7 +69,7 @@ class UtilityMixin(object):
# If selenium runs only in a small (virtual) screen
# If selenium runs only in a small (virtual) screen
driver
.
find_element_by_class_name
(
'navbar-toggle'
)
.
click
()
driver
.
find_element_by_class_name
(
'navbar-toggle'
)
.
click
()
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
element_to_be_clickable
((
ec
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
By
.
CSS_SELECTOR
,
"a[href*='/dashboard/profile/']"
)))
"a[href*='/dashboard/profile/']"
)))
except
:
except
:
...
@@ -89,6 +91,11 @@ class UtilityMixin(object):
...
@@ -89,6 +91,11 @@ class UtilityMixin(object):
'Selenium cannot list the select possibilities'
)
'Selenium cannot list the select possibilities'
)
def
select_option
(
self
,
select
,
what
=
None
):
def
select_option
(
self
,
select
,
what
=
None
):
"""
From an HTML select imput type try to choose the specified one.
Select is a selenium web element type. What represent both the
text of the option and it's ID.
"""
try
:
try
:
my_choice
=
None
my_choice
=
None
options
=
self
.
list_options
(
select
)
options
=
self
.
list_options
(
select
)
...
@@ -141,7 +148,7 @@ class UtilityMixin(object):
...
@@ -141,7 +148,7 @@ class UtilityMixin(object):
Fires a click event via javascript injection.
Fires a click event via javascript injection.
"""
"""
try
:
try
:
#
Javascript function to simulate a click on a link
# Javascript function to simulate a click on a link
javascript
=
(
javascript
=
(
"var link = arguments[0];"
"var link = arguments[0];"
"var cancelled = false;"
"var cancelled = false;"
...
@@ -156,16 +163,20 @@ class UtilityMixin(object):
...
@@ -156,16 +163,20 @@ class UtilityMixin(object):
"} if (!cancelled) {"
"} if (!cancelled) {"
" window.location = link.href;"
" window.location = link.href;"
"}"
)
"}"
)
self
.
driver
.
execute_script
(
"
%
s"
%
javascript
,
link
)
self
.
driver
.
execute_script
(
javascript
,
link
)
except
:
except
:
raise
Exception
(
raise
Exception
(
'Selenium cannot inject javascript to the page'
)
'Selenium cannot inject javascript to the page'
)
def
wait_and_accept_operation
(
self
,
argument
=
None
):
def
wait_and_accept_operation
(
self
,
argument
=
None
):
# try:
"""
Accepts the operation confirmation pop up window.
Fills out the text inputs before accepting if argument is given.
"""
try
:
accept
=
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
accept
=
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
element_to_be_clickable
((
ec
.
element_to_be_clickable
((
By
.
ID
,
"op-form-send
"
)))
By
.
CLASS_NAME
,
"modal-accept
"
)))
if
argument
is
not
None
:
if
argument
is
not
None
:
possible
=
self
.
driver
.
find_elements_by_css_selector
(
possible
=
self
.
driver
.
find_elements_by_css_selector
(
"div.controls > input[type='text']"
)
"div.controls > input[type='text']"
)
...
@@ -178,17 +189,52 @@ class UtilityMixin(object):
...
@@ -178,17 +189,52 @@ class UtilityMixin(object):
form
.
clear
()
form
.
clear
()
form
.
send_keys
(
argument
)
form
.
send_keys
(
argument
)
accept
.
click
()
accept
.
click
()
# except:
except
:
# raise Exception("Selenium cannot accept the"
raise
Exception
(
"Selenium cannot accept the"
# " operation confirmation")
" operation confirmation"
)
def
save_template_from_vm
(
self
,
name
):
try
:
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
ec
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
"a[href$='/op/deploy/']"
)))
self
.
click_on_link
(
self
.
get_link_by_href
(
"/op/deploy/"
))
self
.
wait_and_accept_operation
()
recent_deploy
=
self
.
recently
(
self
.
get_timeline_elements
(
"vm.Instance.deploy"
))
if
not
self
.
check_operation_result
(
recent_deploy
):
print
(
"Selenium cannot deploy the "
"chosen template virtual machine"
)
raise
Exception
(
'Cannot deploy the virtual machine'
)
self
.
click_on_link
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
ec
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
"a[href$='/op/shut_off/']"
))))
self
.
wait_and_accept_operation
()
recent_shut_off
=
self
.
recently
(
self
.
get_timeline_elements
(
"vm.Instance.shut_off"
))
if
not
self
.
check_operation_result
(
recent_shut_off
):
print
(
"Selenium cannot shut off the "
"chosen template virtual machine"
)
raise
Exception
(
'Cannot shut off the virtual machine'
)
self
.
click_on_link
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
ec
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
"a[href$='/op/save_as_template/']"
))))
self
.
wait_and_accept_operation
(
name
)
return
name
except
:
raise
Exception
(
'Selenium cannot save a vm as a template'
)
def
create_base_template
(
self
,
name
=
None
,
architecture
=
"x86-64"
,
def
create_base_template
(
self
,
name
=
None
,
architecture
=
"x86-64"
,
method
=
None
,
op_system
=
None
,
lease
=
None
,
method
=
None
,
op_system
=
None
,
lease
=
None
,
network
=
"vm"
):
network
=
"vm"
):
if
name
is
None
:
if
name
is
None
:
name
=
"template_
%
s"
%
random_accents
name
=
"template_
new_
%
s"
%
client_name
if
op_system
is
None
:
if
op_system
is
None
:
op_system
=
"!os
%
s"
%
random_accents
op_system
=
"!os
%
s"
%
client_name
try
:
try
:
self
.
driver
.
get
(
'
%
s/dashboard/template/choose/'
%
host
)
self
.
driver
.
get
(
'
%
s/dashboard/template/choose/'
%
host
)
self
.
driver
.
find_element_by_css_selector
(
self
.
driver
.
find_element_by_css_selector
(
...
@@ -196,7 +242,7 @@ class UtilityMixin(object):
...
@@ -196,7 +242,7 @@ class UtilityMixin(object):
self
.
driver
.
find_element_by_id
(
self
.
driver
.
find_element_by_id
(
"template-choose-next-button"
)
.
click
()
"template-choose-next-button"
)
.
click
()
template_name
=
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
template_name
=
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
visibility_of_element_located
((
ec
.
visibility_of_element_located
((
By
.
ID
,
'id_name'
)))
By
.
ID
,
'id_name'
)))
template_name
.
clear
()
template_name
.
clear
()
template_name
.
send_keys
(
name
)
template_name
.
send_keys
(
name
)
...
@@ -213,37 +259,53 @@ class UtilityMixin(object):
...
@@ -213,37 +259,53 @@ class UtilityMixin(object):
"id_networks"
),
network
)
"id_networks"
),
network
)
self
.
driver
.
find_element_by_css_selector
(
self
.
driver
.
find_element_by_css_selector
(
"input.btn[type='submit']"
)
.
click
()
"input.btn[type='submit']"
)
.
click
()
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
return
self
.
save_template_from_vm
(
name
)
EC
.
visibility_of_element_located
((
By
.
ID
,
'ops'
)))
self
.
click_on_link
(
self
.
get_link_by_href
(
'/op/deploy/'
))
self
.
wait_and_accept_operation
()
self
.
click_on_link
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
"a[href$='/op/shut_off/']"
))))
self
.
wait_and_accept_operation
()
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
"a[href$='/op/deploy/']"
)))
self
.
click_on_link
(
self
.
get_link_by_href
(
'/op/save_as_template/'
))
self
.
wait_and_accept_operation
(
name
)
return
name
except
:
except
:
raise
Exception
(
raise
Exception
(
'Selenium cannot create a base template virtual machine'
)
'Selenium cannot create a base template virtual machine'
)
def
get_template_id
(
self
,
name
=
None
):
def
get_template_id
(
self
,
name
=
None
,
from_all
=
False
):
"""
In default settings find all templates ID in the template list.
If name is specified searches that specific template's ID
from_all sets whether to use owned templates or all of them
Returns list of the templates ID
"""
try
:
try
:
self
.
driver
.
get
(
'
%
s/dashboard/template/list/'
%
host
)
self
.
driver
.
get
(
'
%
s/dashboard/template/list/'
%
host
)
templates
=
self
.
driver
.
find_elements_by_css_selector
(
"td.name"
)
css_selector_of_a_template
=
(
"a[data-original-title]"
"[href*='/dashboard/template/']"
)
if
from_all
:
self
.
select_option
(
self
.
driver
.
find_element_by_id
(
'id_stype'
),
"all"
)
self
.
driver
.
find_element_by_css_selector
(
"button[type='submit']"
)
.
click
()
try
:
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
ec
.
presence_of_element_located
((
By
.
CSS_SELECTOR
,
css_selector_of_a_template
)))
except
:
print
"Selenium could not locate any templates"
template_table
=
self
.
driver
.
find_element_by_css_selector
(
"table[class*='template-list-table']"
)
templates
=
template_table
.
find_elements_by_css_selector
(
"td.name"
)
found_template_ids
=
[]
found_template_ids
=
[]
for
template
in
templates
:
for
template
in
templates
:
if
name
in
template
.
text
or
name
is
None
:
if
name
is
None
or
name
in
template
.
text
:
template_link
=
template
.
find_element_by_css_selector
(
try
:
"a[data-original-title]"
)
template_link
=
template
.
find_element_by_css_selector
(
found_template_ids
.
append
(
css_selector_of_a_template
)
re
.
search
(
r'\d+'
,
template_link
.
get_attribute
(
template_id
=
re
.
search
(
'innerHTML'
))
.
group
())
r'\d+'
,
template_link
.
get_attribute
(
"outerHTML"
))
.
group
()
found_template_ids
.
append
(
template_id
)
print
(
"Found '
%(name)
s' template's ID as
%(id)
s"
%
{
'name'
:
template
.
text
,
'id'
:
template_id
})
except
NoSuchElementException
:
pass
except
:
raise
if
not
found_template_ids
and
name
is
not
None
:
if
not
found_template_ids
and
name
is
not
None
:
print
(
"Selenium could not find the specified "
print
(
"Selenium could not find the specified "
"
%(name)
s template in the list"
%
{
"
%(name)
s template in the list"
%
{
...
@@ -253,20 +315,39 @@ class UtilityMixin(object):
...
@@ -253,20 +315,39 @@ class UtilityMixin(object):
raise
Exception
(
raise
Exception
(
'Selenium cannot found the template
\'
s id'
)
'Selenium cannot found the template
\'
s id'
)
def
check_operation_result
(
self
,
operation_id
):
def
check_operation_result
(
self
,
operation_id
,
restore
=
True
):
"""
Returns wheter the operation_id result is success (returns: boolean)
"""
try
:
try
:
url_save
=
self
.
driver
.
current_url
if
restore
:
url_base
=
urlparse
.
urlparse
(
self
.
driver
.
current_url
)
url_save
=
(
"
%(host)
s
%(url)
s"
%
{
'host'
:
host
,
'url'
:
urlparse
.
urljoin
(
url_base
.
path
,
url_base
.
query
)})
if
url_base
.
fragment
:
url_save
=
(
"
%(url)
s#
%(fragment)
s"
%
{
'url'
:
url_save
,
'fragment'
:
url_base
.
fragment
})
self
.
driver
.
get
(
'
%(host)
s/dashboard/vm/activity/
%(id)
s/'
%
{
self
.
driver
.
get
(
'
%(host)
s/dashboard/vm/activity/
%(id)
s/'
%
{
'host'
:
host
,
'host'
:
host
,
'id'
:
operation_id
})
'id'
:
operation_id
})
result
=
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
result
=
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
visibility_of_element_located
((
ec
.
visibility_of_element_located
((
By
.
ID
,
"activity_status"
)))
By
.
ID
,
"activity_status"
)))
print
(
"
%(id)
s result text is '
%(result)
s'"
%
{
'id'
:
operation_id
,
'result'
:
result
.
text
})
if
(
result
.
text
==
"success"
):
if
(
result
.
text
==
"success"
):
out
=
True
out
=
True
elif
(
result
.
text
==
"wait"
):
time
.
sleep
(
2
)
out
=
self
.
check_operation_result
(
operation_id
,
False
)
else
:
else
:
out
=
False
out
=
False
self
.
driver
.
get
(
url_save
)
if
restore
:
print
"Restoring to
%
s url"
%
url_save
self
.
driver
.
get
(
url_save
)
return
out
return
out
except
:
except
:
raise
Exception
(
raise
Exception
(
...
@@ -284,15 +365,24 @@ class UtilityMixin(object):
...
@@ -284,15 +365,24 @@ class UtilityMixin(object):
raise
Exception
(
raise
Exception
(
'Selenium cannot filter timeline activities to recent'
)
'Selenium cannot filter timeline activities to recent'
)
def
get_timeline_elements
(
self
,
code
):
def
get_timeline_elements
(
self
,
code
=
None
):
try
:
try
:
self
.
get_link_by_href
(
"#activity"
)
.
click
()
if
code
is
None
:
css_activity_selector
=
"div[data-activity-code]"
code
=
"all activity"
else
:
css_activity_selector
=
(
"div[data-activity-code="
"'
%(code)
s']"
%
{
'code'
:
code
})
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
ec
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
"a[href*='#activity']"
)))
.
click
()
activity_dict
=
{}
activity_dict
=
{}
timeline
=
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
timeline
=
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
visibility_of_element_located
((
ec
.
visibility_of_element_located
((
By
.
ID
,
"activity-timeline"
)))
By
.
ID
,
"activity-timeline"
)))
searched_activity
=
timeline
.
find_elements_by_css_selector
(
searched_activity
=
timeline
.
find_elements_by_css_selector
(
"div[data-activity-code='
%
s']"
%
code
)
css_activity_selector
)
print
"Found activity list for
%
s:"
%
code
print
"Found activity list for
%
s:"
%
code
for
activity
in
searched_activity
:
for
activity
in
searched_activity
:
activity_id
=
activity
.
get_attribute
(
'data-activity-id'
)
activity_id
=
activity
.
get_attribute
(
'data-activity-id'
)
...
@@ -310,7 +400,7 @@ class UtilityMixin(object):
...
@@ -310,7 +400,7 @@ class UtilityMixin(object):
def
create_template_from_base
(
self
,
delete_disk
=
True
,
name
=
None
):
def
create_template_from_base
(
self
,
delete_disk
=
True
,
name
=
None
):
try
:
try
:
if
name
is
None
:
if
name
is
None
:
name
=
"template_from_base_
%
s"
%
random_accents
name
=
"template_from_base_
%
s"
%
client_name
self
.
driver
.
get
(
'
%
s/dashboard/template/choose/'
%
host
)
self
.
driver
.
get
(
'
%
s/dashboard/template/choose/'
%
host
)
choice_list
=
[]
choice_list
=
[]
choices
=
self
.
driver
.
find_elements_by_css_selector
(
choices
=
self
.
driver
.
find_elements_by_css_selector
(
...
@@ -326,7 +416,7 @@ class UtilityMixin(object):
...
@@ -326,7 +416,7 @@ class UtilityMixin(object):
self
.
click_on_link
(
self
.
click_on_link
(
self
.
get_link_by_href
(
"#resources"
))
self
.
get_link_by_href
(
"#resources"
))
disks
=
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
disks
=
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
visibility_of_element_located
((
ec
.
visibility_of_element_located
((
By
.
ID
,
'vm-details-resources-disk'
)))
By
.
ID
,
'vm-details-resources-disk'
)))
disk_list
=
disks
.
find_elements_by_css_selector
(
disk_list
=
disks
.
find_elements_by_css_selector
(
"h4[class*='list-group-item-heading']"
)
"h4[class*='list-group-item-heading']"
)
...
@@ -335,7 +425,7 @@ class UtilityMixin(object):
...
@@ -335,7 +425,7 @@ class UtilityMixin(object):
self
.
get_link_by_href
(
"/op/remove_disk/"
))
self
.
get_link_by_href
(
"/op/remove_disk/"
))
self
.
wait_and_accept_operation
()
self
.
wait_and_accept_operation
()
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
visibility_of_element_located
((
ec
.
visibility_of_element_located
((
By
.
ID
,
"_activity"
)))
By
.
ID
,
"_activity"
)))
recent_remove_disk
=
self
.
recently
(
recent_remove_disk
=
self
.
recently
(
self
.
get_timeline_elements
(
self
.
get_timeline_elements
(
...
@@ -344,49 +434,20 @@ class UtilityMixin(object):
...
@@ -344,49 +434,20 @@ class UtilityMixin(object):
print
(
"Selenium cannot delete disk "
print
(
"Selenium cannot delete disk "
"of the chosen template"
)
"of the chosen template"
)
raise
Exception
(
'Cannot delete disk'
)
raise
Exception
(
'Cannot delete disk'
)
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
return
self
.
save_template_from_vm
(
name
)
EC
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
"a[href$='/op/deploy/']"
)))
self
.
click_on_link
(
self
.
get_link_by_href
(
"/op/deploy/"
))
self
.
wait_and_accept_operation
()
time
.
sleep
(
5
)
recent_deploy
=
self
.
recently
(
self
.
get_timeline_elements
(
"vm.Instance.deploy"
))
if
not
self
.
check_operation_result
(
recent_deploy
):
print
(
"Selenium cannot deploy the "
"chosen template virtual machine"
)
raise
Exception
(
'Cannot deploy the virtual machine'
)
self
.
click_on_link
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
"a[href$='/op/shut_off/']"
))))
self
.
wait_and_accept_operation
()
time
.
sleep
(
2
)
recent_shut_off
=
self
.
recently
(
self
.
get_timeline_elements
(
"vm.Instance.shut_off"
))
if
not
self
.
check_operation_result
(
recent_shut_off
):
print
(
"Selenium cannot shut off the "
"chosen template virtual machine"
)
raise
Exception
(
'Cannot shut off the virtual machine'
)
self
.
click_on_link
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
"a[href$='/op/save_as_template/']"
))))
self
.
wait_and_accept_operation
(
name
)
return
name
except
:
except
:
raise
Exception
(
'Selenium cannot start a template from a base one'
)
raise
Exception
(
'Selenium cannot start a template from a base one'
)
def
delete_template
(
self
,
template_id
):
def
delete_template
(
self
,
template_id
):
try
:
try
:
self
.
driver
.
get
(
'
%
s/dashboard/template/
%
s/'
%
(
host
,
template_id
))
self
.
driver
.
get
(
'
%
s/dashboard/template/
%
s/'
%
(
host
,
template_id
))
url
=
urlparse
.
urlparse
(
self
.
driver
.
current_url
)
self
.
click_on_link
(
self
.
click_on_link
(
self
.
get_link_by_href
(
self
.
get_link_by_href
(
"/dashboard/template/delete/
%
s/"
%
template_id
))
"/dashboard/template/delete/
%
s/"
%
template_id
))
self
.
wait_and_accept_operation
()
self
.
wait_and_accept_operation
()
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
visibility_of_element_located
((
ec
.
visibility_of_element_located
((
By
.
CLASS_NAME
,
'alert-success'
)))
By
.
CLASS_NAME
,
'alert-success'
)))
url
=
urlparse
.
urlparse
(
self
.
driver
.
current_url
)
url
=
urlparse
.
urlparse
(
self
.
driver
.
current_url
)
if
"/template/list/"
not
in
url
.
path
:
if
"/template/list/"
not
in
url
.
path
:
...
@@ -404,10 +465,10 @@ class UtilityMixin(object):
...
@@ -404,10 +465,10 @@ class UtilityMixin(object):
choice
=
random
.
randint
(
0
,
len
(
vm_list
)
-
1
)
choice
=
random
.
randint
(
0
,
len
(
vm_list
)
-
1
)
vm_list
[
choice
]
.
click
()
vm_list
[
choice
]
.
click
()
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
element_to_be_clickable
((
ec
.
element_to_be_clickable
((
By
.
CLASS_NAME
,
'vm-create-start'
)))
.
click
()
By
.
CLASS_NAME
,
'vm-create-start'
)))
.
click
()
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
EC
.
visibility_of_element_located
((
ec
.
visibility_of_element_located
((
By
.
CLASS_NAME
,
'alert-success'
)))
By
.
CLASS_NAME
,
'alert-success'
)))
url
=
urlparse
.
urlparse
(
self
.
driver
.
current_url
)
url
=
urlparse
.
urlparse
(
self
.
driver
.
current_url
)
pk
=
re
.
search
(
r'\d+'
,
url
.
path
)
.
group
()
pk
=
re
.
search
(
r'\d+'
,
url
.
path
)
.
group
()
...
@@ -415,7 +476,7 @@ class UtilityMixin(object):
...
@@ -415,7 +476,7 @@ class UtilityMixin(object):
except
:
except
:
raise
Exception
(
'Selenium cannot start a VM'
)
raise
Exception
(
'Selenium cannot start a VM'
)
def
view
C
hange
(
self
,
target_box
):
def
view
_c
hange
(
self
,
target_box
):
driver
=
self
.
driver
driver
=
self
.
driver
driver
.
get
(
'
%
s/dashboard/'
%
host
)
driver
.
get
(
'
%
s/dashboard/'
%
host
)
list_view
=
driver
.
find_element_by_id
(
'
%
s-list-view'
%
target_box
)
list_view
=
driver
.
find_element_by_id
(
'
%
s-list-view'
%
target_box
)
...
@@ -429,39 +490,59 @@ class UtilityMixin(object):
...
@@ -429,39 +490,59 @@ class UtilityMixin(object):
'#index-list-view'
,
'#index-list-view'
,
required_attributes
)
.
find_element_by_tag_name
(
'i'
)
required_attributes
)
.
find_element_by_tag_name
(
'i'
)
self
.
click_on_link
(
list_view_link
)
self
.
click_on_link
(
list_view_link
)
states
=
[
driver
.
execute_script
(
"
%
s"
%
js_script
,
list_view
),
states
=
[
driver
.
execute_script
(
js_script
,
list_view
),
driver
.
execute_script
(
"
%
s"
%
js_script
,
graph_view
)]
driver
.
execute_script
(
js_script
,
graph_view
)]
self
.
click_on_link
(
graph_view_link
)
self
.
click_on_link
(
graph_view_link
)
states
.
extend
([
driver
.
execute_script
(
"
%
s"
%
js_script
,
list_view
),
states
.
extend
([
driver
.
execute_script
(
js_script
,
list_view
),
driver
.
execute_script
(
"
%
s"
%
js_script
,
graph_view
)])
driver
.
execute_script
(
js_script
,
graph_view
)])
self
.
click_on_link
(
list_view_link
)
self
.
click_on_link
(
list_view_link
)
states
.
extend
([
driver
.
execute_script
(
"
%
s"
%
js_script
,
list_view
),
states
.
extend
([
driver
.
execute_script
(
js_script
,
list_view
),
driver
.
execute_script
(
"
%
s"
%
js_script
,
graph_view
)])
driver
.
execute_script
(
js_script
,
graph_view
)])
return
states
return
states
def
delete_vm
(
self
,
pk
):
def
delete_vm
(
self
,
pk
):
try
:
try
:
driver
=
self
.
driver
# For relability reasons instead of using the JS operatation
driver
.
get
(
'
%
s/dashboard/vm/
%
s/'
%
(
host
,
pk
))
self
.
driver
.
get
(
"
%(host)
s/dashboard/vm/
%(id)
s/op/destroy/"
%
{
status_span
=
driver
.
find_element_by_id
(
'vm-details-state'
)
'host'
:
host
,
self
.
get_link_by_href
(
'id'
:
pk
})
"/dashboard/vm/
%
s/op/destroy/"
%
pk
)
.
click
()
self
.
wait_and_accept_operation
()
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
try
:
EC
.
element_to_be_clickable
((
By
.
ID
,
'op-form-send'
)))
.
click
()
status_span
=
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
WebDriverWait
(
status_span
,
wait_max_sec
)
.
until
(
ec
.
visibility_of_element_located
((
EC
.
visibility_of_element_located
((
By
.
ID
,
'vm-details-state'
)))
By
.
CLASS_NAME
,
'fa-trash-o'
)))
WebDriverWait
(
status_span
,
wait_max_sec
)
.
until
(
return
True
ec
.
visibility_of_element_located
((
By
.
CLASS_NAME
,
'fa-trash-o'
)))
except
:
# Selenium can time-out by not realising the JS refresh
recent_destroy_vm
=
self
.
recently
(
self
.
get_timeline_elements
(
"vm.Instance.destroy"
))
if
not
self
.
check_operation_result
(
recent_destroy_vm
):
print
(
"Selenium cannot destroy "
"the chosen
%(id)
s vm"
%
{
'id'
:
pk
})
raise
Exception
(
'Cannot destroy the specified vm'
)
self
.
driver
.
get
(
'
%
s/dashboard/vm/
%
s/'
%
(
host
,
pk
))
try
:
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
ec
.
visibility_of_element_located
((
By
.
CSS_SELECTOR
,
"span[data-status*='DESTROYED']"
)))
return
True
except
:
return
False
except
:
except
:
raise
Exception
(
"Selenium can not destroy a VM"
)
raise
Exception
(
"Selenium can not destroy a VM"
)
class
VmDetailTest
(
UtilityMixin
,
SeleniumTestCase
):
class
VmDetailTest
(
UtilityMixin
,
SeleniumTestCase
):
template_ids
=
[]
template_ids
=
[]
vm_ids
=
[]
@classmethod
@classmethod
def
setup_class
(
cls
):
def
setup_class
(
cls
):
cls
.
_user
=
User
.
objects
.
create
(
username
=
'test_
%
s'
%
random_accents
,
cls
.
_user
=
User
.
objects
.
create
(
username
=
client_name
,
is_superuser
=
True
)
is_superuser
=
True
)
cls
.
_user
.
set_password
(
random_accents
)
cls
.
_user
.
set_password
(
random_accents
)
cls
.
_user
.
save
()
cls
.
_user
.
save
()
...
@@ -470,50 +551,85 @@ class VmDetailTest(UtilityMixin, SeleniumTestCase):
...
@@ -470,50 +551,85 @@ class VmDetailTest(UtilityMixin, SeleniumTestCase):
def
teardown_class
(
cls
):
def
teardown_class
(
cls
):
cls
.
_user
.
delete
()
cls
.
_user
.
delete
()
# def test_01_login(self):
def
test_01_login
(
self
):
# title = 'Dashboard | CIRCLE'
title
=
'Dashboard | CIRCLE'
# location = '/dashboard/'
location
=
'/dashboard/'
# self.login('test_%s' % random_accents, random_accents)
self
.
login
(
client_name
,
random_accents
)
# self.driver.get('%s/dashboard/' % host)
self
.
driver
.
get
(
'
%
s/dashboard/'
%
host
)
# url = urlparse.urlparse(self.driver.current_url)
url
=
urlparse
.
urlparse
(
self
.
driver
.
current_url
)
# (self.assertIn('%s' % title, self.driver.title,
(
self
.
assertIn
(
'
%
s'
%
title
,
self
.
driver
.
title
,
# '%s is not found in the title' % title) or
'
%
s is not found in the title'
%
title
)
or
# self.assertEqual(url.path, '%s' % location,
self
.
assertEqual
(
url
.
path
,
'
%
s'
%
location
,
# 'URL path is not equal with %s' % location))
'URL path is not equal with
%
s'
%
location
))
# def test_02_able_to_create_template(self):
def
test_02_add_template_rights
(
self
):
# self.login('test_%s' % random_accents, random_accents)
self
.
login
(
client_name
,
random_accents
)
# template_list = None
template_pool
=
self
.
get_template_id
(
from_all
=
True
)
# create_template = self.get_link_by_href('/dashboard/template/choose/')
if
len
(
template_pool
)
>
1
:
# self.click_on_link(create_template)
chosen
=
template_pool
[
random
.
randint
(
0
,
len
(
template_pool
)
-
1
)]
# WebDriverWait(self.driver, wait_max_sec).until(
elif
len
(
template_pool
)
==
1
:
# EC.visibility_of_element_located((
chosen
=
template_pool
[
0
]
# By.ID, 'create-modal')))
else
:
# template_list = self.driver.find_elements_by_class_name(
print
"Selenium did not found any templates"
# 'template-choose-list-element')
raise
Exception
(
# print 'Selenium found %s template possibilities' % len(template_list)
"System did not meet required conditions to continue"
)
# (self.assertIsNotNone(
self
.
driver
.
get
(
'
%
s/dashboard/template/
%
s/'
%
(
host
,
chosen
))
# template_list, "Selenium can not find the create template list") or
acces_form
=
self
.
driver
.
find_element_by_css_selector
(
# self.assertGreater(len(template_list), 0,
"form[action*='/dashboard/template/
%(template_id)
s/acl/']"
# "The create template list is empty"))
"[method='post']"
%
{
'template_id'
:
chosen
})
# def test_03_create_base_template(self):
user_name
=
acces_form
.
find_element_by_css_selector
(
# self.login('test_%s' % random_accents, random_accents)
"input[type='text'][id='id_name']"
)
# template_name = self.create_base_template()
user_status
=
acces_form
.
find_element_by_css_selector
(
# self.driver.get('%s/dashboard/template/list/' % host)
"select[name='level']"
)
# templates = self.driver.find_elements_by_css_selector("td.name")
user_name
.
clear
()
# found = False
user_name
.
send_keys
(
client_name
)
# for template in templates:
self
.
select_option
(
user_status
)
# if template_name in template.text:
acces_form
.
find_element_by_css_selector
(
# found = True
"button[type='submit']"
)
.
click
()
# self.template_ids.append(
found_users
=
[]
# re.search(r'\d+', template.text).group())
acl_users
=
self
.
driver
.
find_elements_by_css_selector
(
# self.assertTrue(
"a[href*='/dashboard/profile/']"
)
# found,
for
user
in
acl_users
:
# "Coud not found the created template in the template list")
user_text
=
re
.
split
(
r':[ ]?'
,
user
.
text
)
if
len
(
user_text
)
==
2
:
def
test_04_create_template_from_base
(
self
):
found_name
=
re
.
search
(
r'[\w\W]+(?=\))'
,
user_text
[
1
])
.
group
()
self
.
login
(
'test_
%
s'
%
random_accents
,
random_accents
)
print
(
"'
%(user)
s' found in ACL list for template
%(id)
s"
%
{
'user'
:
found_name
,
'id'
:
chosen
})
found_users
.
append
(
found_name
)
self
.
assertIn
(
client_name
,
found_users
,
"Could not add user to template's ACL"
)
def
test_03_able_to_create_template
(
self
):
self
.
login
(
client_name
,
random_accents
)
template_list
=
None
create_template
=
self
.
get_link_by_href
(
'/dashboard/template/choose/'
)
self
.
click_on_link
(
create_template
)
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
ec
.
visibility_of_element_located
((
By
.
ID
,
'confirmation-modal'
)))
template_list
=
self
.
driver
.
find_elements_by_class_name
(
'template-choose-list-element'
)
print
'Selenium found
%
s template possibilities'
%
len
(
template_list
)
(
self
.
assertIsNotNone
(
template_list
,
"Selenium can not find the create template list"
)
or
self
.
assertGreater
(
len
(
template_list
),
0
,
"The create template list is empty"
))
def
test_04_create_base_template
(
self
):
self
.
login
(
client_name
,
random_accents
)
created_template_id
=
self
.
get_template_id
(
self
.
create_base_template
())
found
=
created_template_id
is
not
None
if
found
:
self
.
template_ids
.
extend
(
created_template_id
)
self
.
assertTrue
(
found
,
"Coud not found the created template in the template list"
)
def
test_05_create_template_from_base
(
self
):
self
.
login
(
client_name
,
random_accents
)
created_template_id
=
self
.
get_template_id
(
created_template_id
=
self
.
get_template_id
(
self
.
create_template_from_base
())
self
.
create_template_from_base
())
found
=
created_template_id
is
not
None
found
=
created_template_id
is
not
None
...
@@ -523,63 +639,75 @@ class VmDetailTest(UtilityMixin, SeleniumTestCase):
...
@@ -523,63 +639,75 @@ class VmDetailTest(UtilityMixin, SeleniumTestCase):
found
,
found
,
"Coud not found the created template in the template list"
)
"Coud not found the created template in the template list"
)
def
test_05_delete_templates
(
self
):
def
test_06_delete_templates
(
self
):
self
.
login
(
'test_
%
s'
%
random_accents
,
random_accents
)
success
=
False
self
.
login
(
client_name
,
random_accents
)
for
template_id
in
self
.
template_ids
:
for
template_id
in
self
.
template_ids
:
print
"Deleting template
%
s"
%
template_id
self
.
delete_template
(
template_id
)
self
.
delete_template
(
template_id
)
existing_templates
=
self
.
get_template_id
()
existing_templates
=
self
.
get_template_id
()
if
len
(
existing_templates
)
==
0
:
success
=
True
else
:
for
template_id
in
self
.
template_ids
:
for
template_id
in
self
.
template_ids
:
if
template_id
not
in
existing_templates
:
if
template_id
not
in
existing_templates
:
self
.
template_ids
.
remove
(
template_id
)
self
.
template_ids
.
remove
(
template_id
)
self
.
assertListEqual
([],
self
.
template_ids
,
if
len
(
self
.
template_ids
)
==
0
:
"Could not delete (all) the test template(s)"
)
success
=
True
self
.
assertTrue
(
success
,
"Could not delete (all) the test template(s)"
)
# def test_10_able_to_create_vm(self):
# self.login('test_%s' % random_accents, random_accents)
def
test_07_able_to_create_vm
(
self
):
# vm_list = None
self
.
login
(
client_name
,
random_accents
)
# create_vm_link = self.get_link_by_href('/dashboard/vm/create/')
vm_list
=
None
# create_vm_link.click()
create_vm_link
=
self
.
get_link_by_href
(
'/dashboard/vm/create/'
)
# WebDriverWait(self.driver, wait_max_sec).until(
create_vm_link
.
click
()
# EC.visibility_of_element_located((
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
# By.ID, 'create-modal')))
ec
.
visibility_of_element_located
((
# vm_list = self.driver.find_elements_by_class_name(
By
.
ID
,
'confirmation-modal'
)))
# 'vm-create-template-summary')
vm_list
=
self
.
driver
.
find_elements_by_class_name
(
# print ("Selenium found %(vm_number)s virtual machine template "
'vm-create-template-summary'
)
# " possibilities" % {
print
(
"Selenium found
%(vm_number)
s virtual machine template "
# 'vm_number': len(vm_list)})
" possibilities"
%
{
# (self.assertIsNotNone(
'vm_number'
:
len
(
vm_list
)})
# vm_list, "Selenium can not find the VM list") or
(
self
.
assertIsNotNone
(
# self.assertGreater(len(vm_list), 0, "The create VM list is empty"))
vm_list
,
"Selenium can not find the VM list"
)
or
self
.
assertGreater
(
len
(
vm_list
),
0
,
"The create VM list is empty"
))
# def test_11_create_vm(self):
# self.login('test_%s' % random_accents, random_accents)
def
test_08_create_vm
(
self
):
# pk = self.create_random_vm()
self
.
login
(
client_name
,
random_accents
)
# self.assertIsNotNone(pk, "Can not create a VM")
pk
=
self
.
create_random_vm
()
self
.
vm_ids
.
append
(
pk
)
# def test_12_vm_view_change(self):
self
.
assertIsNotNone
(
pk
,
"Can not create a VM"
)
# self.login('test_%s' % random_accents, random_accents)
# expected_states = ["", "none",
def
test_09_vm_view_change
(
self
):
# "none", "",
self
.
login
(
client_name
,
random_accents
)
# "block", "none"]
expected_states
=
[
""
,
"none"
,
# states = self.viewChange("vm")
"none"
,
""
,
# print 'states: [%s]' % ', '.join(map(str, states))
"block"
,
"none"
]
# print 'expected: [%s]' % ', '.join(map(str, expected_states))
states
=
self
.
view_change
(
"vm"
)
# self.assertListEqual(states, expected_states,
print
'states: [
%
s]'
%
', '
.
join
(
map
(
str
,
states
))
# "The view mode does not change for VM listing")
print
'expected: [
%
s]'
%
', '
.
join
(
map
(
str
,
expected_states
))
self
.
assertListEqual
(
states
,
expected_states
,
# def test_13_node_view_change(self):
"The view mode does not change for VM listing"
)
# self.login('test_%s' % random_accents, random_accents)
# expected_states = ["", "none",
def
test_10_node_view_change
(
self
):
# "none", "",
self
.
login
(
client_name
,
random_accents
)
# "block", "none"]
expected_states
=
[
""
,
"none"
,
# states = self.viewChange("node")
"none"
,
""
,
# print 'states: [%s]' % ', '.join(map(str, states))
"block"
,
"none"
]
# print 'expected: [%s]' % ', '.join(map(str, expected_states))
states
=
self
.
view_change
(
"node"
)
# self.assertListEqual(states, expected_states,
print
'states: [
%
s]'
%
', '
.
join
(
map
(
str
,
states
))
# "The view mode does not change for NODE listing")
print
'expected: [
%
s]'
%
', '
.
join
(
map
(
str
,
expected_states
))
self
.
assertListEqual
(
states
,
expected_states
,
# def test_14_delete_vm(self):
"The view mode does not change for NODE listing"
)
# self.login('test_%s' % random_accents, random_accents)
# pk = self.create_random_vm()
def
test_11_delete_vm
(
self
):
# self.assertTrue(self.delete_vm(pk), "Can not delete a VM")
self
.
login
(
client_name
,
random_accents
)
succes
=
True
for
vm
in
self
.
vm_ids
:
if
not
self
.
delete_vm
(
vm
):
succes
=
False
else
:
self
.
vm_ids
.
remove
(
vm
)
self
.
assertTrue
(
succes
,
"Can not delete all VM"
)
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