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)
Why did you change the pattern to not include the timestamp parameter? From the looks of it, and based on your error, the function is expecting one more argument, which you are not really providing because you changed the pattern.