Skip to content

Commit

Permalink
tencentcloud - tests - Add fixture for environment variables, and typ…
Browse files Browse the repository at this point in the history
…os in query.py. (cloud-custodian#7824)
  • Loading branch information
howbazaar authored Oct 7, 2022
1 parent 594a811 commit 0211044
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions tools/c7n_tencentcloud/c7n_tencentcloud/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __repr__(cls) -> str:
class ResourceTypeInfo(metaclass=TypeMeta):
"""ResourceTypeInfo"""
# used to construct tencentcloud client
id: str = "" # requried, the field name to get resource instance id
id: str = "" # required, the field name to get resource instance id
endpoint: str = ""
service: str = ""
version: str = ""
Expand Down Expand Up @@ -182,7 +182,7 @@ def get_resource_qcs(self, resources):
get_resource_qcs
resource description https://cloud.tencent.com/document/product/598/10606
"""
# qcs::${ServiceType}:${Region}:${Account}:${ResourcePreifx}/${ResourceId}
# qcs::${ServiceType}:${Region}:${Account}:${ResourcePrefix}/${ResourceId}
# qcs::cvm:ap-singapore::instance/ins-ibu7wp2a
qcs_list = []
for r in resources:
Expand Down Expand Up @@ -280,7 +280,7 @@ def resources(self):
params = self.get_resource_query_params()
resources = self.source.resources(params)

# filter resoures
# filter resources
resources = self.filter_resources(resources)

self.check_resource_limit(resources)
Expand Down
7 changes: 7 additions & 0 deletions tools/c7n_tencentcloud/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
from c7n_tencentcloud.client import Session


@pytest.fixture(autouse=True)
def credential_env_vars(monkeypatch):
monkeypatch.setenv("TENCENTCLOUD_SECRET_ID", "xyz")
monkeypatch.setenv("TENCENTCLOUD_SECRET_KEY", "abc123")
monkeypatch.setenv("TENCENTCLOUD_REGION", "na-ashburn")


@pytest.fixture(scope="package")
def vcr_config():
return {
Expand Down
6 changes: 3 additions & 3 deletions tools/c7n_tencentcloud/tests/test_tc_provider.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0

import os

import pytest
from c7n.config import Config
from c7n_tencentcloud.client import Session
from c7n_tencentcloud.provider import TencentCloud, DEFAULT_REGION
from c7n_tencentcloud.provider import TencentCloud
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException


Expand All @@ -31,7 +30,8 @@ def test_get_session_factory(tc_provider):


test_cases = [
([], os.environ.get('TENCENTCLOUD_REGION', DEFAULT_REGION)),
# Default region matches the TENCENTCLOUD_REGION configured in conftest.py
([], "na-ashburn"),
(["ap-shanghai"], "ap-shanghai"),
(["ap-shanghai", "others"], "ap-shanghai")
]
Expand Down

0 comments on commit 0211044

Please sign in to comment.