def test_post__when_form_is_not_valid(self): lv = LoginView() request = WSGIRequest({ 'REQUEST_METHOD': 'POST', 'PATH_INFO': 'accounts:login', 'wsgi.input': StringIO()}) mock_wsgi_session_context() expect = render( request, 'accounts/login.html', {'form': LoginForm(data=request.POST)} ) result = lv.post(request) self.assertEqual( remove_csrf(result.content.decode('utf-8')), remove_csrf(expect.content.decode('utf-8')) )
def test_post__when_form_is_valid(self, mock_form): mock_form.return_value.is_valid.return_value = True def getitem(name): return COR_APPUSER_DATA_1st['username'] mock_form.return_value.data = MagicMock() mock_form.return_value.data.__getitem__.side_effect = getitem lv = LoginView() request = WSGIRequest({ 'REQUEST_METHOD': 'POST', 'PATH_INFO': 'accounts:login', 'wsgi.input': StringIO()}) mock_wsgi_session_context() expect = redirect('travel:place_list') result = lv.post(request) self.assertEqual( remove_csrf(result.content.decode('utf-8')), remove_csrf(expect.content.decode('utf-8')) )