I create a unit test that add new ProjApp object to the database, but the returned object shows it is not the same object inserted, I don't follow why it's like this because I have others tests on inserting a row to a different table, and returned shows the same row object.
Test result:
self.assertIs(internship_app_rst, internship_app)
AssertionError: <project.models.ProjectApp object at 0x0000000003EE7E10> is not <project.models.ProjectApp object at 0x0
000000003EE7710>
Test:
def create_new_internship_app(self, student):
internship_app = ProjectApp(
app_id=None,
created_datetime=datetime.date.today(),
proj_title='Long story'
)
mydb.session.add(internship_app)
mydb.session.commit()
internship_app_rst = mydb.session.query(ProjectApp).first()
self.assertIs(internship_app_rst, internship_app)
Model:
class Application(mydb.Model):
__tablename__ = 'APPLICATION'
app_id = mydb.Column(mydb.Integer, primary_key = True)
created_datetime = mydb.Column(mydb.DateTime(), primary_key = True)
app_description = mydb.Column(mydb.Text())
app_category = mydb.Column(mydb.String(30))
case_owner_obj = mydb.relationship('Staff', backref='application_list')
__mapper_args__ = {
'polymorphic_identity':'application',
'polymorphic_on':app_category
}
class ProjectApp(Application):
__tablename__ = 'PROJECT_APP'
__table_args__ = (
mydb.ForeignKeyConstraint(
['app_id','created_datetime'],
['APPLICATION.app_id', 'APPLICATION.created_datetime']
),
)
app_id = mydb.Column(mydb.Integer, primary_key = True)
created_datetime = mydb.Column(mydb.DateTime(), primary_key = True)
proj_title = mydb.Column(mydb.Text())
__mapper_args__ = {
'polymorphic_identity':'projApp',
}