commit 70ebb197a112bbc832bf8528b69dcfc164288539
Author: Roman Podoliaka <email address hidden>
Date: Fri Jan 17 16:26:24 2014 +0200
Fix mocking of utcnow() for model datetime cols
Now when we are going to deprecate timeutils.set_time_override()
and use mock instead, it easy to hit the following gotcha: when
testr does tests discovering, it imports all modules within a given
directory and it might happen that common.db.sqlalchemy.models
is imported before timeutils.utcnow() is mocked in a test case.
In this case the SQLAlchemy model will save the reference to the
original timeutils.utcnow() function, which will be called later
when the model will be saved to a DB, if created_at or updated_at
value aren't provided.
In order to overcome this we can defer resolution of timeutils.utcnow
reference by passing lambda functions to SA Column __init__().
Reviewed: https:/ /review. openstack. org/67484 /git.openstack. org/cgit/ openstack/ oslo-incubator/ commit/ ?id=70ebb197a11 2bbc832bf8528b6 9dcfc164288539
Committed: https:/
Submitter: Jenkins
Branch: master
commit 70ebb197a112bbc 832bf8528b69dcf c164288539
Author: Roman Podoliaka <email address hidden>
Date: Fri Jan 17 16:26:24 2014 +0200
Fix mocking of utcnow() for model datetime cols
Now when we are going to deprecate timeutils. set_time_ override( ) db.sqlalchemy. models
and use mock instead, it easy to hit the following gotcha: when
testr does tests discovering, it imports all modules within a given
directory and it might happen that common.
is imported before timeutils.utcnow() is mocked in a test case.
In this case the SQLAlchemy model will save the reference to the
original timeutils.utcnow() function, which will be called later
when the model will be saved to a DB, if created_at or updated_at
value aren't provided.
In order to overcome this we can defer resolution of timeutils.utcnow
reference by passing lambda functions to SA Column __init__().
Related-Bug: #1266962
Change-Id: I7adce90eacb4a3 f334d77da7b4a17 6c31ff818ed