【发布时间】:2018-10-11 19:43:16
【问题描述】:
我正在尝试编写一个简单的测试,但是我的视图用嵌套的 user_passes_test 语句装饰。他们检查诸如条带订阅和 is_authenticated 之类的内容。我发现了各种帖子,例如this,其中解决了如何绕过带有补丁的装饰器,但我不太清楚如何将所有东西集成在一起。
tests.py
@patch('dashboard.views.authorised_base_user_checks', lambda func: func)
def test_dashboard_root_exists(self):
response = self.client.get('/dashboard/')
self.assertEqual(200, response.status_code)
视图中的装饰器
def authorised_base_user_checks(view_func):
decorated_view_func = login_required(user_active(subscriber_exists(subscriber_valid(view_func))))
return decorated_view_func
views.py
@authorised_base_user_checks
def IndexView(request):
...
上面还是没有通过装饰器。
谢谢!
【问题讨论】:
标签: django unit-testing mocking