diff --git a/.azure-devops/create-release.yml b/.azure-devops/create-release.yml index be446801a..f69eb669c 100644 --- a/.azure-devops/create-release.yml +++ b/.azure-devops/create-release.yml @@ -2,109 +2,148 @@ pr: none trigger: none -jobs: - - # track deployment in environments -- deployment: 'StageGitHub' - displayName: 'Stage CLI extension on GitHub' - environment: 'production' - -- job: 'Build_Publish_Azure_IoT_CLI_Extension' - pool: - vmImage: 'Ubuntu-16.04' - - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '3.6.x' - architecture: 'x64' - - - template: templates/setup-ci-machine.yml - - - template: templates/build-publish-azure-iot-cli-extension.yml - -- job: 'Build_Publish_Azure_CLI_Test_SDK' - pool: - vmImage: 'Ubuntu-16.04' - - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '3.6.x' - architecture: 'x64' - - - template: templates/setup-ci-machine.yml - - - template: templates/build-publish-azure-cli-test-sdk.yml - -- job: 'Run_Tests' - dependsOn : Build_Publish_Azure_CLI_Test_SDK - pool: - vmImage: 'Ubuntu-16.04' - - steps: - - template: templates/run-tests.yml - parameters: - pythonVersion: '3.6.x' - runUnitTestsOnly: 'true' - - - script: 'pip install .' - displayName: 'Install the whl locally' - workingDirectory: '.' - - - task: PythonScript@0 - displayName : 'setupVersion' - name: 'setupVersion' - inputs: - scriptSource: 'inline' - script: | - from azext_iot.constants import VERSION - print("Version is " + VERSION) - print("##vso[task.setvariable variable=CLIVersion;isOutput=true]"+VERSION) - print("##vso[task.setvariable variable=ReleaseTitle;isOutput=true]"+"azure-iot "+VERSION) - -- job: 'Calculate_Sha_And_Create_Release' - dependsOn : Run_Tests - pool: - vmImage: 'vs2017-win2016' - variables: - CLIVersion: $[dependencies.Run_Tests.outputs['setupVersion.CLIVersion']] - ReleaseTitle: $[dependencies.Run_Tests.outputs['setupVersion.ReleaseTitle']] - - steps: - - task: DownloadBuildArtifacts@0 - displayName : 'Download Extension wheel from Build Artifacts' - inputs: - buildType: 'current' - downloadType: 'single' - artifactName: 'azure-iot' - downloadPath: '$(System.ArtifactsDirectory)/extension' - - - task: PowerShell@2 - displayName: 'Calculate sha for downloaded extension' - inputs: - targetType: 'inline' - script: | - $extensions = Get-ChildItem -Filter "*.whl" -Recurse | Select-Object FullName - Foreach ($extension in $extensions) - { - Write-Host "calculating sha256 for " $extension.FullName - (Get-Filehash -Path $extension.Fullname -Algorithm SHA256).Hash.ToLower() - } - Write-Host "done" - workingDirectory: '$(System.ArtifactsDirectory)/extension' - - - task: GitHubRelease@0 - inputs: - gitHubConnection: AzIoTCLIGitHub - repositoryName: $(Build.Repository.Name) - action: 'create' - target: '$(Build.SourceVersion)' - tagSource: manual - tag: 'v$(CLIVersion)' - title: $(ReleaseTitle) - assets: '$(System.ArtifactsDirectory)/extension/**/*.whl' - assetUploadMode: 'replace' - isDraft: true - isPreRelease: false - addChangeLog: false +variables: + pythonVersion: '3.6.x' + architecture: 'x64' + +stages: + - stage: 'build' + displayName: 'Build and Publish Artifacts' + jobs: + + - job: 'Build_Publish_Azure_IoT_CLI_Extension' + pool: + vmImage: 'Ubuntu-16.04' + + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: $(pythonVersion) + architecture: $(architecture) + + - template: templates/setup-ci-machine.yml + + - template: templates/build-publish-azure-iot-cli-extension.yml + + - job: 'Build_Publish_Azure_CLI_Test_SDK' + pool: + vmImage: 'Ubuntu-16.04' + + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: $(pythonVersion) + architecture: $(architecture) + + - template: templates/setup-ci-machine.yml + + - template: templates/build-publish-azure-cli-test-sdk.yml + + - stage: 'test' + displayName: 'Run tests' + pool: + vmImage: 'Ubuntu-16.04' + dependsOn: build + jobs: + - job: 'testCentral' + displayName: 'Test IoT Central' + steps: + - template: templates/run-tests.yml + parameters: + path: 'azext_iot/tests/central' + name: 'IoT-Central' + + - job: 'testADT' + displayName: 'Test Azure DigitalTwins' + steps: + - template: templates/run-tests.yml + parameters: + path: 'azext_iot/tests/digitaltwins' + name: 'Azure-DigitalTwins' + + - job: 'testDPS' + displayName: 'Test DPS' + steps: + - template: templates/run-tests.yml + parameters: + path: 'azext_iot/tests/dps' + name: 'Device-Provisioning-Service' + + - job: 'testHub' + displayName: 'Test IoT Hub' + steps: + - template: templates/run-tests.yml + parameters: + path: 'azext_iot/tests/iothub' + name: 'IoT-Hub' + + - job: 'unitTests' + displayName: 'Unit tests and code coverage' + steps: + - template: templates/run-tests.yml + parameters: + runIntTests: 'false' + runUnitTests: 'true' + + - job: 'recordVersion' + displayName: 'Install and verify version' + steps: + - template: templates/setup-dev-test-env.yml + parameters: + pythonVersion: $(pythonVersion) + architecture: $(architecture) + + - template: templates/install-and-record-version.yml + + - stage: 'release' + displayName: 'Stage GitHub release' + dependsOn: [build, test] + jobs: + - deployment: 'StageGitHub' + displayName: 'Stage CLI extension on GitHub' + environment: 'production' + + - job: 'Calculate_Sha_And_Create_Release' + pool: + vmImage: 'vs2017-win2016' + variables: + CLIVersion: $[ stageDependencies.test.recordVersion.outputs['setupVersion.CLIVersion'] ] + ReleaseTitle: $[ stageDependencies.test.recordVersion.outputs['setupVersion.ReleaseTitle'] ] + + steps: + - task: DownloadBuildArtifacts@0 + displayName : 'Download Extension wheel from Build Artifacts' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: 'azure-iot' + downloadPath: '$(System.ArtifactsDirectory)/extension' + + - task: PowerShell@2 + displayName: 'Calculate sha for downloaded extension' + inputs: + targetType: 'inline' + script: | + $extensions = Get-ChildItem -Filter "*.whl" -Recurse | Select-Object FullName + Foreach ($extension in $extensions) + { + Write-Host "calculating sha256 for " $extension.FullName + (Get-Filehash -Path $extension.Fullname -Algorithm SHA256).Hash.ToLower() + } + Write-Host "done" + workingDirectory: '$(System.ArtifactsDirectory)/extension' + + - task: GitHubRelease@0 + inputs: + gitHubConnection: AzIoTCLIGitHub + repositoryName: $(Build.Repository.Name) + action: 'create' + target: '$(Build.SourceVersion)' + tagSource: manual + tag: 'v$(CLIVersion)' + title: $(ReleaseTitle) + assets: '$(System.ArtifactsDirectory)/extension/**/*.whl' + assetUploadMode: 'replace' + isDraft: true + isPreRelease: false + addChangeLog: false diff --git a/.azure-devops/merge.yml b/.azure-devops/merge.yml index 1dab1cdc0..388c27962 100644 --- a/.azure-devops/merge.yml +++ b/.azure-devops/merge.yml @@ -58,6 +58,8 @@ jobs: - template: templates/run-tests.yml parameters: pythonVersion: '$(python.version)' + runUnitTests: 'true' + runIntTests: 'false' - job: 'run_unit_tests_macOs' dependsOn: ['build_and_publish_azure_iot_cli_ext', 'build_and_publish_azure_cli_test_sdk'] @@ -68,6 +70,8 @@ jobs: - template: templates/run-tests.yml parameters: pythonVersion: '3.8.x' + runUnitTests: 'true' + runIntTests: 'false' - job: 'run_unit_tests_windows' dependsOn : [ 'build_and_publish_azure_iot_cli_ext', 'build_and_publish_azure_cli_test_sdk'] @@ -83,6 +87,8 @@ jobs: - template: templates/run-tests.yml parameters: pythonVersion: '3.8.x' + runUnitTests: 'true' + runIntTests: 'false' - job: 'run_style_check' dependsOn: ['build_and_publish_azure_iot_cli_ext', 'build_and_publish_azure_cli_test_sdk'] diff --git a/.azure-devops/templates/install-and-record-version.yml b/.azure-devops/templates/install-and-record-version.yml new file mode 100644 index 000000000..7c26af21b --- /dev/null +++ b/.azure-devops/templates/install-and-record-version.yml @@ -0,0 +1,15 @@ +steps: +- script: 'pip install .' + displayName: 'Install the whl locally' + workingDirectory: '.' + +- task: PythonScript@0 + displayName : 'setupVersion' + name: 'setupVersion' + inputs: + scriptSource: 'inline' + script: | + from azext_iot.constants import VERSION + print("Version is " + VERSION) + print("##vso[task.setvariable variable=CLIVersion;isOutput=true]"+VERSION) + print("##vso[task.setvariable variable=ReleaseTitle;isOutput=true]"+"azure-iot "+VERSION) diff --git a/.azure-devops/templates/run-tests.yml b/.azure-devops/templates/run-tests.yml index 3676cf7a6..3a86da36f 100644 --- a/.azure-devops/templates/run-tests.yml +++ b/.azure-devops/templates/run-tests.yml @@ -1,51 +1,40 @@ parameters: - pythonVersion: '' - runUnitTestsOnly: 'true' + pythonVersion: '3.6.x' + architecture: 'x64' + runUnitTests: 'false' + runIntTests: 'true' runWithAzureCliReleased: 'true' + path: 'azext_iot/tests' + name: 'All' steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: ${{ parameters.pythonVersion }} - architecture: 'x64' - - - ${{ if eq(parameters.runWithAzureCliReleased, 'false') }}: - - template: install-azure-cli-edge.yml - - - ${{ if eq(parameters.runWithAzureCliReleased, 'true') }}: - - template: install-azure-cli-released.yml - - - template: download-install-local-azure-test-sdk.yml - - - template: setup-ci-machine.yml - - - template: download-install-local-azure-iot-cli-extension.yml - - - template: set-pythonpath.yml + - template: setup-dev-test-env.yml + parameters: + architecture: ${{ parameters.architecture }} + pythonVersion: ${{ parameters.pythonVersion }} + runWithAzureCliReleased: ${{ parameters.runWithAzureCliReleased }} - template: set-testenv-sentinel.yml - - ${{ if eq(parameters.runUnitTestsOnly, 'false') }}: - + - ${{ if eq(parameters.runIntTests, 'true') }}: - task: AzureCLI@2 - displayName: 'Execute full IoT extension test run' + displayName: '${{ parameters.name }} integration tests' inputs: azureSubscription: AzIoTCLIService scriptType: bash scriptLocation: inlineScript - inlineScript: pytest -vv -r azext_iot/tests/ --cov=azext_iot --cov-config .coveragerc --junitxml=junit/test-iotext-full-results.xml --cov-report=xml - - - ${{ if eq(parameters.runUnitTestsOnly, 'true') }}: + inlineScript: pytest -vv ${{ parameters.path }} -k "_int" --junitxml=junit/test-iotext-int-${{ parameters.name }}.xml - - script: pytest -vv -r azext_iot/tests/ -k "_unit" --cov=azext_iot --cov-config .coveragerc --junitxml=junit/test-iotext-unit-results.xml --cov-report=xml - displayName: 'Execute IoT extension unit tests' - - - task: PublishCodeCoverageResults@1 - inputs: - codeCoverageTool: 'cobertura' - summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' - reportDirectory: '$(System.DefaultWorkingDirectory)/htmlcov' - additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/htmlcov/**/*.*' + - ${{ if eq(parameters.runUnitTests, 'true') }}: + - script: pytest -vv ${{ parameters.path }} -k "_unit" --cov=azext_iot --cov-config .coveragerc --junitxml=junit/test-iotext-unit-${{ parameters.name }}.xml --cov-report=xml + displayName: '${{ parameters.name }} unit tests' + + - task: PublishCodeCoverageResults@1 + inputs: + codeCoverageTool: 'cobertura' + summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' + reportDirectory: '$(System.DefaultWorkingDirectory)/htmlcov' + additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/htmlcov/**/*.*' - task: PublishTestResults@2 condition: succeededOrFailed() @@ -53,5 +42,5 @@ steps: inputs: testResultsFormat: 'JUnit' testResultsFiles: '**/test-*.xml' - testRunTitle: 'Publish test results for Python ${{ parameters.pythonVersion }} on OS $(Agent.OS)' + testRunTitle: 'Publish ${{ parameters.name }} test results for Python ${{ parameters.pythonVersion }} on OS $(Agent.OS)' searchFolder: '$(System.DefaultWorkingDirectory)' diff --git a/.azure-devops/templates/setup-dev-test-env.yml b/.azure-devops/templates/setup-dev-test-env.yml new file mode 100644 index 000000000..cc6c1a875 --- /dev/null +++ b/.azure-devops/templates/setup-dev-test-env.yml @@ -0,0 +1,24 @@ +parameters: + pythonVersion: '' + architecture: '' + runWithAzureCliReleased: 'true' + +steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: ${{ parameters.pythonVersion }} + architecture: ${{ parameters.architecture }} + + - ${{ if eq(parameters.runWithAzureCliReleased, 'false') }}: + - template: install-azure-cli-edge.yml + + - ${{ if eq(parameters.runWithAzureCliReleased, 'true') }}: + - template: install-azure-cli-released.yml + + - template: download-install-local-azure-test-sdk.yml + + - template: setup-ci-machine.yml + + - template: download-install-local-azure-iot-cli-extension.yml + + - template: set-pythonpath.yml \ No newline at end of file diff --git a/CredScanSuppressions.json b/CredScanSuppressions.json index 3f349f26e..20e6d7c60 100644 --- a/CredScanSuppressions.json +++ b/CredScanSuppressions.json @@ -20,16 +20,16 @@ "_justification": "Completely made up keys for unit tests." }, { - "file": "azext_iot\\tests\\test_iot_dps_int.py", + "file": "azext_iot\\tests\\dps\\test_iot_dps_int.py", "placeholder": "cT/EXZvsplPEpT//p98Pc6sKh8mY3kYgSxavHwMkl7w=", "_justification": "Ensure made up endorsement key evaluates to the expected device key." }, { - "file": "azext_iot\\tests\\test_iot_dps_unit.py", + "file": "azext_iot\\tests\\dps\\test_iot_dps_unit.py", "_justification": "Completely made up keys for unit tests." }, { - "file": "azext_iot\\tests\\test_iot_ext_unit.py", + "file": "azext_iot\\tests\\iothub\\test_iot_ext_unit.py", "placeholder": "+XLy+MVZ+aTeOnVzN2kLeB16O+kSxmz6g3rS6fAf6rw=", "_justification": "Ensure made up policy key generates the proper SAS token." } diff --git a/azext_iot/tests/test_iot_central_int.py b/azext_iot/tests/central/test_iot_central_int.py similarity index 98% rename from azext_iot/tests/test_iot_central_int.py rename to azext_iot/tests/central/test_iot_central_int.py index 4d80e9f0a..fba2f3fe5 100644 --- a/azext_iot/tests/test_iot_central_int.py +++ b/azext_iot/tests/central/test_iot_central_int.py @@ -10,22 +10,22 @@ import time import pytest -from .conftest import get_context_path +from azext_iot.tests.conftest import get_context_path from azure.iot.device import Message from azext_iot.common import utility from azext_iot.central.models.enum import DeviceStatus, Role from azext_iot.monitor.parsers import strings -from . import CaptureOutputLiveScenarioTest, helpers +from azext_iot.tests import CaptureOutputLiveScenarioTest, helpers APP_ID = os.environ.get("azext_iot_central_app_id") APP_PRIMARY_KEY = os.environ.get("azext_iot_central_primarykey") APP_SCOPE_ID = os.environ.get("azext_iot_central_scope_id") device_template_path = get_context_path( - __file__, "central/json/device_template_int_test.json" + __file__, "json/device_template_int_test.json" ) -sync_command_params = get_context_path(__file__, "central/json/sync_command_args.json") +sync_command_params = get_context_path(__file__, "json/sync_command_args.json") if not all([APP_ID]): raise ValueError("Set azext_iot_central_app_id to run central integration tests.") diff --git a/azext_iot/tests/test_iot_central_unit.py b/azext_iot/tests/central/test_iot_central_unit.py similarity index 99% rename from azext_iot/tests/test_iot_central_unit.py rename to azext_iot/tests/central/test_iot_central_unit.py index 50b1d1933..cd09b11bd 100644 --- a/azext_iot/tests/test_iot_central_unit.py +++ b/azext_iot/tests/central/test_iot_central_unit.py @@ -22,8 +22,8 @@ from azext_iot.central.models.template import Template from azext_iot.monitor.property import PropertyMonitor from azext_iot.monitor.models.enum import Severity -from .helpers import load_json -from .test_constants import FileNames +from azext_iot.tests.helpers import load_json +from azext_iot.tests.test_constants import FileNames from azext_iot.constants import PNP_DTDLV2_COMPONENT_MARKER device_id = "mydevice" diff --git a/azext_iot/tests/test_iot_central_validator_unit.py b/azext_iot/tests/central/test_iot_central_validator_unit.py similarity index 99% rename from azext_iot/tests/test_iot_central_validator_unit.py rename to azext_iot/tests/central/test_iot_central_validator_unit.py index 844b5c6ac..75bafe4bc 100644 --- a/azext_iot/tests/test_iot_central_validator_unit.py +++ b/azext_iot/tests/central/test_iot_central_validator_unit.py @@ -10,8 +10,8 @@ from azext_iot.central.models.template import Template from azext_iot.monitor.central_validator import validate, extract_schema_type -from .helpers import load_json -from .test_constants import FileNames +from azext_iot.tests.helpers import load_json +from azext_iot.tests.test_constants import FileNames class TestTemplateValidations: diff --git a/azext_iot/tests/digitaltwins/__init__.py b/azext_iot/tests/digitaltwins/__init__.py index 5c97dff96..c90956dda 100644 --- a/azext_iot/tests/digitaltwins/__init__.py +++ b/azext_iot/tests/digitaltwins/__init__.py @@ -6,8 +6,8 @@ import pytest import os -from ..generators import generate_generic_id -from ..settings import DynamoSettings +from azext_iot.tests.generators import generate_generic_id +from azext_iot.tests.settings import DynamoSettings from azure.cli.testsdk import LiveScenarioTest from azext_iot.common.embedded_cli import EmbeddedCLI diff --git a/azext_iot/tests/digitaltwins/test_dt_provider_unit.py b/azext_iot/tests/digitaltwins/test_dt_provider_unit.py index e6d7eb3b8..58a9e5ffd 100644 --- a/azext_iot/tests/digitaltwins/test_dt_provider_unit.py +++ b/azext_iot/tests/digitaltwins/test_dt_provider_unit.py @@ -9,7 +9,7 @@ import responses import json from azext_iot.digitaltwins.providers.base import DigitalTwinsProvider -from ..generators import generate_generic_id +from azext_iot.tests.generators import generate_generic_id resource_group = generate_generic_id() diff --git a/azext_iot/tests/digitaltwins/test_dt_resource_lifecycle_int.py b/azext_iot/tests/digitaltwins/test_dt_resource_lifecycle_int.py index 02cd2da5c..b2f682896 100644 --- a/azext_iot/tests/digitaltwins/test_dt_resource_lifecycle_int.py +++ b/azext_iot/tests/digitaltwins/test_dt_resource_lifecycle_int.py @@ -8,7 +8,7 @@ from time import sleep from knack.log import get_logger from azext_iot.digitaltwins.common import ADTEndpointType -from ..settings import DynamoSettings +from azext_iot.tests.settings import DynamoSettings from . import DTLiveScenarioTest from . import ( MOCK_RESOURCE_TAGS, @@ -246,7 +246,7 @@ def test_dt_endpoints_routes(self): ) ) - sleep(20) # Wait for service to catch-up + sleep(60) # Wait for service to catch-up list_ep_output = self.cmd( "dt endpoint list -n {}".format(endpoints_instance_name) diff --git a/azext_iot/tests/digitaltwins/test_dt_twin_lifecycle_int.py b/azext_iot/tests/digitaltwins/test_dt_twin_lifecycle_int.py index 5c48e5979..33b7ab2ea 100644 --- a/azext_iot/tests/digitaltwins/test_dt_twin_lifecycle_int.py +++ b/azext_iot/tests/digitaltwins/test_dt_twin_lifecycle_int.py @@ -42,7 +42,7 @@ def test_dt_twin(self): ) ) # Wait for RBAC to catch-up - sleep(20) + sleep(60) self.cmd( "dt model create -n {} --from-directory '{}'".format( diff --git a/azext_iot/tests/test_iot_dps_int.py b/azext_iot/tests/dps/test_iot_dps_int.py similarity index 99% rename from azext_iot/tests/test_iot_dps_int.py rename to azext_iot/tests/dps/test_iot_dps_int.py index ba78fa09d..b9ca59899 100644 --- a/azext_iot/tests/test_iot_dps_int.py +++ b/azext_iot/tests/dps/test_iot_dps_int.py @@ -11,7 +11,7 @@ from azext_iot.common import embedded_cli from azext_iot.common.utility import generate_key from azext_iot.iothub.providers.discovery import IotHubDiscovery -from .settings import Setting +from azext_iot.tests.settings import Setting # Set these to the proper IoT Hub DPS, IoT Hub and Resource Group for Integration Tests. dps = os.environ.get("azext_iot_testdps") diff --git a/azext_iot/tests/test_iot_dps_unit.py b/azext_iot/tests/dps/test_iot_dps_unit.py similarity index 100% rename from azext_iot/tests/test_iot_dps_unit.py rename to azext_iot/tests/dps/test_iot_dps_unit.py diff --git a/azext_iot/tests/iothub/configurations/test_iot_config_int.py b/azext_iot/tests/iothub/configurations/test_iot_config_int.py index 8b6c00429..8c4997e96 100644 --- a/azext_iot/tests/iothub/configurations/test_iot_config_int.py +++ b/azext_iot/tests/iothub/configurations/test_iot_config_int.py @@ -7,9 +7,9 @@ import random import json -from ... import IoTLiveScenarioTest -from ...conftest import get_context_path -from ...settings import DynamoSettings, ENV_SET_TEST_IOTHUB_BASIC +from azext_iot.tests import IoTLiveScenarioTest +from azext_iot.tests.conftest import get_context_path +from azext_iot.tests.settings import DynamoSettings, ENV_SET_TEST_IOTHUB_BASIC from azext_iot.common.utility import read_file_content settings = DynamoSettings(ENV_SET_TEST_IOTHUB_BASIC) diff --git a/azext_iot/tests/iothub/configurations/test_iot_config_unit.py b/azext_iot/tests/iothub/configurations/test_iot_config_unit.py index 1edcac871..cb54909c2 100644 --- a/azext_iot/tests/iothub/configurations/test_iot_config_unit.py +++ b/azext_iot/tests/iothub/configurations/test_iot_config_unit.py @@ -14,7 +14,7 @@ from knack.cli import CLIError from azext_iot.operations import hub as subject from azext_iot.common.utility import read_file_content, evaluate_literal -from ...conftest import build_mock_response, path_service_client, mock_target, get_context_path +from azext_iot.tests.conftest import build_mock_response, path_service_client, mock_target, get_context_path config_id = "myconfig-{}".format(str(uuid4()).replace("-", "")) diff --git a/azext_iot/tests/iothub/jobs/test_iothub_jobs_int.py b/azext_iot/tests/iothub/jobs/test_iothub_jobs_int.py index d9c47df0b..1bd76bbcc 100644 --- a/azext_iot/tests/iothub/jobs/test_iothub_jobs_int.py +++ b/azext_iot/tests/iothub/jobs/test_iothub_jobs_int.py @@ -6,8 +6,8 @@ import json from datetime import datetime, timedelta -from ... import IoTLiveScenarioTest -from ...settings import DynamoSettings, ENV_SET_TEST_IOTHUB_BASIC +from azext_iot.tests import IoTLiveScenarioTest +from azext_iot.tests.settings import DynamoSettings, ENV_SET_TEST_IOTHUB_BASIC settings = DynamoSettings(ENV_SET_TEST_IOTHUB_BASIC) diff --git a/azext_iot/tests/iothub/jobs/test_iothub_jobs_unit.py b/azext_iot/tests/iothub/jobs/test_iothub_jobs_unit.py index 2d4aff133..491e5ec26 100644 --- a/azext_iot/tests/iothub/jobs/test_iothub_jobs_unit.py +++ b/azext_iot/tests/iothub/jobs/test_iothub_jobs_unit.py @@ -13,7 +13,7 @@ from knack.cli import CLIError from azext_iot.iothub import commands_job as subject from azext_iot.common.shared import JobStatusType, JobType -from ...conftest import build_mock_response, path_service_client, mock_target +from azext_iot.tests.conftest import build_mock_response, path_service_client, mock_target def generate_job_id(): diff --git a/azext_iot/tests/iothub/pnp_runtime/test_iot_pnp_runtime_unit.py b/azext_iot/tests/iothub/pnp_runtime/test_iot_pnp_runtime_unit.py index e36fa1f96..8011e48f5 100644 --- a/azext_iot/tests/iothub/pnp_runtime/test_iot_pnp_runtime_unit.py +++ b/azext_iot/tests/iothub/pnp_runtime/test_iot_pnp_runtime_unit.py @@ -11,8 +11,8 @@ from random import randint from knack.cli import CLIError from azext_iot.iothub import commands_pnp_runtime as subject -from ...conftest import mock_target -from ...generators import generate_generic_id +from azext_iot.tests.conftest import mock_target +from azext_iot.tests.generators import generate_generic_id device_id = generate_generic_id() diff --git a/azext_iot/tests/test_generic_replace.json b/azext_iot/tests/iothub/test_generic_replace.json similarity index 100% rename from azext_iot/tests/test_generic_replace.json rename to azext_iot/tests/iothub/test_generic_replace.json diff --git a/azext_iot/tests/test_generic_twin.json b/azext_iot/tests/iothub/test_generic_twin.json similarity index 100% rename from azext_iot/tests/test_generic_twin.json rename to azext_iot/tests/iothub/test_generic_twin.json diff --git a/azext_iot/tests/test_iot_ext_int.py b/azext_iot/tests/iothub/test_iot_ext_int.py similarity index 99% rename from azext_iot/tests/test_iot_ext_int.py rename to azext_iot/tests/iothub/test_iot_ext_int.py index 925ab99d0..0114e3c37 100644 --- a/azext_iot/tests/test_iot_ext_int.py +++ b/azext_iot/tests/iothub/test_iot_ext_int.py @@ -9,8 +9,8 @@ import warnings from azext_iot.common.utility import read_file_content -from . import IoTLiveScenarioTest -from .settings import DynamoSettings, ENV_SET_TEST_IOTHUB_BASIC +from azext_iot.tests import IoTLiveScenarioTest +from azext_iot.tests.settings import DynamoSettings, ENV_SET_TEST_IOTHUB_BASIC from azext_iot.constants import DEVICE_DEVICESCOPE_PREFIX opt_env_set = ["azext_iot_teststorageuri", "azext_iot_identity_teststorageid"] diff --git a/azext_iot/tests/test_iot_ext_unit.py b/azext_iot/tests/iothub/test_iot_ext_unit.py similarity index 99% rename from azext_iot/tests/test_iot_ext_unit.py rename to azext_iot/tests/iothub/test_iot_ext_unit.py index 4e79a2234..f28bd86db 100644 --- a/azext_iot/tests/test_iot_ext_unit.py +++ b/azext_iot/tests/iothub/test_iot_ext_unit.py @@ -28,7 +28,7 @@ from azext_iot.constants import TRACING_PROPERTY, USER_AGENT, BASE_MQTT_API_VERSION from azext_iot.tests.generators import create_req_monitor_events, generate_generic_id from knack.util import CLIError -from .conftest import ( +from azext_iot.tests.conftest import ( fixture_cmd, build_mock_response, path_service_client, @@ -1682,7 +1682,7 @@ def test_device_method_error(self, serviceclient_generic_error): class TestCloudToDeviceMessaging: @pytest.fixture(params=["full", "min"]) def c2d_receive_scenario(self, fixture_ghcs, mocked_response, request): - from .generators import create_c2d_receive_response + from azext_iot.tests.generators import create_c2d_receive_response if request.param == "full": payload = create_c2d_receive_response() @@ -1706,8 +1706,7 @@ def c2d_receive_scenario(self, fixture_ghcs, mocked_response, request): @pytest.fixture() def c2d_receive_ack_scenario(self, fixture_ghcs, mocked_response): - from .generators import create_c2d_receive_response - + from azext_iot.tests.generators import create_c2d_receive_response payload = create_c2d_receive_response() mocked_response.add( method=responses.GET, diff --git a/azext_iot/tests/test_iot_messaging_int.py b/azext_iot/tests/iothub/test_iot_messaging_int.py similarity index 99% rename from azext_iot/tests/test_iot_messaging_int.py rename to azext_iot/tests/iothub/test_iot_messaging_int.py index 286948d95..6b767631d 100644 --- a/azext_iot/tests/test_iot_messaging_int.py +++ b/azext_iot/tests/iothub/test_iot_messaging_int.py @@ -9,8 +9,8 @@ from time import time from uuid import uuid4 -from . import IoTLiveScenarioTest, PREFIX_DEVICE -from .settings import DynamoSettings, ENV_SET_TEST_IOTHUB_BASIC +from azext_iot.tests import IoTLiveScenarioTest, PREFIX_DEVICE +from azext_iot.tests.settings import DynamoSettings, ENV_SET_TEST_IOTHUB_BASIC from azext_iot.common.utility import ( validate_min_python_version, execute_onthread, diff --git a/azext_iot/tests/iothub/test_iothub_discovery_int.py b/azext_iot/tests/iothub/test_iothub_discovery_int.py index 16927cd51..b0bd35821 100644 --- a/azext_iot/tests/iothub/test_iothub_discovery_int.py +++ b/azext_iot/tests/iothub/test_iothub_discovery_int.py @@ -9,7 +9,7 @@ PRIVILEDGED_ACCESS_RIGHTS_SET, ) from azext_iot.tests import IoTLiveScenarioTest -from ..settings import DynamoSettings, ENV_SET_TEST_IOTHUB_BASIC, Setting +from azext_iot.tests.settings import DynamoSettings, ENV_SET_TEST_IOTHUB_BASIC, Setting settings = DynamoSettings(ENV_SET_TEST_IOTHUB_BASIC) LIVE_HUB = settings.env.azext_iot_testhub diff --git a/azext_iot/tests/test_device_digitaltwin_interfaces.json b/azext_iot/tests/test_device_digitaltwin_interfaces.json deleted file mode 100644 index 22cf08ae5..000000000 --- a/azext_iot/tests/test_device_digitaltwin_interfaces.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "interfaces": { - "environmentalSensor": { - "name": "environmentalSensor", - "properties": { - "brightness": { - "desired": { - "value": 123 - }, - "reported": { - "desiredState": { - "code": 200, - "description": "Brightness updated", - "version": 4 - }, - "value": 123 - } - }, - "name": { - "desired": { - "value": "test" - }, - "reported": { - "desiredState": { - "code": 200, - "description": "Property Updated Successfully", - "version": 4 - }, - "value": "test" - } - }, - "state": { - "reported": { - "value": true - } - } - } - }, - "urn_azureiot_ModelDiscovery_DigitalTwin": { - "name": "urn_azureiot_ModelDiscovery_DigitalTwin", - "properties": { - "modelInformation": { - "reported": { - "value": { - "interfaces": { - "environmentalSensor": "urn:contoso:com:EnvironmentalSensor:1", - "urn_azureiot_ModelDiscovery_DigitalTwin": "urn:azureiot:ModelDiscovery:DigitalTwin:1", - "urn_azureiot_ModelDiscovery_ModelInformation": "urn:azureiot:ModelDiscovery:ModelInformation:1" - }, - "modelId": "urn:azureiot:testdevicecapabilitymodel:1" - } - } - } - } - } - }, - "version": 1 - } \ No newline at end of file diff --git a/azext_iot/tests/test_device_digitaltwin_invoke_command.json b/azext_iot/tests/test_device_digitaltwin_invoke_command.json deleted file mode 100644 index fe34ec6b9..000000000 --- a/azext_iot/tests/test_device_digitaltwin_invoke_command.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "blinkRequest": { - "interval": 1 - } -} \ No newline at end of file diff --git a/azext_iot/tests/test_device_digitaltwin_property_update.json b/azext_iot/tests/test_device_digitaltwin_property_update.json deleted file mode 100644 index 09bcbd6b4..000000000 --- a/azext_iot/tests/test_device_digitaltwin_property_update.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "environmentalSensor": { - "properties": { - "name": { - "desired": { - "value": "test-update" - } - } - } - } -} \ No newline at end of file diff --git a/azext_iot/tests/test_iot_utility_unit.py b/azext_iot/tests/utility/test_iot_utility_unit.py similarity index 98% rename from azext_iot/tests/test_iot_utility_unit.py rename to azext_iot/tests/utility/test_iot_utility_unit.py index 19f8b3441..62516539e 100644 --- a/azext_iot/tests/test_iot_utility_unit.py +++ b/azext_iot/tests/utility/test_iot_utility_unit.py @@ -242,7 +242,7 @@ def test_inline_json_fail(self, content, argname): @pytest.mark.parametrize( "content, argname", - [("iothub/configurations/test_adm_device_content.json", "myarg0")], + [("../iothub/configurations/test_adm_device_content.json", "myarg0")], ) def test_file_json(self, content, argname, set_cwd): result = process_json_arg(content, argument_name=argname) @@ -267,7 +267,7 @@ def test_file_json_fail_invalidpath(self, content, argname, set_cwd, mocker): ) assert mocked_util_logger.call_args[0][1] == argname - @pytest.mark.parametrize("content, argname", [("generators.py", "myarg0")]) + @pytest.mark.parametrize("content, argname", [("../generators.py", "myarg0")]) def test_file_json_fail_invalidcontent(self, content, argname, set_cwd, mocker): mocked_util_logger = mocker.patch.object(logger, "warning", autospec=True) diff --git a/azext_iot/tests/test_monitor_parsers_unit.py b/azext_iot/tests/utility/test_monitor_parsers_unit.py similarity index 99% rename from azext_iot/tests/test_monitor_parsers_unit.py rename to azext_iot/tests/utility/test_monitor_parsers_unit.py index d8c4f9a8f..3d1622181 100644 --- a/azext_iot/tests/test_monitor_parsers_unit.py +++ b/azext_iot/tests/utility/test_monitor_parsers_unit.py @@ -19,8 +19,8 @@ from azext_iot.monitor.parsers import strings from azext_iot.monitor.models.arguments import CommonParserArguments from azext_iot.monitor.models.enum import Severity -from .helpers import load_json -from .test_constants import FileNames +from azext_iot.tests.helpers import load_json +from azext_iot.tests.test_constants import FileNames def _encode_app_props(app_props: dict): diff --git a/azext_iot/tests/test_uamqp_import.py b/azext_iot/tests/utility/test_uamqp_import.py similarity index 100% rename from azext_iot/tests/test_uamqp_import.py rename to azext_iot/tests/utility/test_uamqp_import.py