diff --git a/.gitignore b/.gitignore index eeaf919596c..8ad9875dc3e 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ wheels/ MANIFEST package.json package-lock.json +coverage/ # PyInstaller # Usually these files are written by a python script from a template diff --git a/eng/pipelines/ci.yml b/eng/pipelines/ci.yml index 9a491c8425a..7be82bebfb6 100644 --- a/eng/pipelines/ci.yml +++ b/eng/pipelines/ci.yml @@ -9,7 +9,7 @@ pr: - autorestv3 variables: - NodeVersion: "12.x" + NodeVersion: "14.x" PythonVersion: "3.7" TestFolder: "$(Build.SourcesDirectory)/test/" AUTOREST_TESTSERVER_COVERAGE_DIRECTORY: "$(Build.SourcesDirectory)/coverage/" @@ -62,7 +62,6 @@ jobs: npm install -g autorest npm install displayName: 'Prepare Environment for Generation' - - script: | pylint autorest displayName: 'Pylint' @@ -207,6 +206,7 @@ jobs: npm run coverage -- publish --repo=$(Build.Repository.Name) --ref=$(Build.SourceBranch) --githubToken=$(github-token) --azStorageAccount=$(storage-coverage-user) --azStorageAccessKey=$(storage-coverage-pass) --coverageDirectory=$(AUTOREST_TESTSERVER_COVERAGE_DIRECTORY) workingDirectory: node_modules/@microsoft.azure/autorest.testserver displayName: "Publish coverage report to storage account" + condition: and(succeededOrFailed(), eq(variables['PythonVersion'], '3.10')) - ${{ if eq(and(ne(variables['Build.Reason'], 'PullRequest'), ne(variables['PythonVersion'], '2.7')), 'True') }}: - script: | diff --git a/eng/pipelines/publish-release.yml b/eng/pipelines/publish-release.yml index c3c1447b0b6..5724921e825 100644 --- a/eng/pipelines/publish-release.yml +++ b/eng/pipelines/publish-release.yml @@ -47,31 +47,41 @@ steps: cd $(TestFolder)/azure/legacy tox -e ci displayName: 'Execute legacy "azure" Tests - Python $(PythonVersion)' - - - script: | - cd $(TestFolder)/azure/version-tolerant - tox -e ci - displayName: 'Execute version tolerant "azure" Tests - Python $(PythonVersion)' - + - script: | cd $(TestFolder)/azure/low-level tox -e ci displayName: 'Execute low level "azure" Tests - Python $(PythonVersion)' - + + - script: | + cd $(TestFolder)/azure/version-tolerant + tox -e ci + displayName: 'Execute version tolerant "azure" Tests - Python $(PythonVersion)' + - script: | cd $(TestFolder)/vanilla/legacy tox -e ci displayName: 'Execute legacy "vanilla" Tests - Python $(PythonVersion)' - + + - script: | + cd $(TestFolder)/vanilla/low-level + tox -e ci + displayName: 'Execute low level "vanilla" Tests - Python $(PythonVersion)' + - script: | cd $(TestFolder)/vanilla/version-tolerant tox -e ci displayName: 'Execute version tolerant "vanilla" Tests - Python $(PythonVersion)' - + - script: | - cd $(TestFolder)/vanilla/low-level + cd $(TestFolder)/dpg/low-level tox -e ci - displayName: 'Execute low level "vanilla" Tests - Python $(PythonVersion)' + displayName: 'Execute low level "dpg" Tests - Python $(PythonVersion)' + + - script: | + cd $(TestFolder)/dpg/version-tolerant + tox -e ci + displayName: 'Execute version tolerant "dpg" Tests - Python $(PythonVersion)' - script: | export RELEASE_VERSION=$(node -p -e "require('./package.json').version") diff --git a/package.json b/package.json index aa83b7f2543..a2b26750eed 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@azure-tools/extension": "~3.2.1" }, "devDependencies": { - "@microsoft.azure/autorest.testserver": "^3.2.0" + "@microsoft.azure/autorest.testserver": "^3.3.5" }, "files": [ "autorest/**/*.py", diff --git a/test/azure/legacy/AcceptanceTests/conftest.py b/test/azure/legacy/AcceptanceTests/conftest.py index 49e217dae92..f117b2100ef 100644 --- a/test/azure/legacy/AcceptanceTests/conftest.py +++ b/test/azure/legacy/AcceptanceTests/conftest.py @@ -43,7 +43,7 @@ #Ideally this would be in a common helper library shared between the tests def start_server_process(): - cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver".format(cwd) + cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver/dist/cli/cli.js run --appendCoverage".format(cwd) if os.name == 'nt': #On windows, subprocess creation works without being in the shell return subprocess.Popen(cmd) diff --git a/test/azure/legacy/AcceptanceTests/test_zzz.py b/test/azure/legacy/AcceptanceTests/test_zzz.py index 1d995d0486c..76900bb6cf8 100644 --- a/test/azure/legacy/AcceptanceTests/test_zzz.py +++ b/test/azure/legacy/AcceptanceTests/test_zzz.py @@ -39,13 +39,13 @@ def test_ensure_coverage(self): report = client.get_report(platform.python_version()) # Add tests that wont be supported due to the nature of Python here - not_supported = {} - - # Please add missing features or failing tests here - missing_features_or_bugs = { + not_supported = { "LROPatchInlineCompleteIgnoreHeaders": 1, } + # Please add missing features or failing tests here + missing_features_or_bugs = {} + print("Coverage:") self._print_report(report, not_supported, missing_features_or_bugs) diff --git a/test/azure/low-level/AcceptanceTests/conftest.py b/test/azure/low-level/AcceptanceTests/conftest.py index b05e7d7e9de..775e338eaea 100644 --- a/test/azure/low-level/AcceptanceTests/conftest.py +++ b/test/azure/low-level/AcceptanceTests/conftest.py @@ -37,7 +37,7 @@ #Ideally this would be in a common helper library shared between the tests def start_server_process(): - cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver".format(cwd) + cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver/dist/cli/cli.js run --appendCoverage".format(cwd) if os.name == 'nt': #On windows, subprocess creation works without being in the shell return subprocess.Popen(cmd) diff --git a/test/azure/low-level/coverage/report-dpg.json b/test/azure/low-level/coverage/report-dpg.json new file mode 100644 index 00000000000..d2e2590c4b1 --- /dev/null +++ b/test/azure/low-level/coverage/report-dpg.json @@ -0,0 +1,16 @@ +{ + "GetRawModel": 0, + "GetHandwrittenModel": 0, + "PostRawModel": 0, + "PostHandwrittenModel": 0, + "GetRawPages": 0, + "GetHandwrittenModelPages": 0, + "RawLRO": 0, + "HandwrittenModelLRO": 0, + "DPGAddOptionalInput": 8, + "DPGNewBodyType.JSON": 0, + "DPGNewBodyType.JPEG": 0, + "DPGNewBodyType": 0, + "DPGAddNewOperation": 0, + "DPGAddNewPath": 0 +} \ No newline at end of file diff --git a/test/azure/version-tolerant/AcceptanceTests/conftest.py b/test/azure/version-tolerant/AcceptanceTests/conftest.py index 49e217dae92..f117b2100ef 100644 --- a/test/azure/version-tolerant/AcceptanceTests/conftest.py +++ b/test/azure/version-tolerant/AcceptanceTests/conftest.py @@ -43,7 +43,7 @@ #Ideally this would be in a common helper library shared between the tests def start_server_process(): - cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver".format(cwd) + cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver/dist/cli/cli.js run --appendCoverage".format(cwd) if os.name == 'nt': #On windows, subprocess creation works without being in the shell return subprocess.Popen(cmd) diff --git a/test/azure/version-tolerant/AcceptanceTests/test_zzz.py b/test/azure/version-tolerant/AcceptanceTests/test_zzz.py index 4141c1f11ad..1075dbafde8 100644 --- a/test/azure/version-tolerant/AcceptanceTests/test_zzz.py +++ b/test/azure/version-tolerant/AcceptanceTests/test_zzz.py @@ -36,14 +36,14 @@ def test_ensure_coverage(self): report = client.get_report(qualifier=platform.python_version()) # Add tests that wont be supported due to the nature of Python here - not_supported = {} - - # Please add missing features or failing tests here - missing_features_or_bugs = { + not_supported = { "LROPatchInlineCompleteIgnoreHeaders": 1, "PagingDuplicateParameters": 1 # skipping for now, going to do another PR soon changing paging behavior for version tolerant } + # Please add missing features or failing tests here + missing_features_or_bugs = {} + print("Coverage:") self._print_report(report, not_supported, missing_features_or_bugs) diff --git a/test/dpg/low-level/AcceptanceTests/asynctests/conftest.py b/test/dpg/low-level/AcceptanceTests/asynctests/conftest.py index 829fcdf90df..b80f6be81dc 100644 --- a/test/dpg/low-level/AcceptanceTests/asynctests/conftest.py +++ b/test/dpg/low-level/AcceptanceTests/asynctests/conftest.py @@ -33,7 +33,7 @@ #Ideally this would be in a common helper library shared between the tests def start_server_process(): - cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver".format(cwd) + cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver/dist/cli/cli.js run --appendCoverage".format(cwd) if os.name == 'nt': #On windows, subprocess creation works without being in the shell return subprocess.Popen(cmd) diff --git a/test/dpg/low-level/AcceptanceTests/conftest.py b/test/dpg/low-level/AcceptanceTests/conftest.py index e36a9a9c0c2..21c238ecb61 100644 --- a/test/dpg/low-level/AcceptanceTests/conftest.py +++ b/test/dpg/low-level/AcceptanceTests/conftest.py @@ -33,7 +33,7 @@ #Ideally this would be in a common helper library shared between the tests def start_server_process(): - cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver".format(cwd) + cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver/dist/cli/cli.js run --appendCoverage".format(cwd) if os.name == 'nt': #On windows, subprocess creation works without being in the shell return subprocess.Popen(cmd) diff --git a/test/dpg/low-level/tox.ini b/test/dpg/low-level/tox.ini index 4087afe5482..9936a3d27ac 100644 --- a/test/dpg/low-level/tox.ini +++ b/test/dpg/low-level/tox.ini @@ -3,6 +3,7 @@ envlist=py36, py310 skipsdist=True [testenv:ci] +passenv=* deps= -rrequirements.txt commands = diff --git a/test/dpg/version-tolerant/AcceptanceTests/asynctests/test_service_driven_async.py b/test/dpg/version-tolerant/AcceptanceTests/asynctests/test_service_driven_async.py index fcd2575d18a..804fd792e32 100644 --- a/test/dpg/version-tolerant/AcceptanceTests/asynctests/test_service_driven_async.py +++ b/test/dpg/version-tolerant/AcceptanceTests/asynctests/test_service_driven_async.py @@ -47,3 +47,21 @@ async def test_add_optional_parameter(initial_client, update_one_client): parameter="foo", new_parameter="bar", ) + +@pytest.mark.asyncio +async def test_add_new_content_type(initial_client, update_one_client): + await initial_client.params.post_parameters({ "url": "http://example.org/myimage.jpeg" }) + await update_one_client.params.post_parameters({ "url": "http://example.org/myimage.jpeg" }) + await update_one_client.params.post_parameters(b"hello", content_type="image/jpeg") + +@pytest.mark.asyncio +async def test_add_new_operation(initial_client, update_one_client): + with pytest.raises(AttributeError): + await initial_client.params.delete_parameters() + await update_one_client.params.delete_parameters() + +@pytest.mark.asyncio +async def test_add_new_path(initial_client, update_one_client): + with pytest.raises(AttributeError): + await initial_client.params.get_new_operation() + assert await update_one_client.params.get_new_operation() == {'message': 'An object was successfully returned'} diff --git a/test/dpg/version-tolerant/AcceptanceTests/conftest.py b/test/dpg/version-tolerant/AcceptanceTests/conftest.py index 8e287c175bb..370c86aa176 100644 --- a/test/dpg/version-tolerant/AcceptanceTests/conftest.py +++ b/test/dpg/version-tolerant/AcceptanceTests/conftest.py @@ -33,7 +33,7 @@ #Ideally this would be in a common helper library shared between the tests def start_server_process(): - cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver".format(cwd) + cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver/dist/cli/cli.js run --appendCoverage".format(cwd) if os.name == 'nt': #On windows, subprocess creation works without being in the shell return subprocess.Popen(cmd) diff --git a/test/dpg/version-tolerant/AcceptanceTests/test_service_driven.py b/test/dpg/version-tolerant/AcceptanceTests/test_service_driven.py index 8e191fed242..24491ce1cac 100644 --- a/test/dpg/version-tolerant/AcceptanceTests/test_service_driven.py +++ b/test/dpg/version-tolerant/AcceptanceTests/test_service_driven.py @@ -46,3 +46,18 @@ def test_add_optional_parameter(initial_client, update_one_client): parameter="foo", new_parameter="bar", ) + +def test_add_new_content_type(initial_client, update_one_client): + initial_client.params.post_parameters({ "url": "http://example.org/myimage.jpeg" }) + update_one_client.params.post_parameters({ "url": "http://example.org/myimage.jpeg" }) + update_one_client.params.post_parameters(b"hello", content_type="image/jpeg") + +def test_add_new_operation(initial_client, update_one_client): + with pytest.raises(AttributeError): + initial_client.params.delete_parameters() + update_one_client.params.delete_parameters() + +def test_add_new_path(initial_client, update_one_client): + with pytest.raises(AttributeError): + initial_client.params.get_new_operation() + assert update_one_client.params.get_new_operation() == {'message': 'An object was successfully returned'} diff --git a/test/dpg/version-tolerant/AcceptanceTests/test_zzz.py b/test/dpg/version-tolerant/AcceptanceTests/test_zzz.py new file mode 100644 index 00000000000..b9bc1a7dbe6 --- /dev/null +++ b/test/dpg/version-tolerant/AcceptanceTests/test_zzz.py @@ -0,0 +1,80 @@ +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- +import platform +import warnings +from azure.core.rest import HttpRequest + +from dpgservicedriveninitialversiontolerant import DPGClient + + + + +class TestAcceptance(object): + + def test_ensure_coverage(self): + client = DPGClient() + request = HttpRequest("GET", "http://localhost:3000/report/dpg", params={"qualifier": platform.python_version()}) + response = client.send_request(request) + response.raise_for_status() + support_dict = response.json() + # Add tests that wont be supported due to the nature of Python here + not_supported = { + } + + # Please add missing features or failing tests here + missing_features_or_bugs = { + 'DPGAddOptionalInput_NoParams': 1, + 'DPGAddOptionalInput_RequiredOptionalParam': 1, + 'DPGAddOptionalInput_OptionalParam': 1, + 'DPGGlassBreaker': 1, + } + for name in support_dict: + if "DPG" not in name: + # this folder only does dpg + missing_features_or_bugs[name] = 1 + + print("Coverage:") + self._print_report(support_dict, not_supported, missing_features_or_bugs) + + def _print_report(self, report, not_supported=None, missing_features_or_bugs=None): + if not_supported: + report.update(not_supported) + for s in not_supported.keys(): + print("IGNORING {0}".format(s)) + + if missing_features_or_bugs: + report.update(missing_features_or_bugs) + for s in missing_features_or_bugs.keys(): + print("PENDING {0}".format(s)) + + failed = [k for k, v in report.items() if v == 0] + for s in failed: + print("FAILED TO EXECUTE {0}".format(s)) + + total_tests = len(report) + warnings.warn ("The test coverage is {0}/{1}.".format(total_tests - len(failed), total_tests)) + + assert 0 == len(failed) diff --git a/test/dpg/version-tolerant/coverage/report-dpg.json b/test/dpg/version-tolerant/coverage/report-dpg.json new file mode 100644 index 00000000000..70fc8930e1b --- /dev/null +++ b/test/dpg/version-tolerant/coverage/report-dpg.json @@ -0,0 +1,16 @@ +{ + "GetRawModel": 0, + "GetHandwrittenModel": 0, + "PostRawModel": 0, + "PostHandwrittenModel": 0, + "GetRawPages": 0, + "GetHandwrittenModelPages": 0, + "RawLRO": 0, + "HandwrittenModelLRO": 0, + "DPGAddOptionalInput": 4, + "DPGNewBodyType.JSON": 4, + "DPGNewBodyType.JPEG": 2, + "DPGNewBodyType": 6, + "DPGAddNewOperation": 2, + "DPGAddNewPath": 2 +} \ No newline at end of file diff --git a/test/dpg/version-tolerant/tox.ini b/test/dpg/version-tolerant/tox.ini index fd2daa058a2..ab76acae3fa 100644 --- a/test/dpg/version-tolerant/tox.ini +++ b/test/dpg/version-tolerant/tox.ini @@ -11,6 +11,7 @@ commands = python ../../../eng/scripts/run_pylint.py -t dpg -g version-tolerant [testenv:ci] +passenv=* deps= -rrequirements.txt commands = diff --git a/test/multiapi/AcceptanceTests/conftest.py b/test/multiapi/AcceptanceTests/conftest.py index 583e67424cb..d4f1b509651 100644 --- a/test/multiapi/AcceptanceTests/conftest.py +++ b/test/multiapi/AcceptanceTests/conftest.py @@ -35,7 +35,7 @@ #Ideally this would be in a common helper library shared between the tests def start_server_process(): - cmd = "node {}/../../../node_modules/@microsoft.azure/autorest.testserver".format(cwd) + cmd = "node {}/../../../node_modules/@microsoft.azure/autorest.testserver/dist/cli/cli.js run --appendCoverage".format(cwd) if os.name == 'nt': #On windows, subprocess creation works without being in the shell return subprocess.Popen(cmd) diff --git a/test/vanilla/legacy/AcceptanceTests/asynctests/test_media_types.py b/test/vanilla/legacy/AcceptanceTests/asynctests/test_media_types.py index 379e243ce9d..2fcd09d8458 100644 --- a/test/vanilla/legacy/AcceptanceTests/asynctests/test_media_types.py +++ b/test/vanilla/legacy/AcceptanceTests/asynctests/test_media_types.py @@ -77,3 +77,14 @@ async def test_binary_body_two_content_types(self, client): content = b"hello, world" await client.binary_body_with_two_content_types(content, content_type="application/octet-stream") + + @pytest.mark.asyncio + async def test_binary_body_three_content_types(self, client): + json_input = json.dumps({"hello":"world"}) + await client.binary_body_with_three_content_types(json_input) + + content = b"hello, world" + await client.binary_body_with_three_content_types(content, content_type="application/octet-stream") + + content = "hello, world" + await client.binary_body_with_three_content_types(content, content_type="text/plain") diff --git a/test/vanilla/legacy/AcceptanceTests/conftest.py b/test/vanilla/legacy/AcceptanceTests/conftest.py index df307b81cec..fc5d3764a08 100644 --- a/test/vanilla/legacy/AcceptanceTests/conftest.py +++ b/test/vanilla/legacy/AcceptanceTests/conftest.py @@ -43,7 +43,7 @@ #Ideally this would be in a common helper library shared between the tests def start_server_process(): - cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver".format(cwd) + cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver/dist/cli/cli.js run --appendCoverage".format(cwd) if os.name == 'nt': #On windows, subprocess creation works without being in the shell return subprocess.Popen(cmd) diff --git a/test/vanilla/legacy/AcceptanceTests/test_media_types.py b/test/vanilla/legacy/AcceptanceTests/test_media_types.py index 1c4f24dbf69..591d7d0183d 100644 --- a/test/vanilla/legacy/AcceptanceTests/test_media_types.py +++ b/test/vanilla/legacy/AcceptanceTests/test_media_types.py @@ -69,6 +69,16 @@ def test_binary_body_two_content_types(self, client): content = b"hello, world" client.binary_body_with_two_content_types(content, content_type="application/octet-stream") + def test_binary_body_three_content_types(self, client): + json_input = json.dumps({"hello":"world"}) + client.binary_body_with_three_content_types(json_input) + + content = b"hello, world" + client.binary_body_with_three_content_types(content, content_type="application/octet-stream") + + content = "hello, world" + client.binary_body_with_three_content_types(content, content_type="text/plain") + def test_models(self): from mediatypes.models import SourcePath diff --git a/test/vanilla/legacy/AcceptanceTests/test_zzz.py b/test/vanilla/legacy/AcceptanceTests/test_zzz.py index 9bba3311764..aaa61ed129d 100644 --- a/test/vanilla/legacy/AcceptanceTests/test_zzz.py +++ b/test/vanilla/legacy/AcceptanceTests/test_zzz.py @@ -45,6 +45,8 @@ def test_ensure_coverage(self): # Please add missing features or failing tests here missing_features_or_bugs = { 'ConstantsInBody': 1, # https://github.com/Azure/autorest.modelerfour/issues/83 + "ResponsesScenarioF400DefaultModel": 1, + "ResponsesScenarioF400DefaultNone": 1, } for name in report: if name[:3].lower() == 'dpg': @@ -70,10 +72,10 @@ def test_ensure_coverage(self): # dpg is in a separate test folder missing_features_or_bugs[name] = 1 print("Optional coverage:") - self._print_report(optional_report, not_supported, missing_features_or_bugs) + self._print_report(optional_report, not_supported, missing_features_or_bugs, fail_if_missing=False) - def _print_report(self, report, not_supported=None, missing_features_or_bugs=None): + def _print_report(self, report, not_supported=None, missing_features_or_bugs=None, fail_if_missing=True): if not_supported: report.update(not_supported) for s in not_supported.keys(): @@ -91,4 +93,5 @@ def _print_report(self, report, not_supported=None, missing_features_or_bugs=Non total_tests = len(report) warnings.warn ("The test coverage is {0}/{1}.".format(total_tests - len(failed), total_tests)) - assert 0 == len(failed) + if fail_if_missing: + assert 0 == len(failed) diff --git a/test/vanilla/low-level/AcceptanceTests/asynctests/test_media_types.py b/test/vanilla/low-level/AcceptanceTests/asynctests/test_media_types.py index 315268bb15a..d663044621e 100644 --- a/test/vanilla/low-level/AcceptanceTests/asynctests/test_media_types.py +++ b/test/vanilla/low-level/AcceptanceTests/asynctests/test_media_types.py @@ -81,3 +81,17 @@ async def test_binary_body_two_content_types(send_request): content = b"hello, world" request = build_binary_body_with_two_content_types_request(content=content, content_type="application/octet-stream") await send_request(request) + +@pytest.mark.asyncio +async def test_binary_body_three_content_types(send_request): + json_input = {"hello":"world"} + request = build_binary_body_with_three_content_types_request(json=json_input, content_type="application/json") + await send_request(request) + + content = b"hello, world" + request = build_binary_body_with_three_content_types_request(content=content, content_type="application/octet-stream") + await send_request(request) + + content = "hello, world" + request = build_binary_body_with_three_content_types_request(content=content, content_type="text/plain") + await send_request(request) diff --git a/test/vanilla/low-level/AcceptanceTests/conftest.py b/test/vanilla/low-level/AcceptanceTests/conftest.py index 51e4afde427..fc90a7cb2a5 100644 --- a/test/vanilla/low-level/AcceptanceTests/conftest.py +++ b/test/vanilla/low-level/AcceptanceTests/conftest.py @@ -44,7 +44,7 @@ #Ideally this would be in a common helper library shared between the tests def start_server_process(): - cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver".format(cwd) + cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver/dist/cli/cli.js run --appendCoverage".format(cwd) if os.name == 'nt': #On windows, subprocess creation works without being in the shell return subprocess.Popen(cmd) diff --git a/test/vanilla/low-level/AcceptanceTests/test_media_types.py b/test/vanilla/low-level/AcceptanceTests/test_media_types.py index 9770ab5f7b9..b6b22539724 100644 --- a/test/vanilla/low-level/AcceptanceTests/test_media_types.py +++ b/test/vanilla/low-level/AcceptanceTests/test_media_types.py @@ -72,3 +72,16 @@ def test_binary_body_two_content_types(send_request): content = b"hello, world" request = build_binary_body_with_two_content_types_request(content=content, content_type="application/octet-stream") send_request(request) + +def test_binary_body_three_content_types(send_request): + json_input = {"hello":"world"} + request = build_binary_body_with_three_content_types_request(json=json_input, content_type="application/json") + send_request(request) + + content = b"hello, world" + request = build_binary_body_with_three_content_types_request(content=content, content_type="application/octet-stream") + send_request(request) + + content = "hello, world" + request = build_binary_body_with_three_content_types_request(content=content, content_type="text/plain") + send_request(request) diff --git a/test/vanilla/low-level/AcceptanceTests/test_zzz.py b/test/vanilla/low-level/AcceptanceTests/test_zzz.py index cc90dceb160..6b158fd804a 100644 --- a/test/vanilla/low-level/AcceptanceTests/test_zzz.py +++ b/test/vanilla/low-level/AcceptanceTests/test_zzz.py @@ -43,17 +43,18 @@ def test_ensure_coverage(self): optional_report = client.send_request(request).json() # Add tests that wont be supported due to the nature of Python here - not_supported = {} + not_supported = { + "verifyIncorrectErrorParsing": 1, # we don't deserialize errors in llc + "ResponsesScenarioF400DefaultModel": 1, # don't test this + "ResponsesScenarioF400DefaultNone": 1, # don't test this + "ResponsesScenarioG200DefaultNoModel": 1, # don't test this + } # Please add missing features or failing tests here missing_features_or_bugs = { 'ConstantsInBody': 1, # https://github.com/Azure/autorest.modelerfour/issues/83 - "verifyIncorrectErrorParsing": 1, # we don't deserialize errors in llc "ImplicitOptionalBinaryBody": 1, # these are properties on the client, don't know enough info in LLC "ExplicitRequiredBinaryBody": 1, # these are properties on the client, don't know enough info in LLC - "ResponsesScenarioF400DefaultModel": 1, # don't test this - "ResponsesScenarioF400DefaultNone": 1, # don't test this - "ResponsesScenarioG200DefaultNoModel": 1, # don't test this "CustomBaseUri": 1, # don't have enough info on LLC "CustomBaseUriMoreOptions": 1, "expectedNoErrors": 1, @@ -89,10 +90,10 @@ def test_ensure_coverage(self): # llc is in a separate test folder missing_features_or_bugs[name] = 1 print("Optional coverage:") - self._print_report(optional_report, not_supported, missing_features_or_bugs) + self._print_report(optional_report, not_supported, missing_features_or_bugs, fail_if_missing=False) - def _print_report(self, report, not_supported=None, missing_features_or_bugs=None): + def _print_report(self, report, not_supported=None, missing_features_or_bugs=None, fail_if_missing=True): if not_supported: report.update(not_supported) for s in not_supported.keys(): @@ -110,4 +111,5 @@ def _print_report(self, report, not_supported=None, missing_features_or_bugs=Non total_tests = len(report) warnings.warn ("The test coverage is {0}/{1}.".format(total_tests - len(failed), total_tests)) - assert 0 == len(failed) + if fail_if_missing: + assert 0 == len(failed) diff --git a/test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_media_types.py b/test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_media_types.py index 6b3b534a7f8..e6f786981f5 100644 --- a/test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_media_types.py +++ b/test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_media_types.py @@ -73,3 +73,14 @@ async def test_binary_body_two_content_types(client): content = b"hello, world" await client.binary_body_with_two_content_types(content, content_type="application/octet-stream") + +@pytest.mark.asyncio +async def test_binary_body_three_content_types(client): + json_input = {"hello":"world"} + await client.binary_body_with_three_content_types(json_input) + + content = b"hello, world" + await client.binary_body_with_three_content_types(content, content_type="application/octet-stream") + + content = "hello, world" + await client.binary_body_with_three_content_types(content, content_type="text/plain") diff --git a/test/vanilla/version-tolerant/AcceptanceTests/conftest.py b/test/vanilla/version-tolerant/AcceptanceTests/conftest.py index df307b81cec..fc5d3764a08 100644 --- a/test/vanilla/version-tolerant/AcceptanceTests/conftest.py +++ b/test/vanilla/version-tolerant/AcceptanceTests/conftest.py @@ -43,7 +43,7 @@ #Ideally this would be in a common helper library shared between the tests def start_server_process(): - cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver".format(cwd) + cmd = "node {}/../../../../node_modules/@microsoft.azure/autorest.testserver/dist/cli/cli.js run --appendCoverage".format(cwd) if os.name == 'nt': #On windows, subprocess creation works without being in the shell return subprocess.Popen(cmd) diff --git a/test/vanilla/version-tolerant/AcceptanceTests/test_media_types.py b/test/vanilla/version-tolerant/AcceptanceTests/test_media_types.py index ac2a65c24be..e0a9d59706d 100644 --- a/test/vanilla/version-tolerant/AcceptanceTests/test_media_types.py +++ b/test/vanilla/version-tolerant/AcceptanceTests/test_media_types.py @@ -63,3 +63,13 @@ def test_binary_body_two_content_types(client): content = b"hello, world" client.binary_body_with_two_content_types(content, content_type="application/octet-stream") + +def test_binary_body_three_content_types(client): + json_input = {"hello":"world"} + client.binary_body_with_three_content_types(json_input) + + content = b"hello, world" + client.binary_body_with_three_content_types(content, content_type="application/octet-stream") + + content = "hello, world" + client.binary_body_with_three_content_types(content, content_type="text/plain") diff --git a/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py b/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py index 30eb9f1c491..18f390f43a2 100644 --- a/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py +++ b/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py @@ -37,12 +37,13 @@ def test_ensure_coverage(self): optional_report = client.get_optional_report(qualifier=platform.python_version()) # Add tests that wont be supported due to the nature of Python here - not_supported = {} + not_supported = { + "verifyIncorrectErrorParsing": 1, # not deserializing errors yet in version tolerant + } # Please add missing features or failing tests here missing_features_or_bugs = { 'ConstantsInBody': 1, # https://github.com/Azure/autorest.modelerfour/issues/83 - "verifyIncorrectErrorParsing": 1, # not deserializing errors yet in version tolerant "ResponsesScenarioF400DefaultModel": 1, "ResponsesScenarioF400DefaultNone": 1, } @@ -67,10 +68,10 @@ def test_ensure_coverage(self): # dpg is in a separate test folder missing_features_or_bugs[name] = 1 print("Optional coverage:") - self._print_report(optional_report, not_supported, missing_features_or_bugs) + self._print_report(optional_report, not_supported, missing_features_or_bugs, fail_if_missing=False) - def _print_report(self, report, not_supported=None, missing_features_or_bugs=None): + def _print_report(self, report, not_supported=None, missing_features_or_bugs=None, fail_if_missing=True): if not_supported: report.update(not_supported) for s in not_supported.keys(): @@ -88,4 +89,5 @@ def _print_report(self, report, not_supported=None, missing_features_or_bugs=Non total_tests = len(report) warnings.warn ("The test coverage is {0}/{1}.".format(total_tests - len(failed), total_tests)) - assert 0 == len(failed) + if fail_if_missing: + assert 0 == len(failed)