def readRolesTest(): try: role = tu.createRole("hello", "hey", [1, 2, 4, 5, 6, 9, 10, 17, 18]) inds = [8, 19, 21, 4, 15, 0, 11, 6, 17] iden = tu.createIdentity("billy", "bob") tu.assignRole(iden, role) except: print "Failed to set up read roles test" return False d = tu.newtest() wait = WebDriverWait(d, timeout=5, poll_frequency=0.2) try: tu.goUsers(d) tu.goRoles(d) time.sleep(2) wait.until(lambda x: len( x.find_elements_by_xpath("//input[@type='checkbox']")) > 22) checked = d.find_elements_by_xpath( "//input[@type='checkbox' and @value='on']") boxes = d.find_elements_by_xpath("//input[@type='checkbox']") for i in inds: box = d.find_elements_by_xpath("//input[@type='checkbox']")[(i * 2) + 1] if not box in checked: print "Permission {0} isn't checked".format(i) return False except Exception as e: print e print "Failed to access users/roles page" return False finally: tu.endtest(d) return True
def createRoleUserTest(driver): wait = WebDriverWait(driver, timeout=5, poll_frequency=0.2) try: tu.goUsers(driver) wait.until( lambda x: x.find_element_by_xpath("//div[text()='Create Role']")) driver.find_element_by_xpath("//div[text()='Create Role']").click() except: print "Failed to view 'Create Role' page" return False try: tu.createRoleUI(driver, "future", "future", [1, 4, 5, 7]) wait.until(lambda x: x.find_element_by_xpath( "//div[@class='cell center-text' and text()='future']")) except: print "Failed to create role 'future'" return False try: driver.find_element_by_xpath("//div[text()='Create User']").click() tu.createUser(driver, "morg", "morg", ["future"], []) wait.until(lambda x: x.find_element_by_xpath( "//div[@class='cell' and text()='morg']")) wait.until( lambda x: x.find_element_by_xpath("//span[text()='future']")) except: print "Failed to create user with role 'future'" return False return True
def writeumsTest(driver, role): wait = WebDriverWait(driver, timeout=5, poll_frequency=0.2) try: tu.goUsers(driver) tu.goRoles(driver) wait.until(lambda x: x.find_element_by_xpath( "//input[@data-roleid='{0}']".format(role))) except Exception as e: print e print "Failed to view role on roles page" return False try: boxes = driver.find_elements_by_xpath( "//input[@data-roleid='{0}']".format(role)) for b in boxes: b.click() driver.find_element_by_xpath( "//div[@class='role-permissions intro']/div[@class='button-primary']" ).click() changes = driver.find_elements_by_xpath( "//span[@class='button-primary']") for c in changes: c.click() driver.find_element_by_xpath( "//div[@class='button-primary' and text()='Save Changes']").click( ) time.sleep(19) perm = tu.getRolePermissions(role) if len(perm) != 25: print "Some permissions failed to update" return False driver.refresh() tu.goRoles(driver) wait.until(lambda x: x.find_element_by_xpath( "//input[@data-roleid='{0}']".format(role))) boxes = driver.find_elements_by_xpath( "//input[@data-roleid='{0}']".format(role)) for b in boxes: b.click() driver.find_element_by_xpath( "//div[@class='role-permissions intro']/div[@class='button-primary']" ).click() changes = driver.find_elements_by_xpath( "//span[@class='button-primary']") for c in changes: c.click() driver.find_element_by_xpath( "//div[@class='button-primary' and text()='Save Changes']").click( ) time.sleep(19) perm = tu.getRolePermissions(role) if len(perm) > 3: print "Failed to remove permissions" return False except Exception as e: print e print "Failed to modify role" return False return True
def createUserTest(driver): wait = WebDriverWait(driver, timeout=5, poll_frequency=0.2) try: tu.goUsers(driver) wait.until( lambda x: x.find_element_by_xpath("//div[text()='Create User']")) driver.find_element_by_xpath("//div[text()='Create User']").click() except: print "Couldn't click create user" return False try: tu.createUser(driver, "rach", "bobben", ["Superuser"], []) wait.until(lambda x: x.find_element_by_xpath( "//div[@class='cell' and text()='rach']")) except: print "Failed to create user through UI" return False return True
def createRoleTest(driver): wait = WebDriverWait(driver, timeout=5, poll_frequency=0.2) try: tu.goUsers(driver) wait.until( lambda x: x.find_element_by_xpath("//div[text()='Create Role']")) driver.find_element_by_xpath("//div[text()='Create Role']").click() except: print "Couldn't click create role" return False try: tu.createRoleUI(driver, "darole", "excellent", [1, 2, 3, 4]) wait.until(lambda x: x.find_element_by_xpath( "//div[@class='cell center-text' and text()='excellent']")) except Exception as e: print e print "Failed to create role through UI" return False return True
def readUsersTest(): d = tu.newtest() wait = WebDriverWait(d, timeout=5, poll_frequency=0.2) iden = [("joe", "shmoe"), ("jerry", "fairy"), ("Rick", "kimmy")] try: for i in iden: num = tu.createIdentity(i[0], i[1]) tu.assignRole(num, 1) except: print "Failed to create idnetities" return False try: tu.goUsers(d) for i in iden: wait.until(lambda x: x.find_element_by_xpath( "//div[@class='cell' and text()='{0}']".format(i[0]))) except: print "Users missing from users page" return False finally: tu.endtest(d) return True