Skip to content

Commit

Permalink
[DigitalTwins] Refactor tests to use Test Proxy (#26545)
Browse files Browse the repository at this point in the history
Tests for "azure-digitaltwins-core" were converted to use Test Proxy.

- Refactored to use pytest fixtures for test prep.
- Updated ci.yml and tests.yml to indicate Test Proxy usage.
- Regenerated recordings using updated tests and deleted old vcrpy
  recordings.
- Added a test-resources.bicep file for live testing.
- Added a sleep for two query tests to ensure the service side reflects
  the latest changes.

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
  • Loading branch information
pvaneck authored Sep 30, 2022
1 parent ea8bf40 commit 976604a
Show file tree
Hide file tree
Showing 331 changed files with 53,902 additions and 39,847 deletions.
142 changes: 0 additions & 142 deletions sdk/digitaltwins/azure-digitaltwins-core/tests/_preparer.py

This file was deleted.

46 changes: 41 additions & 5 deletions sdk/digitaltwins/azure-digitaltwins-core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,45 @@
# Licensed under the MIT License. See LICENSE.txt in the project root for
# license information.
# -------------------------------------------------------------------------
import sys
import pytest

# Ignore collection of async tests for Python 2
collect_ignore_glob = []
if sys.version_info < (3, 5):
collect_ignore_glob.append("*_async.py")
from devtools_testutils.sanitizers import (
add_body_key_sanitizer,
add_header_regex_sanitizer,
add_oauth_response_sanitizer,
add_remove_header_sanitizer
)

# Environment variable keys
ENV_URL = "AZURE_DIGITALTWINS_URL"
ENV_SUBSCRIPTION_ID = "AZURE_SUBSCRIPTION_ID"
ENV_TENANT_ID = "AZURE_TENANT_ID"
ENV_CLIENT_ID = "AZURE_CLIENT_ID"
ENV_CLIENT_SECRET = "AZURE_CLIENT_SECRET"

# Fake values
TEST_URL = "https://fake.api.wcus.digitaltwins.azure.net"
TEST_ID = "00000000-0000-0000-0000-000000000000"


@pytest.fixture(scope="session", autouse=True)
def add_sanitizers(test_proxy, environment_variables):
sanitization_mapping = {
ENV_URL: TEST_URL,
ENV_SUBSCRIPTION_ID: TEST_ID,
ENV_TENANT_ID: TEST_ID,
ENV_CLIENT_ID: TEST_ID,
ENV_CLIENT_SECRET: TEST_ID
}
environment_variables.sanitize_batch(sanitization_mapping)
add_remove_header_sanitizer(headers="Telemetry-Source-Time, Message-Id")
add_body_key_sanitizer(json_path="AccessToken", value="fake.eyJleHAiOjIxNDc0ODM2NDd9.fake")
add_oauth_response_sanitizer()
add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]")


@pytest.fixture(scope="session")
def digitaltwin(environment_variables):
yield {
"endpoint": environment_variables.get(ENV_URL),
}
Loading

0 comments on commit 976604a

Please sign in to comment.