def test2(): error.sink = sys.stdout passed = [] failed = [] test_count = 0 for test, prem, conc in test_cases.Core_or_BLD_PET_AST(): test_count += 1 print '\n\n\n\n\nTest %d: %s' % (test_count, test) pattern = query.from_conclusion(conc) try: prem2 = do_import.Plugin().transform(prem) except do_import.RDFLibParseError, e: error.notify(e) continue if prem is prem2: pass else: print "Did IMPORT processing" prem = prem2 try: result = run_query(prem, pattern, msg="From test "+test) except error.Error, e: error.notify(e) continue
def fetch_activation_link(username, password, mailalias = None): #username is name of the user to login to gmail account, password is real password, mailalias is alias name for account error.notify("Fetching user activation link from gmail server") mail = imaplib.IMAP4_SSL('imap.gmail.com') if (mailalias is None): mailalias = username mail.login(username, password) mail.select("inbox") result, data = mail.search(None,'(TO "%s" SUBJECT "Portal user email activation")' % (mailalias)) ids = data[0] # data is a list. id_list = ids.split() # ids is a space separated string latest_email_id = id_list[-1] # get the latest if (1): result, data = mail.fetch(latest_email_id, "(RFC822)") # fetch the email body (RFC822) for the given ID mail.store(latest_email_id, '+FLAGS', '\\Deleted') # delete this email soup = BeautifulSoup(data[0][1]) for link in soup.findAll('a'): l = link.get('href') if ('email_activation' in l): return l return None
def logout(driver): error.notify("logging off") try: driver.find_element_by_id('logout').click() driver.switch_to_alert().accept() driver.switch_to.window except: error.notify("I was not able to logout (could not find the button?)") return
def default_do(self, obj): if isinstance(obj, nodecentric.Instance): error.notify(error.NotImplemented("Not Implemented: " +obj.rdf_type.any.as_string)) self.out("not_implemented('%s')" % obj.rdf_type.any.as_string) else: error.notify(error.NotImplemented("Not Implemented (obj): "+ str(type(obj)))) self.out("not_implemented('%s')" % str(type(obj)))
def Core_or_BLD_PET_AST(): for test, prem, conc in Core_or_BLD_PET_filenames(): if test == "Unordered_Relations": # can't parse NAU's continue try: premise_node = load(prem) conclusion_node = load(conc) yield test, premise_node, conclusion_node except error.Error, e: error.notify(e)
def is_pi(driver, url, fakeuser, testname, errordb, datadb, concurrent_users, display = None): error.notify("Checking if user is PI", url, testname, errordb) signin_status = signin(driver, fakeuser['email'], fakeuser['password'], url, testname, errordb, datadb, concurrent_users, display) if not signin_status[0]: filename = error.save_error(signin_status[1], url, testname, driver, errordb) return (False, signin_status[1], filename) url += '/portal/user/'+fakeuser['email'] #page.load(driver, url, testname, errordb, datadb, "//*[contains(text(), 'User Account')]", 'xpath', concurrent_users) load_status = page.load(driver, url, testname, errordb, datadb, 'User Account', 'link_text', 'user_account_details', concurrent_users, display) if not load_status[0]: filename = error.save_error(load_status[1], url, testname, driver, errordb) return (False, load_status[1], filename) try: element = driver.find_element_by_link_text('User Account') error.notify("Found 'User Account'", url, testname, errordb) element.click() except: message = "[%s] TEST FAILED: could not find 'User Account' link for: %s" % (str(__name__)+'.is_pi', fakeuser['email']) filename = error.save_error(message, url, testname, driver, errordb) return (False, message, filename) try: #driver.find_element_by_xpath("//button[contains(@name,'dl_onelab.')]") driver.find_element_by_xpath("//button[contains(@oldtitle,'Download Authority Credentials')]") error.notify('User is PI', url, testname, errordb) return (True, True) except: error.notify("User is not PI", url, testname, errordb) return (True, False)
def delete_all_emails(username, password, mailalias = None): mail = imaplib.IMAP4_SSL('imap.gmail.com') if (mailalias is None): mailalias = username error.notify("Deleting all emails for user: %s" % (mailalias)) mail.login(username, password) mail.select("inbox") result, data = mail.search(None,'(TO "%s")' % mailalias ) ids = data[0] # data is a list. id_list = ids.split() # ids is a space separated string for item in id_list: mail.store(item, '+FLAGS', '\\Deleted') # delete this email
def read_solutions(stream): """ Read sets of atoms from the stream, one per line, with a blank line between each set. """ results = [] binding = [] for line in stream: line = line.strip() if line == "end marker": # could never appear in data unquoted results.append(binding) binding = [] else: binding.append(atom_unquote(line)) if binding: error.notify(error.SyntaxErrorFromSubprocess('no end marker')) return results
def create(driver, url, testname, fakeuser, organisation, errordb=None, datadb=None, users=1, display = None): error.notify("Running module: create user", url, testname, errordb) # load page url = url+'/register' load_status = page.load(driver, url, testname, errordb, datadb, 'terms and conditions.', 'link_text','create_user', users, display) if not load_status[0]: filename = error.save_error(load_status[1], url, testname, driver, errordb) return (False, load_status[1], filename) # delete all old emails for this alias gemail.delete_all_emails(fakeuser['trueemail'], fakeuser['password'], fakeuser['email']) # fil ou the registration form error.notify("Filling up user form on registration page", url, testname, errordb) try: firstname = driver.find_element_by_name("firstname") firstname.send_keys(fakeuser['firstname']) lastname = driver.find_element_by_name("lastname") lastname.send_keys(fakeuser['lastname']) email = driver.find_element_by_name("email") email.send_keys(fakeuser['email']) agreement = driver.find_element_by_name("agreement") agreement.click() password = driver.find_element_by_name("password") password.send_keys(fakeuser['password']) password = driver.find_element_by_name("confirmpassword") password.send_keys(fakeuser['password']) org = driver.find_element_by_class_name("ui-corner-right") org.click() organisation = "//li[text() = '"+organisation+"']" org = driver.find_element_by_xpath(organisation).click() time_now = datetime.now() password.submit() #error.notify("Submit user form on registration page", url, testname, errordb) except Exception, e: message = "[%s] TEST FAILED with error: I was not able to properly fill the form on: %s" % (str(__name__)+'.create', url) filename = error.save_error(message, url, testname, driver, errordb) return (False, message, filename)
def signin(driver, user, paswd, url, testname, errordb=None, datadb=None, users=1, display = None): # first load main page load_status = page.load(driver, url, testname, errordb, datadb, 'Can\'t access your account?', 'link_text','signin_page', users, display) if not load_status[0]: filename = error.save_error(load_status[1], url, testname, driver, errordb) return (False, load_status[1], filename) # fill up login form error.notify("Singining in user", url, testname, errordb) email = driver.find_element_by_name("username") email.send_keys(user) password = driver.find_element_by_name("password") password.send_keys(paswd) # ... and submit the form time_now = datetime.now() password.submit() # wait for resluts try: # waiting 20 seconds until user login and get information about his slice list driver.wait = ui.WebDriverWait(driver, 50) driver.wait.until(lambda driver: driver.find_elements_by_xpath("//*[contains(text(), 'Your projects and slices')]")) exec_time = datetime.now() - time_now except: driver.wait = ui.WebDriverWait(driver, 10) # check if login/password are correct if driver.wait.until(lambda driver: driver.find_element_by_xpath("//span[text() = 'Your username and/or password were incorrect.']")): message = "[%s] TEST FAILED with error: I was NOT able to signn-in: %s (User or/and password incorrect)" % (str(__name__)+'.signin', url) else: message = "[%s] TEST FAILED with error: I was NOT able to signn-in: %s (I was not able to see home-slice-list)" % (str(__name__)+'.signin', url) filename = error.save_error(load_status[1], url, testname, driver, errordb) return (False, load_status[1], filename) # save data into influx portal if datadb: influx.savedata("signin", exec_time.total_seconds(), datadb, url, testname, users) error.notify("Time to signin to portal %f [s]" % (exec_time.total_seconds()), url, testname, errordb) return (True, 'User %s signed in successfully' % user)
def run_query(kb, query, msg): """assert the document, then query for the pattern, returning all the sets of bindings.""" to_pl = tempfile.NamedTemporaryFile('wb', dir="testing_tmp", delete=False) from_pl = tempfile.NamedTemporaryFile('rb', dir="testing_tmp", delete=False) debug('prolog', to_pl.name, from_pl.name) global filenames filenames = (to_pl.name, from_pl.name) nsmap = qname.Map() nsmap.defaults = [qname.common] #nsmap.bind("", "http://www.w3.org/2007/rif#") to_pl.write("% "+msg) ast = kb._factory rifeval = ast.Instance('rif_Const') rifeval.rif_value = ast.DataValue(rif_bip+'eval', rifns+'iri') kb_pform = func_to_pred.Plugin(calc_pred=rifeval).transform(kb) query_pform = func_to_pred.Plugin(calc_pred=rifeval).transform(query) Plugin(nsmap=nsmap, supress_nsmap=True).serialize(kb_pform, to_pl) Plugin(nsmap=nsmap).serialize(query_pform, to_pl) to_pl.close() popen = subprocess.Popen( ["swipl", "-q", "-g", "[builtins], run_query(%s, %s), halt." % (atom_quote(to_pl.name), atom_quote(from_pl.name)) ], bufsize=0, # unbuffered for now at least stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) # to start reading this safely....? # popen.stdout.setblocking(False) (stdoutdata, stderrdata) = popen.communicate() if stdoutdata: # since this doesn't seem to ever happen, I guess we can # use this for the results feed error.notify(error.UnexpectedOutputFromSubprocess( "\n===stdout===\n"+stdoutdata+"==========")) if stderrdata: error.notify(error.UnexpectedOutputFromSubprocess( "\n===stderr===\n"+stderrdata+"==========")) if popen.returncode != 0: error.notify(error.ErrorReturnFromSubprocess("Return code: "+ str(popen.returncode))) result = read_solutions(from_pl) return result
def reset_password(driver, url, fakeuser, testname, errordb, datadb, concurrent_users, display = None): error.notify("Reseting users password", url, testname, errordb) url += '/portal/pass_reset/' page.load(driver, url, testname, errordb, datadb, "//h3[text()='Welcome to the secured password reset wizard']", 'xpath', 'password_reset', concurrent_users, display) try: email = driver.find_element_by_name("email") email.send_keys(fakeuser['email']) element = driver.find_element_by_xpath("//input[contains(@value,'Reset my password')]") element.click() except: message = "[%s] TEST FAILED: could not find proper from to input email address, url: %s" % (str(__name__)+'.reset_password', url) filename = error.save_error(message, url, testname, driver, errordb) return (False, message, filename) driver.wait = ui.WebDriverWait(driver, 50) try: driver.wait.until(lambda driver: driver.find_element_by_xpath("//h3[text()='Welcome to the secured password reset wizard']")) message = None except: message = "[%s] TEST FAILED: processing email reset request failed for user: %s" % (str(__name__)+'.reset_password', fakeuser['email']) try: driver.wait.until(lambda driver: driver.find_element_by_xpath("//li[text()=\"That email address doesn't have an associated user account. Are you sure you've registered?\"]")) message = "[%s] TEST FAILED: email has been reported as not existing in database: %s" % (str(__name__)+'.reset_password', fakeuser['email']) except: message = None if message: filename = error.save_error(message, url, testname, driver, errordb) return (False, message, filename) # TODO #1 - clean up the code needed - for now it is copy paste # confirm account with gmail try: a = 0 while a < 5: # I try to fetch email 5 times (25s in total): try: link = gemail.fetch_reset_link(fakeuser['trueemail'], fakeuser['password'], fakeuser['email']) if link: error.notify("validation link: %s " % link, url, testname, errordb) break else: error.notify("waiting...", url, testname, errordb) a = a+1 t.sleep(5) except: a = a+1 t.sleep(5) except: message = "[%s] TEST FAILED with error: I was not able to read email link." % (str(__name__)+'.reset_password') filename = error.save_error(message, url, testname, driver, errordb) return (False, message, filename) # TODO replace with load() - what text is expected? try: driver.get(link) except: message = "[%s] TEST FAILED with error: I was not able to confirm email link" % (str(__name__)+'.reset_password') filename = error.save_error(message, url, testname, driver, errordb) return (False, message, filename) error.notify("[%s] OK - Reseting password for user: %s" % (str(__name__)+'.reset_password', fakeuser['email']), url, testname, errordb) return (True, "[%s] OK - Reseting password for user: %s"% (str(__name__)+'.reset_password', fakeuser['email']))
except Exception, e: message = "[%s] TEST FAILED with error: I was not able to properly fill the form on: %s" % (str(__name__)+'.create', url) filename = error.save_error(message, url, testname, driver, errordb) return (False, message, filename) try: driver.wait.until(lambda driver: driver.find_elements_by_xpath("//*[contains(text(), 'Email already registered.')] | //*[contains(text(), 'Exception Type:')] | //*[contains(text(), 'Sign up information received')]")) except: message = "[%s] TEST FAILED with unknown error: I've not get proper after create-account screen %s" % (str(__name__)+'.create', url) error.save_error(message, url, testname, driver, errordb) return (False, message) if driver.find_elements_by_xpath("//*[contains(text(), 'Sign up information received')]"): error.notify("Registration completed successfully", url, testname, errordb) elif driver.find_elements_by_xpath("//*[contains(text(), 'Email already registered.')]"): message = "[%s] TEST FAILED with error: Email address already registered %s" % (str(__name__)+'.create', fakeuser['email']) filename = error.save_error(message, url, testname, driver, errordb) return (False, message, filename) elif driver.find_elements_by_xpath("//*[contains(text(), 'Exception Type:')]") > 0: message = "[%s] TEST FAILED with Django error" % (str(__name__)+'.create') filename = error.save_error(message, url, testname, driver, errordb) return (False, message, filename) exec_time = datetime.now() - time_now if (datadb): influx.savedata("create_user_form_submit", exec_time.total_seconds(), datadb, url, testname, users)