2 ms·
My experience with time is that whenever you build a system that is time-dependent in any meaningful way, you want to have "synthetic time" that you control, wh
by mpweiher 12y ago
My experience with time is that whenever you build a system that is time-dependent in any meaningful way, you want to have "synthetic time" that you control, which you only feed with real time in a single, controllable place.
Otherwise you get nasty effects, such as time moving on while your system is processing etc.
- meric 12y agoI'm guessing you mean like: def has_expired(now=None): #.. implementation instead of: def has_expired(): #.. implementation But at some point you need to call that method somewhere else... def get_request_handler(request): #...code now = timezone.now() if has_expired(now=now): raise Error403. And `get_request_handler` still needs to be tested, which I 'stub' the API for getting the current time in the correct timezone within the test for the request. (Taking into account the other comment), using a library called 'mock'. (https://pypi.python.org/pypi/mock https://pypi.python.org/pypi/mock)