<s> from twisted . trial import unittest <EOL> from twisted . internet . defer import inlineCallbacks <EOL> from twistar import utils <EOL> from utils import User , initDB , tearDownDB <EOL> from collections import OrderedDict <EOL> class UtilsTest ( unittest . TestCase ) : <EOL> @ inlineCallbacks <EOL> def setUp ( self ) : <EOL> yield initDB ( self ) <EOL> self . user = yield User ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" , age = <NUM_LIT:10> ) . save ( ) <EOL> @ inlineCallbacks <EOL> def test_joinWheres_precedence ( self ) : <EOL> yield User ( first_name = "<STR_LIT>" ) . save ( ) <EOL> first = [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> last = [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> second = [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> last_or_second = utils . joinWheres ( last , second , joiner = '<STR_LIT>' ) <EOL> where = utils . joinWheres ( first , last_or_second , joiner = '<STR_LIT>' ) <EOL> results = yield User . count ( where = where ) <EOL> self . assertEqual ( <NUM_LIT:1> , results ) <EOL> def test_joinMultipleWheres_empty_arg ( self ) : <EOL> where = utils . joinMultipleWheres ( [ ] , joiner = '<STR_LIT>' ) <EOL> self . assertEqual ( where , [ ] ) <EOL> def test_joinMultipleWheres_single_where ( self ) : <EOL> where = [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> joined_where = utils . joinMultipleWheres ( [ where ] , joiner = '<STR_LIT>' ) <EOL> self . assertEqual ( where , joined_where ) <EOL> @ inlineCallbacks <EOL> def test_joinMultipleWheres ( self ) : <EOL> yield User ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" , age = <NUM_LIT:20> ) . save ( ) <EOL> first = [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> last = [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> age = [ '<STR_LIT>' , <NUM_LIT:20> ] <EOL> where = utils . joinMultipleWheres ( [ first , last , age ] , joiner = '<STR_LIT>' ) <EOL> results = yield User . count ( where = where ) <EOL> self . assertEqual ( <NUM_LIT:1> , results ) <EOL> def test_dictToWhere ( self ) : <EOL> self . assertEqual ( utils . dictToWhere ( { } ) , None ) <EOL> result = utils . dictToWhere ( { '<STR_LIT>' : '<STR_LIT>' } , "<STR_LIT>" ) <EOL> self . assertEqual ( result , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> result = utils . dictToWhere ( { '<STR_LIT>' : None } , "<STR_LIT>" ) <EOL> self . assertEqual ( result , [ "<STR_LIT>" , None ] ) <EOL> result = utils . dictToWhere ( OrderedDict ( [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] ) ) <EOL> self . assertEqual ( result , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> result = utils . dictToWhere ( OrderedDict ( [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] ) , "<STR_LIT>" ) <EOL> self . assertEqual ( result , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> result = utils . dictToWhere ( OrderedDict ( [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , None ) ] ) ) <EOL> self . assertEqual ( result , [ "<STR_LIT>" , "<STR_LIT>" , None ] ) <EOL> @ inlineCallbacks <EOL> def tearDown ( self ) : <EOL> yield tearDownDB ( self ) </s>
