def test_post_index_page_with_expired_token(self): token = make_token() data = {"greeting": "hello", "_onetimetoken": token} mock_settings = Config(dict(PAGE_LOADER=settings.PAGE_LOADER, TOKEN_EXPIRES=0)) with mock.patch("confpages.token.settings", mock_settings): response = client.post("/p/index/", data) self.assertEqual(response.status_code, 403) self.assertEqual(response.content, "Expired one-time token")
def test_post_index_page_with_expired_token(self): token = make_token() data = {'greeting': 'hello', '_onetimetoken': token} mock_settings = Config(dict( PAGE_LOADER=settings.PAGE_LOADER, TOKEN_EXPIRES=0 )) with mock.patch('confpages.token.settings', mock_settings): response = client.post('/p/index/', data) self.assertEqual(response.status_code, 403) self.assertEqual(response.content, 'Expired one-time token')
def test_post_index_page_successful(self): token = make_token() data = {"greeting": "hello", "_onetimetoken": token} with mock.patch("confpages.views.ConfPages.client.request") as mock_request: mock_request.return_value = DummyResponse( content="The form submission is successful", status_code=200, headers={"Content-Type": "application/json"}, ) response = client.post("/p/index/", data) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, "The form submission is successful") self.assertEqual(response["Content-Type"], "application/json")
def test_post_index_page_successful(self): token = make_token() data = {'greeting': 'hello', '_onetimetoken': token} with mock.patch('confpages.views.ConfPages.client.request') \ as mock_request: mock_request.return_value = DummyResponse( content='The form submission is successful', status_code=200, headers={'Content-Type': 'application/json'} ) response = client.post('/p/index/', data) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, 'The form submission is successful') self.assertEqual(response['Content-Type'], 'application/json')
def test_post_index_page_with_nonexistent_api_url(self): token = make_token() data = {"greeting": "hello", "_onetimetoken": token} response = client.post("/p/index/", data) self.assertEqual(response.status_code, 500) self.assertEqual(response.content, "The backend API can not be found")
def test_post_index_page_without_api_url(self): token = make_token() data = {"greeting": "hello", "_onetimetoken": token} response = client.post("/p/index/", data) self.assertEqual(response.status_code, 405) self.assertEqual(response["Allow"], "GET")
def test_post_index_page_with_nonexistent_api_url(self): token = make_token() data = {'greeting': 'hello', '_onetimetoken': token} response = client.post('/p/index/', data) self.assertEqual(response.status_code, 500) self.assertEqual(response.content, 'The backend API can not be found')
def test_post_index_page_without_api_url(self): token = make_token() data = {'greeting': 'hello', '_onetimetoken': token} response = client.post('/p/index/', data) self.assertEqual(response.status_code, 405) self.assertEqual(response['Allow'], 'GET')