<s> from querybuilder . tests . models import Account , Order , User <EOL> from querybuilder . query import Query <EOL> from querybuilder . tests . query_tests import QueryTestCase , get_comparison_str <EOL> class JoinTest ( QueryTestCase ) : <EOL> def test_join_str_to_str ( self ) : <EOL> query = Query ( ) . from_table ( <EOL> table = '<STR_LIT>' <EOL> ) . join ( <EOL> '<STR_LIT>' , <EOL> condition = '<STR_LIT>' <EOL> ) <EOL> query_str = query . get_sql ( ) <EOL> expected_query = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( query_str , expected_query , get_comparison_str ( query_str , expected_query ) ) <EOL> def test_join_model_to_str ( self ) : <EOL> query = Query ( ) . from_table ( <EOL> table = Account <EOL> ) . join ( <EOL> '<STR_LIT>' , <EOL> condition = '<STR_LIT>' <EOL> ) <EOL> query_str = query . get_sql ( ) <EOL> expected_query = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( query_str , expected_query , get_comparison_str ( query_str , expected_query ) ) <EOL> def test_no_fields_and_fields ( self ) : <EOL> query = Query ( ) . from_table ( <EOL> table = Account , <EOL> fields = None <EOL> ) . join ( <EOL> '<STR_LIT>' , <EOL> fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] , <EOL> prefix_fields = True , <EOL> condition = '<STR_LIT>' <EOL> ) <EOL> query_str = query . get_sql ( ) <EOL> expected_query = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( query_str , expected_query , get_comparison_str ( query_str , expected_query ) ) <EOL> def test_join_model_foreign_key ( self ) : <EOL> query = Query ( ) . from_table ( <EOL> table = Account <EOL> ) . join ( <EOL> Order , <EOL> ) <EOL> query_str = query . get_sql ( ) <EOL> expected_query = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( query_str , expected_query , get_comparison_str ( query_str , expected_query ) ) <EOL> def test_join_model_foreign_key_reverse ( self ) : <EOL> query = Query ( ) . from_table ( <EOL> table = Order <EOL> ) . join ( <EOL> Account , <EOL> ) <EOL> query_str = query . get_sql ( ) <EOL> expected_query = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( query_str , expected_query , get_comparison_str ( query_str , expected_query ) ) <EOL> def test_join_model_one_to_one ( self ) : <EOL> query = Query ( ) . from_table ( <EOL> table = Account <EOL> ) . join ( <EOL> User , <EOL> ) <EOL> query_str = query . get_sql ( ) <EOL> expected_query = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( query_str , expected_query , get_comparison_str ( query_str , expected_query ) ) <EOL> def test_join_model_one_to_one_reverse ( self ) : <EOL> query = Query ( ) . from_table ( <EOL> table = User <EOL> ) . join ( <EOL> Account , <EOL> ) <EOL> query_str = query . get_sql ( ) <EOL> expected_query = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( query_str , expected_query , get_comparison_str ( query_str , expected_query ) ) <EOL> def test_join_model_fields ( self ) : <EOL> query = Query ( ) . from_table ( <EOL> table = Account , <EOL> fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> ) . join ( <EOL> Order , <EOL> fields = [ { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] <EOL> ) <EOL> query_str = query . get_sql ( ) <EOL> expected_query = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( query_str , expected_query , get_comparison_str ( query_str , expected_query ) ) <EOL> def test_join_model_fields_all ( self ) : <EOL> query = Query ( ) . from_table ( <EOL> table = Account , <EOL> fields = [ <EOL> '<STR_LIT:*>' , <EOL> ] <EOL> ) . join ( <EOL> Order , <EOL> fields = [ <EOL> '<STR_LIT:*>' <EOL> ] , <EOL> extract_fields = False <EOL> ) <EOL> query_str = query . get_sql ( ) <EOL> expected_query = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( query_str , expected_query , get_comparison_str ( query_str , expected_query ) ) <EOL> def test_join_model_fields_extract ( self ) : <EOL> query = Query ( ) . from_table ( <EOL> table = Account , <EOL> fields = [ <EOL> '<STR_LIT:*>' , <EOL> ] <EOL> ) . join ( <EOL> Order , <EOL> fields = [ <EOL> '<STR_LIT:*>' <EOL> ] <EOL> ) <EOL> query_str = query . get_sql ( ) <EOL> expected_query = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( query_str , expected_query , get_comparison_str ( query_str , expected_query ) ) <EOL> def test_join_model_fields_prefix ( self ) : <EOL> query = Query ( ) . from_table ( <EOL> table = Account , <EOL> fields = [ <EOL> '<STR_LIT:*>' , <EOL> ] <EOL> ) . join ( <EOL> Order , <EOL> fields = [ <EOL> '<STR_LIT:id>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> prefix_fields = True <EOL> ) <EOL> query_str = query . get_sql ( ) <EOL> expected_query = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( query_str , expected_query ) </s>
