def test_post__when_form_is_not_valid(self): suv = SignUpView() request = WSGIRequest({ 'REQUEST_METHOD': 'POST', 'PATH_INFO': 'accounts:signup', 'wsgi.input': StringIO()}) mock_wsgi_session_context() expect = render( request, 'accounts/signup.html', {'form': SignUpForm(data=request.POST)} ) result = suv.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 mock_form.return_value.save.return_value = AppUser.objects.get( id=COR_APPUSER_DATA_1st['id']) def getitem(name): return COR_APPUSER_DATA_1st['password'] mock_form.return_value.data = MagicMock() mock_form.return_value.data.__getitem__.side_effect = getitem suv = SignUpView() request = WSGIRequest({ 'REQUEST_METHOD': 'POST', 'PATH_INFO': 'accounts:signup', 'wsgi.input': StringIO()}) mock_wsgi_session_context() expect = redirect('travel:place_list') result = suv.post(request) self.assertEqual( remove_csrf(result.content.decode('utf-8')), remove_csrf(expect.content.decode('utf-8')) )