def test_get_fields_many_to_many(self): """ Tests getting the fields for a many-to-many """ Base = declarative_base() association_table = Table( 'association', Base.metadata, Column('left_id', Integer, ForeignKey('left.id')), Column('right_id', Integer, ForeignKey('right.id')) ) class Parent(Base): __tablename__ = 'left' id = Column(Integer, primary_key=True) children = relationship("Child", secondary=association_table, backref='parents') class Child(Base): __tablename__ = 'right' id = Column(Integer, primary_key=True) resp = _get_fields_for_model(Parent) self.assertAllIn(resp, ('id', 'children.id',)) resp = _get_fields_for_model(Child) self.assertAllIn(resp, ('id', 'parents.id',))
def test_get_fields_many_to_many(self): """ Tests getting the fields for a many-to-many """ Base = declarative_base() association_table = Table( 'association', Base.metadata, Column('left_id', Integer, ForeignKey('left.id')), Column('right_id', Integer, ForeignKey('right.id'))) class Parent(Base): __tablename__ = 'left' id = Column(Integer, primary_key=True) children = relationship("Child", secondary=association_table, backref='parents') class Child(Base): __tablename__ = 'right' id = Column(Integer, primary_key=True) resp = _get_fields_for_model(Parent) self.assertAllIn(resp, ( 'id', 'children.id', )) resp = _get_fields_for_model(Child) self.assertAllIn(resp, ( 'id', 'parents.id', ))
def test_get_fields_for_model_many_to_one(self): """ Tests getting the fields for a many_to_one """ Base = declarative_base() class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True) child_id = Column(Integer, ForeignKey('child.id')) child = relationship("Child", backref="parents") class Child(Base): __tablename__ = 'child' id = Column(Integer, primary_key=True) resp = _get_fields_for_model(Parent) self.assertAllIn(resp, ('id', 'child.id', 'child_id')) resp = _get_fields_for_model(Child) self.assertAllIn(resp, ('id', 'parents.id',))
def test_get_fields_for_model(self): """ Tests a simple get_field_for_model """ Base = declarative_base() class MyModel(Base): __tablename__ = 'blah' id = Column(Integer, primary_key=True) value = Column(String) resp = _get_fields_for_model(MyModel) self.assertAllIn(('id', 'value',), resp)
def test_get_fields_for_model_many_to_one(self): """ Tests getting the fields for a many_to_one """ Base = declarative_base() class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True) child_id = Column(Integer, ForeignKey('child.id')) child = relationship("Child", backref="parents") class Child(Base): __tablename__ = 'child' id = Column(Integer, primary_key=True) resp = _get_fields_for_model(Parent) self.assertAllIn(resp, ('id', 'child.id', 'child_id')) resp = _get_fields_for_model(Child) self.assertAllIn(resp, ( 'id', 'parents.id', ))
def test_get_fields_for_model(self): """ Tests a simple get_field_for_model """ Base = declarative_base() class MyModel(Base): __tablename__ = 'blah' id = Column(Integer, primary_key=True) value = Column(String) resp = _get_fields_for_model(MyModel) self.assertAllIn(( 'id', 'value', ), resp)