def test_config_authentic(): '''Setting up Authentic metadata''' twill.execute_string(''' go http://localhost:10001/admin/settings/idp formfile 1 privatekey private-key.pem formfile 1 publickey public-key.pem submit''')
def do_cleanup_for(name): if has_cleanup_handler(name) and not options.no_cleanup_mode: log_info("running cleanup handler for %s" % name) try: suite_data = file(current_namespace[-1].cleanup[name]).read() calls = parse_suite(suite_data) for script,args,line in calls: try: if current_namespace[-1].suites.get(script): log_warn("Cannot call sub-suite %s during cleanup at %s(%d)" % (script,name,line)) else: log_info("running cleanup: %s" % name) script_data = read_test(script) try: parameters = make_dict_from_call(args,get_twill_glocals()[0]) except (ValueError, TypeError, SyntaxError), e: e.args = ("\"%s%s\": Only positional argument passing is supported in suites." % \ (name, args), ) + e.args[1:] raise e script_data = make_twill_local_defs(parameters) + script_data twill.execute_string(script_data, no_reset=1) except Exception, e: maybe_print_stack() log_warn("Cleanup call to %s failed at %s(%d)" % (script + args, name + CLEANUP, line)) except IOError,e: maybe_print_stack() log_warn("Unable to read cleanup handler for %s" % name) except Exception,e: maybe_print_stack() log_warn("Exception during cleanup handler for %s" % name)
def tagging_tes(self): ''' Tagging tests:''' # copied from twilltests/files/files-tests.tsuite mytwilltests = [ "login 'admin'", # Tag suite # tag a community "runfile '${test_path}/tagging/tag_community.twill'", # tag a blog entry #"runfile '${test_path}/tagging/tag_blog_entry.twill'", # tag a calendar entry "runfile '${test_path}/tagging/tag_calendar_entry.twill'", # tag a file "runfile '${test_path}/tagging/tag_file.twill'", # tag a user "runfile '${test_path}/tagging/tag_user.twill'", # tag a wiki "runfile '${test_path}/tagging/tag_wiki_entry.twill'", ] for comm in mytwilltests: twill.execute_string(comm)
def test_sso_defederate_then_slo(): twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10002 submit fv 1 username fred fv 1 password fred submit url http://localhost:10002 submit fedterm-soap url http://localhost:10002 notfind 'Log on' find 'Single Logout' notfind 'Federation Termination' go http://localhost:10001 find 'Local Logout' find 'Single Logout' notfind 'Federation Termination' fv 2 binding SOAP fv 2 slo 'Single Logout' submit 'Single Logout' url http://localhost:10001 find 'Log in' notfind 'Single Logout' notfind 'Federation termination' go http://localhost:10002 find 'Log on' notfind 'Single Logout' notfind 'Federation termination' ''')
def search_tes(self): ''' Search tests:''' # copied from twilltests/files/files-tests.tsuite mytwilltests = [ "login 'admin'", # Search tests # Test searching for a blog entry "runfile '${test_path}/search/search_blog_entry.twill'", # Test searching for a calendar entry "runfile '${test_path}/search/search_calendar_entry.twill'", # Test searching for a community "runfile '${test_path}/search/search_community.twill'", # Test searching for a file "runfile '${test_path}/search/search_file.twill'", # Test searching for a user "runfile '${test_path}/search/search_user.twill'", # Test searching for wiki "runfile '${test_path}/search/search_wiki_entry.twill'", ] for comm in mytwilltests: twill.execute_string(comm)
def test_config_lcs_providers(): '''Adding Authentic as identity provider in LCS''' twill.execute_string(''' go http://localhost:10002/admin/settings/identification/idp/idp/new_remote showforms fv 1 metadata_url http://localhost:10001/saml/metadata submit ''')
def test_create_users(): '''Creating Authentic user''' twill.execute_string(''' go http://localhost:10001/admin/identities/new fv 1 name Fred fv 1 roles$element0 Administrator fv 1 username fred fv 1 password fred submit submit''')
def test_sso_ispassive(): twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10002 fv 1 is_passive true submit url http://localhost:10002 find 'Authentication failure' ''')
def test_config_lcs(): '''Setting up LCS metadata''' twill.execute_string(''' go http://localhost:10002/admin/settings/identification/ fv 1 methods$elementidp true submit go http://localhost:10002/admin/settings/identification/idp/sp formfile 1 privatekey private-key.pem formfile 1 publickey public-key.pem submit''')
def testIndex(): test = """ extend_with header debug commands 1 go / code 200 header charset=utf-8 """ twill.execute_string(test, initial_url='http://localhost:4444')
def test_sso_default(): twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10002 submit fv 1 username fred fv 1 password fred submit url http://localhost:10002 find 'Logged in' ''')
def testi18n(): test = """ debug commands 1 go /test_i18n.html code 200 find 'I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3\xb8n' """ twill.execute_string(test, initial_url='http://localhost:4444') browser = twill.get_browser() print dir(browser)
def test_sso_idp_initiated(): twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10001 fv 1 username fred fv 1 password fred submit fv 1 sp http-localhost-10002-saml-metadata submit sso url http://localhost:10002 find 'Logged in' ''')
def test_config_authentic_providers(): '''Adding LCS as service provider in Authentic''' twill.execute_string(''' go http://localhost:10001/login fv 1 username fred fv 1 password fred submit go http://localhost:10001/admin/settings/liberty_providers/new_remote showforms fv 1 metadata_url http://localhost:10002/saml/metadata submit ''')
def load_configuration(name): filename = current_namespace[-1].conf.get(name) if filename: try: configuration = read_configuration(name) twill.execute_string(configuration, no_reset=1) log_info("loaded configuration: %s" % (name + CONFIGURATION)) except IOError, e: handle_exception("Unable to read configuration for suite %s" \ % (name + SUITE), e) except Exception, e: handle_exception("Invalid configuration: '%s'" \ % (name + CONFIGURATION), e)
def load_configuration(name): filename = current_namespace[-1].conf.get(name) if filename: try: configuration = read_configuration(name) twill.execute_string(configuration, no_reset=1) log_info("loaded configuration: %s" % (name + CONFIGURATION)) except IOError,e: handle_exception("Unable to read configuration for suite %s" \ % (name + SUITE), e) except Exception,e: handle_exception("Invalid configuration: '%s'" \ % (name + CONFIGURATION), e)
def test_sso_post(): twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10002 fv 1 binding POST submit fv 1 username fred fv 1 password fred submit find 'You should be automaticaly' submit url http://localhost:10002 find 'Logged in' ''')
def blog_tes(self): ''' Blog tests:''' # copied from twilltests/blog/blog-tests.tsuite mytwilltests = [ "login 'admin'", # run blog tests "runfile '${test_path}/blog/blog_view.twill'", "runfile '${test_path}/blog/blogentry_aved.twill'", "runfile '${test_path}/blog/blog_index.twill'", ] for comm in mytwilltests: twill.execute_string(comm)
def wiki_tes(self): ''' Wiki tests:''' # copied from twilltests/wiki/wiki-tests.tsuite mytwilltests = [ "login 'admin'", # run wiki tests "runfile '${test_path}/wiki/wiki_view.twill'", "runfile '${test_path}/wiki/wikipage_aved.twill'", "runfile '${test_path}/wiki/wiki_index.twill'" ] for comm in mytwilltests: twill.execute_string(comm)
def getTicketList(self, userNamePwdList): """This method should pass in a list [(userName, userPwd)] and will return [(userName, 普通|初级VIP|高级VIP, 用户积分(大号|小号), 日推荐票, 日广告票)]. Or [(userName, u'登陆失败', u'登陆失败', '-1', '-1')] """ ticketList = [] for userName, userPwd in userNamePwdList: try: self.__emitStatus(u'正在使用用户 {0} 登录。。。'.format(userName)) twill_script = """ go http://www.qidian.com/User/Login.aspx fv 1 txtUserName {0} fv 1 txtPwd {1} submit """.format(userName, userPwd) twill.execute_string(twill_script) # Check whether the current url has been go to the line below, if not, means user faile to login, the clause below will throw a exception. twill.commands.url('http://www.qidian.com/Default.aspx') self.__emitStatus(u'正在访问用户 {0} 的个人书屋。。。'.format(userName)) twill.commands.go('http://www.qidian.com/User/Index.aspx') # Get html and begin to parse the html. html = twill.commands.show() html = unicode(html, 'gbk') userType = re.search(ur'用户类型.*?>(.*?)<.*?用户', html).groups()[0] userScore = re.search(ur'用户积分.*?>(\d+\.?\d*)<.*?分', html).groups()[0] recNum = re.search(ur'日推荐票.*?现余.*?>(\d+)<.*?次', html).groups()[0] advNum = re.search(ur'日广告票.*?现余.*?>(\d+)<.*?次', html).groups()[0] if userType == u'普通': bigSmall = userScore + u'(大号)' if float(userScore) > 6000 else userScore + u'(小号)' elif userType == u'初级VIP': bigSmall = userScore + u'(大号)' if float(userScore) > 1000 else userScore + u'(小号)' elif userType == u'高级VIP': bigSmall = userScore + u'(大号)' ticketList.append((userName, userType, bigSmall, recNum, advNum)) except Exception as e: print e self.__emitStatus(u'用户 {0} 登录失败,请检查用户名密码或联系作者更新本软件。。。'.format(userName)) ticketList.append((userName, u'登陆失败', u'登陆失败', '-1', '-1')) finally: # Clear the cookies for the next user will login. twill.commands.clear_cookies() return ticketList
def calendar_tes(self): ''' Calendar tests:''' # copied from twilltests/calendar/calendar-tests.tsuite mytwilltests = [ "login 'admin'", # run calendar tests "runfile '${test_path}/calendar/calendar-view.twill'", "runfile '${test_path}/calendar/create-event.twill'", "runfile '${test_path}/calendar/calendar-aved.twill'", "runfile '${test_path}/calendar/calendar-index.twill'" ] for comm in mytwilltests: twill.execute_string(comm)
def test_sso_slo_initiated_by_sp_redirect(): twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10002 submit fv 1 username fred fv 1 password fred submit url http://localhost:10002 submit slo-redirect url http://localhost:10002 find 'Log on' go http://localhost:10001 find password ''')
def files_tes(self): ''' Files tests:''' # copied from twilltests/files/files-tests.tsuite mytwilltests = [ "login 'admin'", # Tests for files suite "runfile '${test_path}/files/files_view.twill'", "runfile '${test_path}/files/files_aved.twill'", "runfile '${test_path}/files/files_index.twill'" ] for comm in mytwilltests: twill.execute_string(comm)
def run_test(name, args): # this pushes the correct namespace on the stack # should be popped test = current_namespace[-1].lookup(name) if test is None: raise NameError("Unable to locate %s or %s in search path" % (name + TEST, name + SUITE)) name = test current = current_namespace[-1] try: if current.suites.get(name): if args: log_warn("Arguments provided to suites are ignored! [%s%s]" % (name, args)) return run_suite(name) elif current.tests.get(name): # don't do anything in cleanup only mode if options.cleanup_mode: return [] try: log_info("running test: %s" % name) output_stream.indent() try: script = file(current.tests[name]).read() try: parameters = make_dict_from_call( args, get_twill_glocals()[0]) except (ValueError, TypeError, SyntaxError), e: e.args = ("\"%s%s\": Only positional argument passing is supported in suites." % \ (name, args), ) + e.args[1:] raise e script = make_twill_local_defs(parameters) + script twill.execute_string(script, no_reset=1) return [] except IOError, e: handle_exception( "Unable to read test '%s'" % (name + TEST), e) return [name] except Exception, e: handle_exception("Error running %s" % name, e) return [name]
def test_sso_slo_initiated_by_idp_soap(): twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10002 submit fv 1 username fred fv 1 password fred submit url http://localhost:10002 go http://localhost:10001 fv 2 binding SOAP fv 2 slo 'Single Logout' submit 'Single Logout' url http://localhost:10001 find password go http://localhost:10002 find 'Log on' ''')
def test_sso_idp_initiated_then_slo_sp_soap(): ### http://bugs.entrouvert.org/rapport-de-bug-pour-la-conformance-saml-2-0/8/ twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10001 fv 1 username fred fv 1 password fred submit fv 1 sp http-localhost-10002-saml-metadata submit sso url http://localhost:10002 find 'Logged in' submit slo-soap url http://localhost:10002 find 'Log on' go http://localhost:10001 find password ''')
def test_sso_slo_initiated_by_idp_redirect(): twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10002 submit fv 1 username fred fv 1 password fred submit url http://localhost:10002 go http://localhost:10001 fv 2 slo 'Single Logout' submit 'Single Logout' follow 'singleLogout' go http://localhost:10001/saml/singleLogoutFinish url http://localhost:10001 find password go http://localhost:10002 find 'Log on' ''')
def community_tes(self): ''' Community tests:''' # copied from twilltests/community/community-tests.tsuite mytwilltests = [ "login 'admin'", # Make community "runfile '${test_path}/community/make_community.twill'", # optional tests which we run to test functionality of new community. # you can comment out if needed "runfile '${test_path}/community/blog_initialize.twill'", "runfile '${test_path}/community/calendar_initialize.twill'", "runfile '${test_path}/community/files_initialize.twill'", "runfile '${test_path}/community/wiki_initialize.twill'" ] for comm in mytwilltests: twill.execute_string(comm)
def test_config_idp(): twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10000/admin/ fv 1 username admin fv 1 password admin submit go http://localhost:10000/admin/ find 'dministration' ''') twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10000 fv 1 username user1 fv 1 password user1 submit url http://localhost:10000 find 'You are authenticated' ''')
def run_test(name,args): # this pushes the correct namespace on the stack # should be popped test = current_namespace[-1].lookup(name) if test is None: raise NameError("Unable to locate %s or %s in search path" % (name + TEST, name + SUITE)) name = test current = current_namespace[-1] try: if current.suites.get(name): if args: log_warn("Arguments provided to suites are ignored! [%s%s]" % (name,args)) return run_suite(name) elif current.tests.get(name): # don't do anything in cleanup only mode if options.cleanup_mode: return [] try: log_info("running test: %s" % name) output_stream.indent() try: script = file(current.tests[name]).read() try: parameters = make_dict_from_call(args,get_twill_glocals()[0]) except (ValueError, TypeError, SyntaxError), e: e.args = ("\"%s%s\": Only positional argument passing is supported in suites." % \ (name, args), ) + e.args[1:] raise e script = make_twill_local_defs(parameters) + script twill.execute_string(script, no_reset=1) return [] except IOError, e: handle_exception("Unable to read test '%s'" % (name + TEST), e) return [name] except Exception, e: handle_exception("Error running %s" % name, e) return [name]
def setUp(self): '''Create the app''' test_path = os.path.abspath(os.path.dirname(__file__)) testpath_command = "setglobal test_path " + test_path twill.execute_string(testpath_command) fixtures = os.path.join(test_path, 'fixtures') for to_delete in [fname for fname in os.listdir(fixtures) if fname.startswith('Data.fs') or fname in ['blobs']]: _rm(os.path.join(fixtures, to_delete)) os.mkdir(os.path.join(fixtures, 'blobs')) wsgi_app = get_app(os.path.join(test_path, 'fixtures', 'karl.ini'), 'main') def build_app(): return wsgi_app twill.add_wsgi_intercept('localhost', 6543, build_app) # XXX How do we suppress the annoying "AT LINE: " output? twill.set_output(open('/dev/null', 'wb')) twill.execute_string("extend_with karl.twillcommands") # mostly the same as karl3.conf without extending with flunc # and few other adjustments. twill.execute_string("runfile '" + os.path.abspath(os.path.dirname(__file__)) + "/test_twill_wsgi_karl3.conf'")
def test_sso_defederate_initiated_by_sp_redirect(): twill.commands.reset_browser() twill.execute_string(''' go http://localhost:10002 submit fv 1 username fred fv 1 password fred submit url http://localhost:10002 notfind 'Log on' find 'Single Logout' find 'Federation Termination' submit fedterm-redirect url http://localhost:10002 notfind 'Log on' find 'Single Logout' notfind 'Federation Termination' go http://localhost:10001 find 'Local Logout' find 'Single Logout' notfind 'Federation Termination' ''')
def profiles_tes(self): ''' Profiles tests:''' # copied from twilltests/profiles/profiles-tests.tsuite mytwilltests = [ "login 'admin'", # Profile tests # Test to see what profiles we can see #user_view # Login as admin before add/edit/delete user "login 'admin'", # Add, edit, and delete user account "runfile '${test_path}/profiles/user_add.twill'", #user_edit "runfile '${test_path}/profiles/user_delete.twill'" ] for comm in mytwilltests: twill.execute_string(comm)
def do_cleanup_for(name): if has_cleanup_handler(name) and not options.no_cleanup_mode: log_info("running cleanup handler for %s" % name) try: suite_data = file(current_namespace[-1].cleanup[name]).read() calls = parse_suite(suite_data) for script, args, line in calls: try: if current_namespace[-1].suites.get(script): log_warn( "Cannot call sub-suite %s during cleanup at %s(%d)" % (script, name, line)) else: log_info("running cleanup: %s" % name) script_data = read_test(script) try: parameters = make_dict_from_call( args, get_twill_glocals()[0]) except (ValueError, TypeError, SyntaxError), e: e.args = ("\"%s%s\": Only positional argument passing is supported in suites." % \ (name, args), ) + e.args[1:] raise e script_data = make_twill_local_defs( parameters) + script_data twill.execute_string(script_data, no_reset=1) except Exception, e: maybe_print_stack() log_warn("Cleanup call to %s failed at %s(%d)" % (script + args, name + CLEANUP, line)) except IOError, e: maybe_print_stack() log_warn("Unable to read cleanup handler for %s" % name) except Exception, e: maybe_print_stack() log_warn("Exception during cleanup handler for %s" % name)
map_file = open(options.host_file) lines = [x.strip() for x in map_file] lines = [x for x in lines if x and not x.startswith('#')] mapping = [x.split() for x in lines] mapping = [x for x in mapping if len(x) == 2] hostname_redirect_mapping.update(dict(mapping)) if options.verbose: log_info('[*] mapping\n%s' % ('\n'.join(['%s -> %s' % (a, b) for a, b in mapping]))) except IOError: pass set_use_tidy(options.use_tidy) twill.execute_string("add_extra_header 'Accept-Language' '%s'" % options.language) try: error_tests = [] calls = map(parse_test_call, args[1:]) for name, args in calls: load_overrides() error_tests += run_test(name, args) except SystemExit: raise except Exception, e: handle_exception("ERROR", e) else: nerrors = len(error_tests) if options.cleanup_mode: log_info('Cleanup Complete.')
def run_twill_tests(filename): fp = open(filename) twill.execute_string(fp.read(), initial_url='http://localhost:8000/') meeplib._reset()
def set_use_tidy(value): setting = int(bool(value)) twill.execute_string("config use_tidy %d" % value, no_reset=1)
twill_script = """setlocal username "ghost_e" setlocal password "13916939847273450" # debug "http" 1 go https://developer.emetrix.com fv 1 UserName $username fv 1 Password $password submit follow "Windows Audio Recorder Professional" follow "Send Download Link" fv 2 Format "PRINTLINK" # can not submit directly here, for the formaction url contains space which should be encoded first, # so I rewrite the form action attributes as below: fa 2 "https://developer.emetrix.com/storefront/send_DL.asp?PID=11784033&UN=ghost_e&FFN=Official_Recorder_Professional.exe&PN=Windows%20Audio%20Recorder%20Professional&FFS=5119714" submit """ twill.execute_string(twill_script) # and then use twill in python to show & analyze the result. # twill.commands.* contains all the twill script command, below is 'show' command. html = twill.commands.show() print '============================================' print html print '============================================' links = list(twill.commands.showlinks()) print links print print '===============Way 1 showlinks() method to Get the link you want.=============================' print for link in links: if 'Official_Recorder_Professional.exe' in link.url: print link.url break
def load_overrides(): if CONFIG_OVERRIDE_SCRIPT: try: twill.execute_string(CONFIG_OVERRIDE_SCRIPT, no_reset=1) except Exception, e: handle_exception('Error in global configuration overrides', e)
def run(fileName): fp = open(fileName) twill.execute_string(fp.read(), initial_url='http://localhost:8000/')