<s> import htmlPy <EOL> import unittest <EOL> import os <EOL> import random <EOL> import string <EOL> import json <EOL> from nose . plugins . attrib import attr <EOL> def random_string ( ) : <EOL> return "<STR_LIT>" . join ( random . sample ( string . ascii_letters , <NUM_LIT:32> ) ) <EOL> RANDOM_PARAMS = { <EOL> "<STR_LIT>" : random_string ( ) , <EOL> "<STR_LIT>" : random_string ( ) , <EOL> "<STR_LIT>" : random_string ( ) , <EOL> "<STR_LIT>" : random_string ( ) , <EOL> "<STR_LIT>" : random_string ( ) , <EOL> "<STR_LIT>" : random_string ( ) , <EOL> "<STR_LIT>" : random_string ( ) , <EOL> "<STR_LIT>" : random_string ( ) , <EOL> "<STR_LIT>" : random_string ( ) , <EOL> "<STR_LIT>" : random_string ( ) , <EOL> "<STR_LIT>" : random_string ( ) , <EOL> "<STR_LIT>" : random_string ( ) , <EOL> } <EOL> class BindingTest ( htmlPy . Object ) : <EOL> def __init__ ( self , app ) : <EOL> super ( BindingTest , self ) . __init__ ( ) <EOL> self . app = app <EOL> def __set_appname ( self , appname ) : <EOL> context = { "<STR_LIT>" : appname } <EOL> context . update ( RANDOM_PARAMS ) <EOL> self . app . template = ( "<STR_LIT>" , context ) <EOL> @ htmlPy . Slot ( str ) <EOL> def appname_change ( self , appname ) : <EOL> self . __set_appname ( appname ) <EOL> @ htmlPy . Slot ( str , result = str ) <EOL> def return_same ( self , value ) : <EOL> return value <EOL> @ htmlPy . Slot ( ) <EOL> def appname_link_clicked ( self ) : <EOL> self . __set_appname ( RANDOM_PARAMS [ "<STR_LIT>" ] ) <EOL> @ htmlPy . Slot ( str ) <EOL> def appname_link_clicked_with_args ( self , argstring ) : <EOL> self . __set_appname ( argstring * <NUM_LIT:2> ) <EOL> @ htmlPy . Slot ( str ) <EOL> def appname_form_submit ( self , form_data ) : <EOL> jsondata = json . loads ( form_data ) <EOL> self . __set_appname ( jsondata [ "<STR_LIT:name>" ] ) <EOL> @ htmlPy . Slot ( str , str ) <EOL> def appname_form_submit_with_args ( self , form_data , argstring ) : <EOL> jsondata = json . loads ( form_data ) <EOL> self . __set_appname ( jsondata [ "<STR_LIT:name>" ] + argstring ) <EOL> class TestAppGUIBinding ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . app = htmlPy . AppGUI ( allow_overwrite = True ) <EOL> self . app . static_path = os . path . join ( <EOL> os . path . dirname ( os . path . abspath ( __file__ ) ) , "<STR_LIT>" ) <EOL> self . app . template_path = self . app . static_path <EOL> self . frame = self . app . web_app . page ( ) . mainFrame ( ) <EOL> self . app . bind ( BindingTest ( self . app ) ) <EOL> self . app . web_app . loadFinished . connect ( self . app . stop ) <EOL> self . reloader ( ) <EOL> def reloader ( self ) : <EOL> context = { "<STR_LIT>" : "<STR_LIT>" } <EOL> context . update ( RANDOM_PARAMS ) <EOL> self . app . template = ( "<STR_LIT>" , context ) <EOL> def refresh_view ( self ) : <EOL> self . app . web_app . loadFinished . connect ( self . app . stop ) <EOL> self . app . execute ( ) <EOL> def form_submitter ( self , form_id ) : <EOL> self . app . evaluate_javascript ( <EOL> "<STR_LIT>" . format ( <EOL> form_id , RANDOM_PARAMS [ "<STR_LIT>" ] ) ) <EOL> self . app . evaluate_javascript ( <EOL> "<STR_LIT>" . format ( form_id ) ) <EOL> @ attr ( "<STR_LIT>" ) <EOL> def test_binding_activation ( self ) : <EOL> assert self . frame . documentElement ( ) . findFirst ( <EOL> "<STR_LIT:body>" ) . hasClass ( "<STR_LIT>" ) <EOL> @ attr ( "<STR_LIT>" ) <EOL> def test_binding_persistence ( self ) : <EOL> self . test_binding_activation ( ) <EOL> self . html = "<STR_LIT>" <EOL> self . test_binding_activation ( ) <EOL> def test_function_call ( self ) : <EOL> rs = random_string ( ) <EOL> assert rs not in self . app . html <EOL> self . app . evaluate_javascript ( <EOL> "<STR_LIT>" . format ( rs ) ) <EOL> assert rs in self . app . html <EOL> def test_function_return ( self ) : <EOL> rs = random_string ( ) <EOL> assert rs not in self . app . html <EOL> self . app . evaluate_javascript ( <EOL> "<STR_LIT>" . format ( rs ) ) <EOL> assert rs in self . app . html <EOL> def test_non_existent_call ( self ) : <EOL> html = self . app . html <EOL> self . app . evaluate_javascript ( "<STR_LIT>" ) <EOL> assert self . app . html == html <EOL> @ attr ( "<STR_LIT>" ) <EOL> def test_link_click ( self ) : <EOL> assert RANDOM_PARAMS [ "<STR_LIT>" ] not in self . app . html <EOL> self . app . evaluate_javascript ( <EOL> "<STR_LIT>" . format ( <EOL> RANDOM_PARAMS [ "<STR_LIT>" ] ) ) <EOL> assert RANDOM_PARAMS [ "<STR_LIT>" ] in self . app . html <EOL> @ attr ( "<STR_LIT>" ) <EOL> def test_link_click_with_args ( self ) : <EOL> assert RANDOM_PARAMS [ "<STR_LIT>" ] * <NUM_LIT:2> not in self . app . html <EOL> self . app . evaluate_javascript ( <EOL> "<STR_LIT>" . format ( <EOL> RANDOM_PARAMS [ "<STR_LIT>" ] ) ) <EOL> assert RANDOM_PARAMS [ "<STR_LIT>" ] * <NUM_LIT:2> in self . app . html <EOL> @ attr ( "<STR_LIT>" ) <EOL> def test_link_click_dynamic ( self ) : <EOL> assert RANDOM_PARAMS [ "<STR_LIT>" ] not in self . app . html <EOL> self . app . evaluate_javascript ( """<STR_LIT>""" . format ( <EOL> RANDOM_PARAMS [ "<STR_LIT>" ] ) ) <EOL> self . app . evaluate_javascript ( <EOL> "<STR_LIT>" . format ( <EOL> RANDOM_PARAMS [ "<STR_LIT>" ] ) ) <EOL> assert RANDOM_PARAMS [ "<STR_LIT>" ] in self . app . html <EOL> def test_link_click_404 ( self ) : <EOL> html = self . app . html <EOL> self . app . evaluate_javascript ( <EOL> "<STR_LIT>" . format ( <EOL> RANDOM_PARAMS [ "<STR_LIT>" ] ) ) <EOL> assert self . app . html == html <EOL> @ attr ( "<STR_LIT>" ) <EOL> def test_form_submit ( self ) : <EOL> assert RANDOM_PARAMS [ "<STR_LIT>" ] not in self . app . html <EOL> self . form_submitter ( RANDOM_PARAMS [ "<STR_LIT>" ] ) <EOL> assert RANDOM_PARAMS [ "<STR_LIT>" ] in self . app . html <EOL> @ attr ( "<STR_LIT>" ) <EOL> def test_form_submit_with_args ( self ) : <EOL> check = RANDOM_PARAMS [ "<STR_LIT>" ] + RANDOM_PARAMS [ "<STR_LIT>" ] <EOL> assert check not in self . app . html <EOL> self . form_submitter ( RANDOM_PARAMS [ "<STR_LIT>" ] ) <EOL> assert check in self . app . html <EOL> @ attr ( "<STR_LIT>" ) <EOL> def test_form_submit_dynamic ( self ) : <EOL> assert RANDOM_PARAMS [ "<STR_LIT>" ] not in self . app . html <EOL> form_html = """<STR_LIT>""" . format ( * ( [ RANDOM_PARAMS [ "<STR_LIT>" ] ] * <NUM_LIT:3> ) ) <EOL> self . app . evaluate_javascript ( <EOL> "<STR_LIT>" . format ( <EOL> form_html . replace ( "<STR_LIT:\n>" , "<STR_LIT:;>" ) ) ) <EOL> self . form_submitter ( RANDOM_PARAMS [ "<STR_LIT>" ] ) <EOL> assert RANDOM_PARAMS [ "<STR_LIT>" ] in self . app . html <EOL> def test_form_submit_404 ( self ) : <EOL> html = self . app . html <EOL> self . form_submitter ( RANDOM_PARAMS [ "<STR_LIT>" ] ) <EOL> assert self . app . html == html </s>
