Пример #1
0
    def test_logs_unknown_qual(self, fake_log):
        fake_log\
            .expects_call()\
            .with_args(arg.contains('Unknown operator'), WARNING, hint=arg.contains('Implement'))

        options = {
            'filename':
            os.path.join(TEST_FILES_DIR,
                         'rowid_int_col1_str_header_and_100_rows_gzipped.msg')
        }
        columns = ['rowid', 'col1']
        wrapper = PartitionMsgpackForeignDataWrapper(options, columns)
        quals = [Qual('col1', '?', '3')]
        list(wrapper.execute(quals, columns))
Пример #2
0
 def test_positive_case(self, fake_post, fake_get, fake_is_path_exist,
                        fake_save):
     url = 'api.forvo.com'
     expected_data = {
         "action": "word-pronunciations",
         "format": "json",
         "id_lang_speak": "39",
         "id_order": "",
         "limit": "",
         "rate": "",
         "send": "",
         "username": "",
         "word": "fake_word"
     }
     fake_post.expects_call().with_args(
         arg.contains(url), data=expected_data).returns(
             FakeRequestsResponse(
                 ('<html><div class="intro"><pre>'
                  ' {&quot;items&quot;: ['
                  '{&quot;code&quot;: &quot;en&quot;, '
                  '&quot;country&quot;: &quot;United States&quot;, '
                  '&quot;pathmp3&quot;: &quot;mp3\/url\/&quot;}'
                  ']}'
                  ' </pre></html>')))
     fake_get.expects_call().returns(FakeRequestsResponse(b'0x11'))
     fake_is_path_exist.expects_call().returns(True)
     fake_save.expects_call().returns(None)
     test_word = ForvoImporter('fake_word')
     res = test_word.import_sound()
     # TODO check if file saved
     self.assertEqual(res, None)
Пример #3
0
 def test_if_forvo_json_does_not_have_required_keys(self, fake_post):
     url = 'api.forvo.com'
     expected_data = {
         "action": "word-pronunciations",
         "format": "json",
         "id_lang_speak": "39",
         "id_order": "",
         "limit": "",
         "rate": "",
         "send": "",
         "username": "",
         "word": "fake_word"
     }
     html_response = ('<div class="intro"><pre> {&quot;items&quot;:'
                      ' [{&quot;pathmp777&quot;: &quot;mp3_url&quot;, '
                      '&quot;code&quot;: &quot;en&quot;,'
                      '&quot;country&quot;: &quot;United States&quot;}]} '
                      '</pre></div>')
     fake_post.expects_call().with_args(
         arg.contains(url),
         data=expected_data).returns(FakeRequestsResponse(html_response))
     test_word = ForvoImporter('fake_word')
     with self.assertLogs(logger='general',
                          level='ERROR') as general, self.assertLogs(
                              logger='forvo_fails', level='ERROR') as forvo:
         test_word.import_sound()
     self.assertEqual([*general.output, *forvo.output], [
         'ERROR:general:JSON response from Forvo does not have required keys',
         'ERROR:forvo_fails:fake_word'
     ])
Пример #4
0
 def test_11(self, fake_post, fake_get, fake_mkdir):
     url = 'api.forvo.com'
     expected_data = {
         "action": "word-pronunciations",
         "format": "json",
         "id_lang_speak": "39",
         "id_order": "",
         "limit": "",
         "rate": "",
         "send": "",
         "username": "",
         "word": "fake_word1"
     }
     mp3_file = b'1234567890'
     html_response = ('<div class="intro"><pre> {&quot;items&quot;:'
                      ' [{&quot;pathmp3&quot;: &quot;mp3_url&quot;, '
                      '&quot;code&quot;: &quot;en&quot;,'
                      '&quot;country&quot;: &quot;United States&quot;}]} '
                      '</pre></div>')
     fake_post.expects_call().with_args(
         arg.contains(url),
         data=expected_data).returns(FakeRequestsResponse(html_response))
     fake_get.expects_call().returns(FakeRequestsResponse(mp3_file))
     fake_mkdir.expects_call().with_args()
     test_word = ForvoImporter('fake_word1')
     test_word.import_sound()
Пример #5
0
 def test_uses_requests_to_raise_connection_error_mp3(
         self, fake_post, fake_get):
     url = 'api.forvo.com'
     expected_data = {
         "action": "word-pronunciations",
         "format": "json",
         "id_lang_speak": "39",
         "id_order": "",
         "limit": "",
         "rate": "",
         "send": "",
         "username": "",
         "word": "fake_word"
     }
     html_response = ('<div class="intro"><pre> {&quot;items&quot;:'
                      ' [{&quot;pathmp3&quot;: &quot;mp3_url&quot;, '
                      '&quot;code&quot;: &quot;en&quot;,'
                      '&quot;country&quot;: &quot;United States&quot;}]} '
                      '</pre></div>')
     fake_post.expects_call().with_args(
         arg.contains(url),
         data=expected_data).returns(FakeRequestsResponse(html_response))
     fake_get.expects_call().raises(requests.exceptions.ConnectionError)
     test_word = ForvoImporter('fake_word')
     with self.assertLogs(logger='general',
                          level='ERROR') as general, self.assertLogs(
                              logger='forvo_fails', level='ERROR') as forvo:
         test_word.import_sound()
     self.assertEqual(
         [*general.output, *forvo.output],
         ['ERROR:general:Connection error', 'ERROR:forvo_fails:fake_word'])
Пример #6
0
    def test_positive_case(self, fake_get, fake_open):

        class FakeFile:
            def write(self, *args, **kwargs):
                pass

        class FakeContextManager:
            def __enter__(self):
                return FakeFile()

            def __exit__(self, *args):
                pass

        url = 'https://od-api.oxforddictionaries.com'
        expected_headers = {'app_id': 'test_app_id',
                            'app_key': 'test_app_key'}
        dir_path = os.path.join(settings.BASE_DIR, 'media', 'od')
        fake_get.expects_call().with_args(arg.contains(
            url), headers=expected_headers).returns(
            FakeRequestsResponse('{"article": "article"}'))
        fake_open.expects_call().returns(FakeContextManager())
        test_word = ODImporter('fifth')
        msg = test_word.create_word_article(dir_path, 'test_app_id',
                                            'test_app_key')
        self.assertEqual(msg, 'Data successfully saved')
Пример #7
0
 def test_if_forvo_html_response_has_unexpected_structure(self, fake_post):
     url = 'api.forvo.com'
     expected_data = {
         "action": "word-pronunciations",
         "format": "json",
         "id_lang_speak": "39",
         "id_order": "",
         "limit": "",
         "rate": "",
         "send": "",
         "username": "",
         "word": "fake_word"
     }
     fake_post.expects_call().with_args(
         arg.contains(url), data=expected_data).returns(
             FakeRequestsResponse('some unexpected html code'))
     test_word = ForvoImporter('fake_word')
     with self.assertLogs(logger='general',
                          level='ERROR') as general, self.assertLogs(
                              logger='forvo_fails', level='ERROR') as forvo:
         test_word.import_sound()
     self.assertEqual([*general.output, *forvo.output], [
         'ERROR:general:Unexpected HTML Response from Forvo',
         'ERROR:forvo_fails:fake_word'
     ])
Пример #8
0
    def test_logs_unknown_qual(self, fake_log):
        fake_log.expects_call().with_args(arg.contains("Unknown operator"), WARNING, hint=arg.contains("Implement"))

        options = {"filename": os.path.join(TEST_FILES_DIR, "rowid_int_col1_str_header_and_100_rows_gzipped.msg")}
        columns = ["rowid", "col1"]
        wrapper = PartitionMsgpackForeignDataWrapper(options, columns)
        quals = [Qual("col1", "?", "3")]
        list(wrapper.execute(quals, columns))
Пример #9
0
 def test_contains_list(self):
     db = Fake("db").expects("execute_statements").with_args(
                                         arg.contains("select * from foo"))
     db.execute_statements([
         "update foo",
         "select * from foo",
         "drop table foo"
     ])
     fudge.verify()
Пример #10
0
 def test_contains_list(self):
     db = Fake("db").expects("execute_statements").with_args(
                                         arg.contains("select * from foo"))
     db.execute_statements([
         "update foo",
         "select * from foo",
         "drop table foo"
     ])
     fudge.verify()
Пример #11
0
    def test_mail_contains_text_for_claiming_via_url(self, mock_send_mail):
        user = mommy.make(settings.AUTH_USER_MODEL)
        self.bid1.ask_match_sent = timezone.now()
        self.bid1.save()

        mock_send_mail.expects_call().with_args(arg.any(),
                                                arg.contains(self.bid1.url),
                                                arg.any(), ['*****@*****.**'])

        mommy.make(Bid, offer=100, user=user, ask=1000, url=self.url)
Пример #12
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')
Пример #13
0
    def test_mail_contains_text_for_claiming_via_url(self, mock_send_mail):
        user = mommy.make(settings.AUTH_USER_MODEL)
        self.bid1.ask_match_sent = timezone.now()
        self.bid1.save()

        mock_send_mail.expects_call().with_args(
            arg.any(),
            arg.contains(self.bid1.url),
            arg.any(),
            ['*****@*****.**']
        )

        mommy.make(
            Bid, offer=100, user=user, ask=1000, url=self.url
        )
Пример #14
0
 def test_uses_requests_to_get_html_from_forvo(self, fake_post):
     url = 'api.forvo.com'
     expected_data = {
         "action": "word-pronunciations",
         "format": "json",
         "id_lang_speak": "39",
         "id_order": "",
         "limit": "",
         "rate": "",
         "send": "",
         "username": "",
         "word": "fake_word"
     }
     fake_post.expects_call().with_args(
         arg.contains(url),
         data=expected_data).returns(FakeRequestsResponse('some html code'))
     test_word = ForvoImporter('fake_word')
     res = test_word.get_html_from_forvo()
     self.assertEqual(res, 'some html code')
Пример #15
0
 def test_1_if_forvo_json_does_not_have_required_keys(self, fake_post):
     url = 'api.forvo.com'
     expected_data = {
         "action": "word-pronunciations",
         "format": "json",
         "id_lang_speak": "39",
         "id_order": "",
         "limit": "",
         "rate": "",
         "send": "",
         "username": "",
         "word": "fake_word"
     }
     html_response = (
         '<div class="intro"><pre> {&quot;items&quot;:'
         ' [{&quot;pathmp3&quot;: &quot;mp3_url&quot;, '
         '&quot;not_code&quot;: &quot;en&quot;,'
         '&quot;not_country1&quot;: &quot;United States&quot;}]} '
         '</pre></div>')
     fake_post.expects_call().with_args(
         arg.contains(url),
         data=expected_data).returns(FakeRequestsResponse(html_response))
     test_word = ForvoImporter('fake_word')
     test_word.import_sound()
Пример #16
0
 def test_contains_fail(self):
     db = Fake("db").expects("execute").with_args(arg.contains("table foo"))
     db.execute("select into table notyourmama;")
     fudge.verify()
Пример #17
0
 def test_contains_str(self):
     db = Fake("db").expects("execute").with_args(arg.contains("table foo"))
     db.execute("select into table foo;")
     db.execute("select * from table foo where bar = 1")
     fudge.verify()
Пример #18
0
 def test_contains_str(self):
     db = Fake("db").expects("execute").with_args(arg.contains("table foo"))
     db.execute("select into table foo;")
     db.execute("select * from table foo where bar = 1")
     fudge.verify()
Пример #19
0
 def test_contains_fail(self):
     db = Fake("db").expects("execute").with_args(arg.contains("table foo"))
     db.execute("select into table notyourmama;")
     fudge.verify()