我的应用程序根据作为自定义 URL 的输入提供的日期和时间提供状态。通常它会使用当前时间(datetime.now()),但我想创建单元测试来验证未来的时间。但是,我在使用时间戳作为测试变量时遇到了问题。想法?这是到目前为止的代码:
网址.py:
urlpatterns = patterns('',
(r'^/(\w+)/status/$', 'app.views.fetch_status'),
# Normally:
#(r'^/(\w+)/status/$', 'app.views.fetch_status', {'timestamp': datetime.now() }),
...
视图.py:
def fetch_status(request, slug, timestamp):
...
测试.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')
结果:
TypeError: fetch_status() takes exactly 2 arguments (1 given)