示例#1
0
 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")
示例#2
0
 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')
示例#3
0
 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")
示例#4
0
 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')
示例#5
0
 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")
示例#6
0
 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")
示例#7
0
 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')
示例#8
0
 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')