def test(): url = twilltestlib.get_url() # test empty page get_title namespaces.new_local_dict() twill.commands.reset_browser() browser = twill.get_browser() try: browser.get_title() assert 0, "should never get here" except TwillException: pass ### now test a few special cases commands.go(url) commands.go('/login') # test no matching forms try: commands.fv('2', 'submit', '1') assert 0 except TwillAssertionError: pass # test regexp match commands.fv('1', '.*you', '1') # test ambiguous match to value commands.go('/testform') commands.fv('1', 'selecttest', 'val') commands.fv('1', 'selecttest', 'value1') commands.fv('1', 'selecttest', 'selvalue1') commands.formclear('1') commands.showforms() try: commands.fv('1', 'selecttest', 'value') assert 0 except TwillException: pass # test ambiguous match to name commands.go('/testform') try: commands.fv('1', 'item_', 'value') assert 0 except Exception: pass try: commands.formfile('1', 'selecttest', 'null') assert 0 except Exception: pass commands.go('http://www.google.com/') browser.get_title() # test the twill script. twilltestlib.execute_twill_script('test-form.twill', initial_url=url)
def test_select_single(): namespaces.new_local_dict() twill.commands.reset_browser() browser = twill.get_browser() try: browser.get_title() assert 0, "should never get here" except BrowserStateError: pass commands.go(url) commands.go("/test_checkboxes") for x in ("1", "0", "True", "False"): try: commands.fv("1", "checkboxtest", x) assert False, "Should not be able to use a bool style for when " "there are multiple checkboxes" except: pass
def test_select_single(): namespaces.new_local_dict() twill.commands.reset_browser() browser = twill.get_browser() try: browser.get_title() assert 0, "should never get here" except BrowserStateError: pass commands.go(url) commands.go('/test_checkboxes') for x in ('1', '0', 'True', 'False'): try: commands.fv('1', 'checkboxtest', x) assert False, ("Should not be able to use a bool style for when " "there are multiple checkboxes") except: pass
def test_select_multiple(): namespaces.new_local_dict() twill.commands.reset_browser() browser = twill.get_browser() try: browser.get_title() assert 0, "should never get here" except BrowserStateError: pass commands.go(url) commands.go("/test_checkboxes") commands.fv("1", "checkboxtest", "one") commands.fv("1", "checkboxtest", "two") commands.fv("1", "checkboxtest", "three") commands.fv("1", "checkboxtest", "-one") commands.fv("1", "checkboxtest", "-two") commands.fv("1", "checkboxtest", "-three") commands.submit() assert not "CHECKBOXTEST" in browser.get_html() commands.fv("1", "checkboxtest", "+one") commands.fv("1", "checkboxtest", "+two") commands.fv("1", "checkboxtest", "+three") commands.submit() assert "CHECKBOXTEST: ==one,two,three==" in browser.get_html() commands.fv("1", "checkboxtest", "-one") commands.fv("1", "checkboxtest", "-two") commands.fv("1", "checkboxtest", "-three") commands.submit() assert not "CHECKBOXTEST" in browser.get_html()
def test_select_multiple(): namespaces.new_local_dict() twill.commands.reset_browser() browser = twill.get_browser() try: browser.get_title() assert 0, "should never get here" except BrowserStateError: pass commands.go(url) commands.go('/test_checkboxes') commands.fv('1', 'checkboxtest', 'one') commands.fv('1', 'checkboxtest', 'two') commands.fv('1', 'checkboxtest', 'three') commands.fv('1', 'checkboxtest', '-one') commands.fv('1', 'checkboxtest', '-two') commands.fv('1', 'checkboxtest', '-three') commands.submit() assert not 'CHECKBOXTEST' in browser.get_html() commands.fv('1', 'checkboxtest', '+one') commands.fv('1', 'checkboxtest', '+two') commands.fv('1', 'checkboxtest', '+three') commands.submit() assert 'CHECKBOXTEST: ==one,two,three==' in browser.get_html() commands.fv('1', 'checkboxtest', '-one') commands.fv('1', 'checkboxtest', '-two') commands.fv('1', 'checkboxtest', '-three') commands.submit() assert not 'CHECKBOXTEST' in browser.get_html()
def test(): url = twilltestlib.get_url() # test empty page get_title namespaces.new_local_dict() twill.commands.reset_browser() browser = twill.get_browser() try: browser.get_title() assert 0, "should never get here" except BrowserStateError: pass ### now test a few special cases commands.go(url) commands.go('/login') commands.showforms() # test no matching forms try: commands.fv('2', 'submit', '1') assert 0 except TwillAssertionError: pass # test regexp match commands.fv('1', '.*you', '1') # test ambiguous match to value commands.go('/testform') commands.fv('1', 'selecttest', 'val') commands.fv('1', 'selecttest', 'value1') commands.fv('1', 'selecttest', 'selvalue1') commands.formclear('1') try: commands.fv('1', 'selecttest', 'value') assert 0 except ClientForm.ItemNotFoundError: pass # test ambiguous match to name commands.go('/testform') try: commands.fv('1', 'item_', 'value') assert 0 except Exception: pass try: commands.formfile('1', 'selecttest', 'null') assert 0 except Exception: pass commands.go('http://www.google.com/') browser.get_title() # test the twill script. twilltestlib.execute_twill_script('test-form.twill', initial_url=url)
def test(): url = twilltestlib.get_url() # capture output fp = StringIO() twill.set_output(fp) twill.parse.execute_string('code 200', initial_url=url) # from file twilltestlib.execute_twill_script('test-go.twill', initial_url=url) twill.set_output(None) assert fp.getvalue() ### # from stdin filename = os.path.join(twilltestlib.testdir, 'test-go.twill') old_in, sys.stdin = sys.stdin, open(filename) try: twilltestlib.execute_twill_script('-', initial_url=url) finally: sys.stdin = old_in # from parse.execute_file twill.parse.execute_file('test-go-exit.twill', initial_url=url) # also test some failures. old_err, sys.stderr = sys.stderr, StringIO() try: twill.set_errout(sys.stderr) # # failed assert in a script # try: twill.parse.execute_file('test-go-fail.twill', initial_url=url) assert 0 except TwillAssertionError: pass commands.go(url) try: commands.code(400) assert 0 except TwillAssertionError: pass # # no such command (NameError) # try: twill.parse.execute_file('test-go-fail2.twill', initial_url=url) assert 0 except TwillNameError, e: pass finally: sys.stderr = old_err namespaces.new_local_dict() gd, ld = namespaces.get_twill_glocals() commands.go(url) try: twill.parse.execute_command('url', ('not this', ), gd, ld, "anony") assert 0, "shouldn't get here" except TwillAssertionError: pass try: commands.follow('no such link') assert 0, "shouldn't get here" except TwillAssertionError: pass try: commands.find('no such link') assert 0, "shouldn't get here" except TwillAssertionError: pass try: commands.notfind('Hello') assert 0, "shouldn't get here" except TwillAssertionError: pass try: twill.parse.execute_command('exit', ('0', ), gd, ld, "anony") assert 0, "shouldn't get here" except SystemExit: pass
def test(): url = twilltestlib.get_url() # capture output fp = StringIO() twill.set_output(fp) twill.parse.execute_string('code 200', initial_url=url) # from file twilltestlib.execute_twill_script('test-go.twill', initial_url=url) twill.set_output(None) assert fp.getvalue() ### # from stdin filename = os.path.join(twilltestlib.testdir, 'test-go.twill') old_in, sys.stdin = sys.stdin, open(filename) try: twilltestlib.execute_twill_script('-', initial_url=url) finally: sys.stdin = old_in # from parse.execute_file twill.parse.execute_file('test-go-exit.twill', initial_url=url) # also test some failures. old_err, sys.stderr = sys.stderr, StringIO() try: twill.set_errout(sys.stderr) # # failed assert in a script # try: twill.parse.execute_file('test-go-fail.twill', initial_url=url) assert 0 except TwillAssertionError: pass commands.go(url) try: commands.code(400) assert 0 except TwillAssertionError: pass # # no such command (NameError) # try: twill.parse.execute_file('test-go-fail2.twill', initial_url=url) assert 0 except TwillNameError, e: pass finally: sys.stderr = old_err namespaces.new_local_dict() gd, ld = namespaces.get_twill_glocals() commands.go(url) try: twill.parse.execute_command('url', ('not this',), gd, ld, "anony") assert 0, "shouldn't get here" except TwillAssertionError: pass try: commands.follow('no such link') assert 0, "shouldn't get here" except TwillAssertionError: pass try: commands.find('no such link') assert 0, "shouldn't get here" except TwillAssertionError: pass try: commands.notfind('Hello') assert 0, "shouldn't get here" except TwillAssertionError: pass try: twill.parse.execute_command('exit', ('0',), gd, ld, "anony") assert 0, "shouldn't get here" except SystemExit: pass