<s> from __future__ import absolute_import <EOL> import sqlalchemy as sa <EOL> from tests import FormRelationsTestCase <EOL> from wtforms_alchemy import utils <EOL> class TestUtils ( FormRelationsTestCase ) : <EOL> def create_models ( self ) : <EOL> class Band ( self . base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = sa . Column ( sa . Integer , primary_key = True ) <EOL> name = sa . Column ( sa . Unicode ( <NUM_LIT:255> ) , nullable = False ) <EOL> class Person ( self . base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = sa . Column ( sa . Integer , primary_key = True ) <EOL> name = sa . Column ( sa . Unicode ( <NUM_LIT:255> ) , nullable = False ) <EOL> class BandMember ( self . base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> band_id = sa . Column ( sa . Integer , sa . ForeignKey ( Band . id ) , <EOL> primary_key = True ) <EOL> band = sa . orm . relationship ( Band , backref = '<STR_LIT>' ) <EOL> person_id = sa . Column ( sa . Integer , sa . ForeignKey ( Person . id ) , <EOL> primary_key = True ) <EOL> person = sa . orm . relationship ( Person , <EOL> backref = sa . orm . backref ( '<STR_LIT>' , <EOL> uselist = False ) ) <EOL> role = sa . Column ( sa . Unicode ( <NUM_LIT:255> ) , nullable = False ) <EOL> def __repr__ ( self ) : <EOL> fmt = '<STR_LIT>' <EOL> return fmt . format ( repr ( self . band_id ) , repr ( self . person_id ) , <EOL> id ( self ) ) <EOL> self . Band = Band <EOL> self . Person = Person <EOL> self . BandMember = BandMember <EOL> def create_forms ( self ) : <EOL> pass <EOL> def test_find_entity ( self ) : <EOL> band = self . Band ( name = u'<STR_LIT>' ) <EOL> self . session . add ( band ) <EOL> singer = self . Person ( name = u'<STR_LIT>' ) <EOL> self . BandMember ( band = band , person = singer , role = u'<STR_LIT>' ) <EOL> guitarist = self . Person ( name = u'<STR_LIT>' ) <EOL> self . BandMember ( band = band , person = guitarist , role = u'<STR_LIT>' ) <EOL> self . session . commit ( ) <EOL> sing_data = dict ( band_id = band . id , person_id = singer . id , role = u'<STR_LIT>' ) <EOL> guitar_data = dict ( <EOL> band_id = band . id , <EOL> person_id = guitarist . id , <EOL> role = u'<STR_LIT>' <EOL> ) <EOL> assert ( utils . find_entity ( band . members , self . BandMember , sing_data ) <EOL> is singer . band_role ) <EOL> assert ( utils . find_entity ( band . members , self . BandMember , guitar_data ) <EOL> is guitarist . band_role ) </s>
