<s> import io <EOL> from django . test import TestCase <EOL> from explorer . actions import generate_report_action <EOL> from explorer . tests . factories import SimpleQueryFactory <EOL> from explorer . utils import csv_report <EOL> from zipfile import ZipFile <EOL> class TestSqlQueryActions ( TestCase ) : <EOL> def test_simple_query_runs ( self ) : <EOL> expected_csv = '<STR_LIT>' <EOL> r = SimpleQueryFactory ( ) <EOL> result = csv_report ( r ) . getvalue ( ) <EOL> self . assertIsNotNone ( result , "<STR_LIT>" % r . title ) <EOL> self . assertEqual ( result . lower ( ) , expected_csv ) <EOL> def test_simple_query_does_not_transform ( self ) : <EOL> expected_csv = '<STR_LIT>' <EOL> r = SimpleQueryFactory ( sql = '<STR_LIT>' ) <EOL> result = csv_report ( r ) . getvalue ( ) <EOL> self . assertIsNotNone ( result , "<STR_LIT>" % r . title ) <EOL> self . assertEqual ( result . lower ( ) , expected_csv ) <EOL> def test_single_query_is_csv_file ( self ) : <EOL> expected_csv = b'<STR_LIT>' <EOL> r = SimpleQueryFactory ( ) <EOL> fn = generate_report_action ( ) <EOL> result = fn ( None , None , [ r , ] ) <EOL> self . assertEqual ( result . content . lower ( ) , expected_csv ) <EOL> def test_multiple_queries_are_zip_file ( self ) : <EOL> expected_csv = '<STR_LIT>' <EOL> q = SimpleQueryFactory ( ) <EOL> q2 = SimpleQueryFactory ( ) <EOL> fn = generate_report_action ( ) <EOL> res = fn ( None , None , [ q , q2 ] ) <EOL> z = ZipFile ( io . BytesIO ( res . content ) ) <EOL> got_csv = z . read ( z . namelist ( ) [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( len ( z . namelist ( ) ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( z . namelist ( ) [ <NUM_LIT:0> ] , '<STR_LIT>' % q . title ) <EOL> self . assertEqual ( got_csv . lower ( ) . decode ( '<STR_LIT:utf-8>' ) , expected_csv ) <EOL> def test_packaging_removes_commas_from_file_name ( self ) : <EOL> expected = '<STR_LIT>' <EOL> q = SimpleQueryFactory ( title = '<STR_LIT>' ) <EOL> fn = generate_report_action ( ) <EOL> res = fn ( None , None , [ q ] ) <EOL> self . assertEqual ( res [ '<STR_LIT>' ] , expected ) </s>
