<reponame>robertstarmer/aurora
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
from random import randint
import unittest
from qa.web_tests import config
import time

class TestEditTenantQuotes(unittest.TestCase):
    
    def setUp(self):
        self.base_url = config.base_url
        self.verificationErrors = []
        self.accept_next_alert = True
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(config.implicitly_wait)
    
    def test_edit_tenant_quotes(self):
        driver = self.driver
        driver.maximize_window()
        driver.get(self.base_url + "/")
        driver.find_element_by_name("username").send_keys(config.username)
        driver.find_element_by_name("password").send_keys(<PASSWORD>)
        driver.find_element_by_css_selector("input.loginSubmit").click()
        Move = ActionChains(driver).move_to_element(driver.find_element_by_link_text("Settings"))
        Move.perform()
        driver.find_element_by_link_text("Tenants").click()
        driver.find_element_by_xpath("//tr[td[text()='openstack']]/td/a").click()
        driver.find_element_by_link_text("Edit Tenant").click()
        driver.find_element_by_link_text("Edit Quotas").click()
        driver.find_element_by_xpath("//tr[td[text()=' Cores']]/td/input").clear()
        core_quota_value = str(randint(11, 99))
        driver.find_element_by_xpath("//tr[td[text()=' Cores']]/td/input").send_keys("%s" % core_quota_value)
        driver.find_element_by_name("_action_saveQuotas").click()
        driver.find_element_by_link_text("Edit Quotas").click()
        #Move = ActionChains(driver).move_to_element(driver.find_element_by_link_text("Settings"))
        #Move.perform()
        #driver.find_element_by_link_text("Quotas").click()
        self.assertTrue(driver.find_element_by_xpath(
            '//*[@id="quota-cores"]/../input[@value="%s"]' % core_quota_value))
        
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True
    
    def tearDown(self):
        self.driver.save_screenshot(config.screen_path)
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()
