Exemple #1
0
 def test_uses_requests_to_raise_not_404_http_error(self, fake_get):
     http_error = 418
     fake_get.expects_call().raises(requests.exceptions
                                    .HTTPError(http_error))
     test_word = ODImporter('fourth')
     msg, res = test_word.get_article('', '')
     self.assertEqual(msg, 'HTTP error occurred: {}'.format(
         requests.exceptions.HTTPError(http_error)))
Exemple #2
0
 def test_uses_requests_to_raise_404_error(self, fake_get):
     http_error = 404
     fake_get.expects_call().raises(requests.exceptions
                                    .HTTPError(http_error))
     test_word = ODImporter('qwerty')
     msg, res = test_word.get_article('', '')
     self.assertEqual(msg, 'Word "qwerty" does not exist'
                           ' in Oxford Dictionary')
Exemple #3
0
 def test_uses_requests_to_get_article_from_od(self, fake_get):
     url = 'https://od-api.oxforddictionaries.com'
     expected_headers = {'app_id': 'test_app_id', 'app_key': 'test_app_key'}
     fake_get.expects_call().with_args(arg.contains(url),
                                       headers=expected_headers).returns(
                                           FakeRequestsResponse('{}'))
     test_word = ODImporter('something')
     msg, res = test_word.get_article(
         settings.OXFORD_DICTIONARY_CONFIG[0]['app_id'],
         settings.OXFORD_DICTIONARY_CONFIG[0]['app_key'])
     self.assertEqual(msg, 'Data successfully saved')
Exemple #4
0
 def test_uses_requests_to_raise_connection_error(self, fake_get):
     fake_get.expects_call().raises(requests.exceptions.ConnectionError)
     test_word = ODImporter('second')
     msg, res = test_word.get_article('', '')
     self.assertEqual(msg, 'Connection error')