diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index a6ed364c..fd909b32 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -38,7 +38,7 @@ jobs: pip install --upgrade pip pip install -r requirements.txt -r requirements_dev.txt - name: Test - run: python setup.py test + run: pytest tests/ - name: Lint run: | flake8 tests --ignore=F401,W504,E731,E123,E125,E127,E128,E501 diff --git a/setup.py b/setup.py index 4b2096ca..ce3f5f30 100644 --- a/setup.py +++ b/setup.py @@ -68,8 +68,5 @@ def parse_requirements(filehandle): 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', ], - setup_requires=['pytest-runner==4.2'], - test_suite='tests', - tests_require=test_requirements, url='https://github.com/revdotcom/revai-python-sdk', ) diff --git a/src/rev_ai/__init__.py b/src/rev_ai/__init__.py index 30e64704..7cc7fa04 100644 --- a/src/rev_ai/__init__.py +++ b/src/rev_ai/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Top-level package for rev_ai""" -__version__ = '2.21.0' +__version__ = '2.22.0' from .models import Job, JobStatus, Account, Transcript, Monologue, Element, MediaConfig, \ CaptionType, GroupChannelsType, CustomVocabulary, TopicExtractionJob, TopicExtractionResult, \ diff --git a/src/rev_ai/apiclient.py b/src/rev_ai/apiclient.py index 8f4d91fb..4c41d97b 100644 --- a/src/rev_ai/apiclient.py +++ b/src/rev_ai/apiclient.py @@ -817,7 +817,11 @@ def _create_job_options_payload( translation_config: TranslationOptions = None): payload = {} if media_url: - payload['media_url'] = media_url + if source_config: + raise ValueError( + 'media_url is not compatible with source_config. ' + 'Use source_config for all URL-based submissions.') + payload['source_config'] = {'url': media_url} if skip_diarization: payload['skip_diarization'] = skip_diarization if skip_punctuation: @@ -842,7 +846,7 @@ def _create_job_options_payload( payload['custom_vocabulary_id'] = custom_vocabulary_id if transcriber: payload['transcriber'] = transcriber - if verbatim: + if verbatim is not None: payload['verbatim'] = verbatim if rush: payload['rush'] = rush diff --git a/tests/test_async_summarization.py b/tests/test_async_summarization.py index 7b1746e8..ab6d2803 100644 --- a/tests/test_async_summarization.py +++ b/tests/test_async_summarization.py @@ -112,7 +112,7 @@ def test_submit_source_url(self, mock_session, make_mock_response): "POST", JOBS_URL, json={ - 'media_url': 'https://example.com/test.mp3', + 'source_config': {'url': 'https://example.com/test.mp3'}, 'language': 'en', 'summarization_config': { 'prompt': "Try to summarize this transcript as good as you possibly can", diff --git a/tests/test_async_translation.py b/tests/test_async_translation.py index 0e368898..0dfdede6 100644 --- a/tests/test_async_translation.py +++ b/tests/test_async_translation.py @@ -147,7 +147,7 @@ def test_submit_source_url(self, mock_session, make_mock_response): "POST", JOBS_URL, json={ - 'media_url': 'https://example.com/test.mp3', + 'source_config': {'url': 'https://example.com/test.mp3'}, 'language': 'en', 'translation_config': { 'target_languages': [ diff --git a/tests/test_job.py b/tests/test_job.py index 4f0cdf2d..1dc0ff0c 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -162,7 +162,7 @@ def test_submit_job_url_with_success(self, mock_session, make_mock_response): "POST", JOBS_URL, json={ - 'media_url': SOURCE_URL, + 'source_config': {'url': SOURCE_URL}, 'callback_url': NOTIFICATION_URL, 'metadata': METADATA, 'skip_diarization': True, @@ -276,7 +276,7 @@ def test_submit_job_url_with_human_transcription_and_success(self, mock_session, 'POST', JOBS_URL, json={ - 'media_url': SOURCE_URL, + 'source_config': {'url': SOURCE_URL}, 'transcriber': 'human', 'verbatim': True, 'segments_to_transcribe': segments, @@ -284,6 +284,77 @@ def test_submit_job_url_with_human_transcription_and_success(self, mock_session, }, headers=client.default_headers) + def test_submit_job_url_with_media_url_and_source_config_conflict(self, mock_session): + """Passing both media_url and source_config should raise ValueError.""" + client = RevAiAPIClient(TOKEN) + + with pytest.raises(ValueError, match='media_url is not compatible with source_config'): + client.submit_job_url( + media_url=SOURCE_URL, + source_config=SOURCE_CONFIG + ) + + def test_submit_job_url_verbatim_false(self, mock_session, make_mock_response): + """verbatim=False should be included in payload.""" + data = { + 'id': JOB_ID, + 'status': 'in_progress', + 'created_on': CREATED_ON, + } + response = make_mock_response(url=JOB_ID_URL, json_data=data) + mock_session.request.return_value = response + client = RevAiAPIClient(TOKEN) + + client.submit_job_url(SOURCE_URL, verbatim=False) + + mock_session.request.assert_called_once_with( + 'POST', + JOBS_URL, + json={ + 'source_config': {'url': SOURCE_URL}, + 'verbatim': False, + }, + headers=client.default_headers) + + def test_submit_job_url_verbatim_true(self, mock_session, make_mock_response): + """verbatim=True should be included in payload.""" + data = { + 'id': JOB_ID, + 'status': 'in_progress', + 'created_on': CREATED_ON, + } + response = make_mock_response(url=JOB_ID_URL, json_data=data) + mock_session.request.return_value = response + client = RevAiAPIClient(TOKEN) + + client.submit_job_url(SOURCE_URL, verbatim=True) + + mock_session.request.assert_called_once_with( + 'POST', + JOBS_URL, + json={ + 'source_config': {'url': SOURCE_URL}, + 'verbatim': True, + }, + headers=client.default_headers) + + def test_submit_job_url_verbatim_none(self, mock_session, make_mock_response): + """verbatim=None (default) should NOT be included in payload.""" + data = { + 'id': JOB_ID, + 'status': 'in_progress', + 'created_on': CREATED_ON, + } + response = make_mock_response(url=JOB_ID_URL, json_data=data) + mock_session.request.return_value = response + client = RevAiAPIClient(TOKEN) + + client.submit_job_url(SOURCE_URL) + + call_kwargs = mock_session.request.call_args + payload = call_kwargs[1]['json'] if 'json' in call_kwargs[1] else call_kwargs[0][2] + assert 'verbatim' not in payload + def test_submit_job_local_file_with_success(self, mocker, mock_session, make_mock_response): created_on = '2018-05-05T23:23:22.29Z' data = {