Commit 1426611d by Csók Tamás

commit before update

parent 9d40ae4f
...@@ -26,6 +26,7 @@ from selenium.webdriver.support.ui import WebDriverWait ...@@ -26,6 +26,7 @@ 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
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(
...@@ -35,39 +36,44 @@ host = 'https:127.0.0.1' ...@@ -35,39 +36,44 @@ host = 'https:127.0.0.1'
class UtilityMixin(object): class UtilityMixin(object):
def login(self, username, password='password'): def login(self, username, password='password', location=None):
driver = self.driver driver = self.driver
driver.get('%s/accounts/login/' % host) if location is None:
try: location = '/dashboard/'
name_input = driver.find_element_by_id("id_username") driver.get('%s%s' % (host, location))
password_input = driver.find_element_by_id("id_password") # Only if we aren't logged in already
submit_input = driver.find_element_by_id("submit-id-submit") if location not in urlparse.urlparse(self.driver.current_url).path:
except:
inputs = driver.find_elements_by_tag_name("input")
for current_input in inputs:
input_type = current_input.get_attribute("type")
if input_type == "text":
name_input = current_input
if input_type == "password":
password_input = current_input
if input_type == "submit":
submit_input = current_input
try:
name_input.clear()
name_input.send_keys(username)
password_input.clear()
password_input.send_keys(password)
submit_input.click()
try: try:
# If selenium runs only in a small (virtual) screen name_input = driver.find_element_by_id("id_username")
driver.find_element_by_class_name('navbar-toggle').click() password_input = driver.find_element_by_id("id_password")
WebDriverWait(self.driver, wait_max_sec).until( submit_input = driver.find_element_by_id("submit-id-submit")
EC.element_to_be_clickable((
By.CSS_SELECTOR, "a[href*='/dashboard/profile/']")))
except: except:
time.sleep(0.5) inputs = driver.find_elements_by_tag_name("input")
except: for current_input in inputs:
raise Exception('Selenium cannot find the form controls') input_type = current_input.get_attribute("type")
if input_type == "text":
name_input = current_input
if input_type == "password":
password_input = current_input
if input_type == "submit":
submit_input = current_input
try:
name_input.clear()
name_input.send_keys(username)
password_input.clear()
password_input.send_keys(password)
submit_input.click()
try:
# If selenium runs only in a small (virtual) screen
driver.find_element_by_class_name('navbar-toggle').click()
WebDriverWait(self.driver, wait_max_sec).until(
EC.element_to_be_clickable((
By.CSS_SELECTOR,
"a[href*='/dashboard/profile/']")))
except:
time.sleep(0.5)
except:
raise Exception('Selenium cannot find the form controls')
def list_options(self, select): def list_options(self, select):
try: try:
...@@ -106,7 +112,7 @@ class UtilityMixin(object): ...@@ -106,7 +112,7 @@ class UtilityMixin(object):
select.select_by_value(my_choice) select.select_by_value(my_choice)
except: except:
raise Exception( raise Exception(
'Selenium cannot select the choosen one') 'Selenium cannot select the chosen one')
def get_link_by_href(self, target_href, attributes=None): def get_link_by_href(self, target_href, attributes=None):
try: try:
...@@ -187,9 +193,8 @@ class UtilityMixin(object): ...@@ -187,9 +193,8 @@ class UtilityMixin(object):
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(
"input[type='radio'][value='base_vm']").click() "input[type='radio'][value='base_vm']").click()
next_button = self.driver.find_element_by_id( self.driver.find_element_by_id(
"template-choose-next-button") "template-choose-next-button").click()
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')))
...@@ -227,6 +232,129 @@ class UtilityMixin(object): ...@@ -227,6 +232,129 @@ class UtilityMixin(object):
raise Exception( raise Exception(
'Selenium cannot create a base template virtual machine') 'Selenium cannot create a base template virtual machine')
def check_operation_result(self, operation_id):
try:
url_save = self.driver.current_url
self.driver.get('%(host)s/dashboard/vm/activity/%(id)s/' % {
'host': host,
'id': operation_id})
result = WebDriverWait(self.driver, wait_max_sec).until(
EC.visibility_of_element_located((
By.ID, "activity_status")))
if (result.text == "success"):
out = True
else:
out = False
self.driver.get(url_save)
return out
except:
raise Exception(
'Selenium cannot check the result of an operation')
def recently(self, timeline_dict, second=90):
try:
if isinstance(timeline_dict, dict):
for key, value in timeline_dict.iteritems():
time = datetime.strptime(key, '%Y-%m-%d %H:%M')
delta = datetime.now() - time
if delta.total_seconds() <= second:
return value
except:
raise Exception(
'Selenium cannot filter timeline activities to recent')
def get_timeline_elements(self, code):
try:
self.get_link_by_href("#activity").click()
activity_dict = {}
timeline = WebDriverWait(self.driver, wait_max_sec).until(
EC.visibility_of_element_located((
By.ID, "activity-timeline")))
searched_activity = timeline.find_elements_by_css_selector(
"div[data-activity-code='%s']" % code)
print "Found activity list for %s:" % code
for activity in searched_activity:
activity_id = activity.get_attribute('data-activity-id')
activity_text = activity.text
key = re.search(
r'\d+-\d+-\d+ \d+:\d+,', activity_text).group()[:-1]
print ("%(id)s @ %(activity)s" % {
'id': activity_id,
'activity': key})
activity_dict[key] = activity_id
return activity_dict
except:
raise Exception('Selenium cannot find the searched activity')
def create_template_from_base(self, delete_disk=True, name=None):
#try:
if name is None:
name = "template_from_base_%s" % random_accents
self.driver.get('%s/dashboard/template/choose/' % host)
choice_list = []
choices = self.driver.find_elements_by_css_selector(
"input[type='radio']")
choice_list = [item for item in choices if (
'test' not in item.get_attribute('value')
and item.get_attribute('value') != 'base_vm')]
chosen = random.randint(0, len(choice_list) - 1)
choice_list[chosen].click()
self.driver.find_element_by_id(
"template-choose-next-button").click()
if delete_disk:
self.get_link_by_href("#resources").click()
disks = WebDriverWait(self.driver, wait_max_sec).until(
EC.visibility_of_element_located((
By.ID, 'vm-details-resources-disk')))
disk_list = disks.find_elements_by_css_selector(
"h4[class*='list-group-item-heading']")
if len(disk_list) > 0:
self.get_link_by_href("/op/remove_disk/").click()
self.wait_and_accept_operation()
WebDriverWait(self.driver, wait_max_sec).until(
EC.visibility_of_element_located((
By.ID, "_activity")))
recent_remove_disk = self.recently(
self.get_timeline_elements(
"vm.Instance.remove_disk"))
if not self.check_operation_result(recent_remove_disk):
print ("Selenium cannot delete disk "
"of the chosen template")
raise Exception('Cannot delete disk')
WebDriverWait(self.driver, wait_max_sec).until(
EC.element_to_be_clickable((
By.CSS_SELECTOR,
"a[href$='/op/deploy/']")))
self.get_link_by_href("/op/deploy/").click()
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')
WebDriverWait(self.driver, wait_max_sec).until(
EC.element_to_be_clickable((
By.CSS_SELECTOR,
"a[href$='/op/shut_off/']"))).click()
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')
WebDriverWait(self.driver, wait_max_sec).until(
EC.element_to_be_clickable((
By.CSS_SELECTOR,
"a[href$='/op/save_as_template/']"))).click()
self.wait_and_accept_operation(name)
return name
#except:
# raise Exception('Selenium cannot start a template from a base one')
def create_random_vm(self): def create_random_vm(self):
try: try:
self.driver.get('%s/dashboard/vm/create/' % host) self.driver.get('%s/dashboard/vm/create/' % host)
...@@ -247,7 +375,7 @@ class UtilityMixin(object): ...@@ -247,7 +375,7 @@ class UtilityMixin(object):
pk = re.search(r'\d+', url.path).group() pk = re.search(r'\d+', url.path).group()
return pk return pk
except: except:
raise Exception('Selenium cannot start any VM') raise Exception('Selenium cannot start a VM')
def viewChange(self, target_box): def viewChange(self, target_box):
driver = self.driver driver = self.driver
...@@ -293,7 +421,7 @@ class UtilityMixin(object): ...@@ -293,7 +421,7 @@ class UtilityMixin(object):
class VmDetailTest(UtilityMixin, SeleniumTestCase): class VmDetailTest(UtilityMixin, SeleniumTestCase):
template_id = None template_ids = []
@classmethod @classmethod
def setup_class(cls): def setup_class(cls):
...@@ -306,92 +434,116 @@ class VmDetailTest(UtilityMixin, SeleniumTestCase): ...@@ -306,92 +434,116 @@ 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('test_%s' % random_accents, 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_able_to_create_template(self):
self.login('test_%s' % random_accents, random_accents) # self.login('test_%s' % random_accents, random_accents)
template_list = None # template_list = None
create_template = self.get_link_by_href('/dashboard/template/choose/') # create_template = self.get_link_by_href('/dashboard/template/choose/')
self.click_on_link(create_template) # self.click_on_link(create_template)
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, 'create-modal'))) # By.ID, 'create-modal')))
template_list = self.driver.find_elements_by_class_name( # template_list = self.driver.find_elements_by_class_name(
'template-choose-list-element') # 'template-choose-list-element')
print 'Selenium found %s template possibilities' % len(template_list) # print 'Selenium found %s template possibilities' % len(template_list)
(self.assertIsNotNone( # (self.assertIsNotNone(
template_list, "Selenium can not find the create template list") or # template_list, "Selenium can not find the create template list") or
self.assertGreater(len(template_list), 0, # self.assertGreater(len(template_list), 0,
"The create template list is empty")) # "The create template list is empty"))
# def test_03_create_base_template(self):
# self.login('test_%s' % random_accents, random_accents)
# template_name = self.create_base_template()
# self.driver.get('%s/dashboard/template/list/' % host)
# templates = self.driver.find_elements_by_css_selector("td.name")
# found = False
# for template in templates:
# if template_name in template.text:
# found = True
# self.template_ids.append(
# re.search(r'\d+', template.text).group())
# self.assertTrue(
# found,
# "Coud not found the created template in the template list")
def test_03_create_base_vm(self): def test_04_create_template_from_base(self):
self.login('test_%s' % random_accents, random_accents) self.login('test_%s' % random_accents, random_accents)
template_name = self.create_base_template() template_name = self.create_template_from_base()
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") templates = self.driver.find_elements_by_css_selector("td.name")
found = False found = False
for template in templates: for template in templates:
if template_name in template.text: if template_name in template.text:
found = True found = True
self.template_id = re.search(r'\d+', template.text).group() self.template_ids.append(
re.search(r'\d+', template.text).group())
self.assertTrue( self.assertTrue(
found, found,
"Coud not found the created template in the template list") "Coud not found the created template in the template list")
def test_10_able_to_create_vm(self): def test_05_delete_templates(self):
self.login('test_%s' % random_accents, random_accents) self.login('test_%s' % random_accents, random_accents)
vm_list = None for template_id in self.template_ids:
create_vm_link = self.get_link_by_href('/dashboard/vm/create/') # self.driver.get('%s/dashboard/template/%s/' % (host, template_id))
create_vm_link.click() pass
WebDriverWait(self.driver, wait_max_sec).until( assert False
EC.visibility_of_element_located((
By.ID, 'create-modal')))
vm_list = self.driver.find_elements_by_class_name(
'vm-create-template-summary')
print ("Selenium found %(vm_number)s virtual machine template "
" possibilities" % {
'vm_number': len(vm_list)})
(self.assertIsNotNone(
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)
pk = self.create_random_vm()
self.assertIsNotNone(pk, "Can not create a VM")
def test_12_vm_view_change(self): # def test_10_able_to_create_vm(self):
self.login('test_%s' % random_accents, random_accents) # self.login('test_%s' % random_accents, random_accents)
expected_states = ["", "none", # vm_list = None
"none", "", # create_vm_link = self.get_link_by_href('/dashboard/vm/create/')
"block", "none"] # create_vm_link.click()
states = self.viewChange("vm") # WebDriverWait(self.driver, wait_max_sec).until(
print 'states: [%s]' % ', '.join(map(str, states)) # EC.visibility_of_element_located((
print 'expected: [%s]' % ', '.join(map(str, expected_states)) # By.ID, 'create-modal')))
self.assertListEqual(states, expected_states, # vm_list = self.driver.find_elements_by_class_name(
"The view mode does not change for VM listing") # 'vm-create-template-summary')
# print ("Selenium found %(vm_number)s virtual machine template "
# " possibilities" % {
# 'vm_number': len(vm_list)})
# (self.assertIsNotNone(
# vm_list, "Selenium can not find the VM list") or
# self.assertGreater(len(vm_list), 0, "The create VM list is empty"))
def test_13_node_view_change(self): # def test_11_create_vm(self):
self.login('test_%s' % random_accents, random_accents) # self.login('test_%s' % random_accents, random_accents)
expected_states = ["", "none", # pk = self.create_random_vm()
"none", "", # self.assertIsNotNone(pk, "Can not create a VM")
"block", "none"]
states = self.viewChange("node")
print 'states: [%s]' % ', '.join(map(str, states))
print 'expected: [%s]' % ', '.join(map(str, expected_states))
self.assertListEqual(states, expected_states,
"The view mode does not change for NODE listing")
def test_14_delete_vm(self): # def test_12_vm_view_change(self):
self.login('test_%s' % random_accents, random_accents) # self.login('test_%s' % random_accents, random_accents)
pk = self.create_random_vm() # expected_states = ["", "none",
self.assertTrue(self.delete_vm(pk), "Can not delete a VM") # "none", "",
# "block", "none"]
# states = self.viewChange("vm")
# print 'states: [%s]' % ', '.join(map(str, states))
# print 'expected: [%s]' % ', '.join(map(str, expected_states))
# self.assertListEqual(states, expected_states,
# "The view mode does not change for VM listing")
# def test_13_node_view_change(self):
# self.login('test_%s' % random_accents, random_accents)
# expected_states = ["", "none",
# "none", "",
# "block", "none"]
# states = self.viewChange("node")
# print 'states: [%s]' % ', '.join(map(str, states))
# print 'expected: [%s]' % ', '.join(map(str, expected_states))
# self.assertListEqual(states, expected_states,
# "The view mode does not change for NODE listing")
# def test_14_delete_vm(self):
# self.login('test_%s' % random_accents, random_accents)
# pk = self.create_random_vm()
# self.assertTrue(self.delete_vm(pk), "Can not delete a VM")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment