My application provides a status depending on the date and time of day that is provided as input to a custom URL. Normally it will use the current time (datetime.now()), but I'd like to create unit tests to verify future times. However, I'm having trouble using a timestamp as the variable to test. Ideas? Here is the code so far:
urls.py:
urlpatterns = patterns('',
(r'^/(\w+)/status/$', 'app.views.fetch_status'),
# Normally:
#(r'^/(\w+)/status/$', 'app.views.fetch_status', {'timestamp': datetime.now() }),
...
views.py:
def fetch_status(request, slug, timestamp):
...
tests.py:
class TimeTests(TestCase):
fixtures = ['hours.json']
def testSchedule(self):
timestamp = datetime(2012, 6, 19, 5, 0)
client = Client()
response = client.get('/service/status/', {'timestamp': timestamp})
self.assertEqual(response.context['status'], 'closed')
Result:
TypeError: fetch_status() takes exactly 2 arguments (1 given)