Esempio n. 1
0
 def test_client_submit_empty_input(self, mock_urlopen):
     """
     Should return False if input is empty string
     """
     result = client.submit('', '', '')
     self.assertFalse(result.is_valid)
     self.assertEqual(['incorrect-captcha-sol'], result.error_codes)
Esempio n. 2
0
 def test_client_submit_empty_input(self, mock_urlopen):
     """
     Should return False if input is empty string
     """
     result = client.submit('', '', '')
     self.assertFalse(result.is_valid)
     self.assertEqual(['incorrect-captcha-sol'], result.error_codes)
Esempio n. 3
0
 def test_client_submit_response_not_json(self, mock_urlopen):
     """
     Should return json read error if response is not json
     """
     mock_resp = mock.Mock()
     mock_resp.read.return_value = "{'success': True, 'error-codes': []}"
     mock_urlopen.return_value = mock_resp
     result = client.submit('a', 'a', 'a')
     self.assertFalse(result.is_valid)
     self.assertEqual(result.error_codes, ['json-read-issue'])
Esempio n. 4
0
 def test_client_submit_response_not_json(self, mock_urlopen):
     """
     Should return json read error if response is not json
     """
     mock_resp = mock.Mock()
     mock_resp.read.return_value = "{'success': True, 'error-codes': []}"
     mock_urlopen.return_value = mock_resp
     result = client.submit('a', 'a', 'a')
     self.assertFalse(result.is_valid)
     self.assertEqual(result.error_codes, ['json-read-issue'])
Esempio n. 5
0
 def test_client_submit_response_incorrect(self, mock_urlopen):
     """
     Should return false if response is incorrect
     """
     mock_resp = mock.Mock()
     mock_resp.read.return_value = json.dumps(
         {'success': False, 'error-codes': ['ERROR']})
     mock_urlopen.return_value = mock_resp
     result = client.submit('a', 'a', 'a')
     self.assertFalse(result.is_valid)
     self.assertEqual(result.error_codes, ['ERROR'])
Esempio n. 6
0
 def test_client_submit_correct(self, mock_urlopen):
     """
     Should return True if response is correct
     """
     mock_resp = mock.Mock()
     mock_resp.read.return_value = json.dumps(
         {'success': True, 'error-codes': []})
     mock_urlopen.return_value = mock_resp
     result = client.submit('a', 'a', 'a')
     self.assertTrue(result.is_valid)
     self.assertEqual(result.error_codes, None)
Esempio n. 7
0
 def test_client_submit_response_incorrect(self, mock_urlopen):
     """
     Should return false if response is incorrect
     """
     mock_resp = mock.Mock()
     mock_resp.read.return_value = json.dumps({
         'success': False,
         'error-codes': ['ERROR']
     })
     mock_urlopen.return_value = mock_resp
     result = client.submit('a', 'a', 'a')
     self.assertFalse(result.is_valid)
     self.assertEqual(result.error_codes, ['ERROR'])
Esempio n. 8
0
 def test_client_submit_correct(self, mock_urlopen):
     """
     Should return True if response is correct
     """
     mock_resp = mock.Mock()
     mock_resp.read.return_value = json.dumps({
         'success': True,
         'error-codes': []
     })
     mock_urlopen.return_value = mock_resp
     result = client.submit('a', 'a', 'a')
     self.assertTrue(result.is_valid)
     self.assertEqual(result.error_codes, None)