Created
June 2, 2015 09:17
-
-
Save komuw/2cbb0982528365b91bab to your computer and use it in GitHub Desktop.
fake(mock) datetime in python (django)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DateTimefaker(datetime): | |
""" | |
fake datetime to use your own custom datetimes | |
""" | |
def __new__(cls, *args, **kwargs): | |
return datetime.__new__(datetime, *args, **kwargs) | |
class TestSomething(TestCase): | |
fixtures = ['test_data'] | |
@mock.patch('module.tasks.datetime', DateTimefaker) | |
def test_something(self): | |
DateTimefaker.today = classmethod(lambda cls: datetime(2014, 2, 28)) | |
client = Client() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment