Hi!
On 07/30/2018 05:04 PM, Kasper Laudrup wrote:
> Hi Birger,
>
> On 2018-07-30 16:12, Birger Schacht wrote:
>> i'm using my own PasswordResetTokenGenerator which has a timeout that is
>> not given in days but hours, to make the password token timeout more
>> fine grained. Is there a way to test such a timeout in Django tests,
>> i.e. something that lets the unit test use a fake time in the future?
>>
>
> You can mock out pretty much everything using the mock module in the
> standard Python unittest library that Django already uses.
>
> Depending on your code of course, but something like:
>
> @mock.path('os.time.now')
> def test_my_token(self, mock_now):
> mock_now.return_value = datetime(3000, 12, 31)
> # The rest of your test code goes here
>
> Now your code should see the current time as being new years 3000.
>
> I haven't tested this and there might be better ways to do that, but
> that's how I would handle it. Hope that helps.
thanks, that did the trick!
cheers,
Birger
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ce3eeff8-2bc5-c687-1777-414e2316e0cc%40rantanplan.org.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment