Techdebt: Disable some duplicate tests (#7040)

This commit is contained in:
Bert Blommers 2023-11-17 20:10:11 -01:00 committed by GitHub
parent a0876916b9
commit 16dd1d483c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 72 deletions

View File

@ -1,9 +1,10 @@
import json import json
import pytest import pytest
import unittest
from copy import deepcopy from copy import deepcopy
import moto.server as server import moto.server as server
from moto import mock_eks from moto import mock_eks, settings
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
from moto.eks.exceptions import ResourceInUseException, ResourceNotFoundException from moto.eks.exceptions import ResourceInUseException, ResourceNotFoundException
from moto.eks.models import ( from moto.eks.models import (
@ -79,6 +80,8 @@ class TestNodegroup:
@pytest.fixture(autouse=True, name="test_client") @pytest.fixture(autouse=True, name="test_client")
def fixture_test_client(): def fixture_test_client():
if settings.TEST_SERVER_MODE:
raise unittest.SkipTest("No point in testing this in ServerMode")
backend = server.create_backend_app(service=SERVICE) backend = server.create_backend_app(service=SERVICE)
yield backend.test_client() yield backend.test_client()

View File

@ -1,12 +1,18 @@
"""Test the different server responses.""" """Test the different server responses."""
import json import json
import re import re
import pytest import pytest
import xmltodict import xmltodict
import unittest
import moto.server as server import moto.server as server
from moto import mock_redshift from moto import mock_redshift, settings
@pytest.fixture(scope="function", autouse=True)
def skip_in_server_mode():
if settings.TEST_SERVER_MODE:
raise unittest.SkipTest("No point in testing this in ServerMode")
@mock_redshift @mock_redshift

View File

@ -1,9 +1,10 @@
"""Test different server responses.""" """Test different server responses."""
import json import json
import pytest
import unittest
from uuid import UUID from uuid import UUID
import pytest from moto import settings
import moto.server as server import moto.server as server
from tests.test_redshiftdata.test_redshiftdata_constants import ( from tests.test_redshiftdata.test_redshiftdata_constants import (
DEFAULT_ENCODING, DEFAULT_ENCODING,
@ -13,6 +14,12 @@ from tests.test_redshiftdata.test_redshiftdata_constants import (
CLIENT_ENDPOINT = "/" CLIENT_ENDPOINT = "/"
@pytest.fixture(scope="function", autouse=True)
def skip_in_server_mode():
if settings.TEST_SERVER_MODE:
raise unittest.SkipTest("No point in testing this in ServerMode")
def headers(action): def headers(action):
return { return {
"X-Amz-Target": f"RedshiftData.{action}", "X-Amz-Target": f"RedshiftData.{action}",

View File

@ -3,6 +3,7 @@ import json
import boto3 import boto3
import pytest import pytest
import unittest
import moto.server as server import moto.server as server
from moto import mock_secretsmanager, mock_lambda, mock_iam, mock_logs, settings from moto import mock_secretsmanager, mock_lambda, mock_iam, mock_logs, settings
@ -12,6 +13,12 @@ from tests.test_awslambda.test_lambda import get_test_zip_file1
DEFAULT_SECRET_NAME = "test-secret" DEFAULT_SECRET_NAME = "test-secret"
@pytest.fixture(scope="function", autouse=True)
def skip_in_server_mode():
if settings.TEST_SERVER_MODE:
raise unittest.SkipTest("No point in testing this in ServerMode")
@mock_secretsmanager @mock_secretsmanager
def test_get_secret_value(): def test_get_secret_value():
@ -329,11 +336,7 @@ def test_rotate_secret_that_is_still_rotating():
create_secret = test_client.post( create_secret = test_client.post(
"/", "/",
data={ data={"Name": DEFAULT_SECRET_NAME, "SecretString": "foosecret"},
"Name": DEFAULT_SECRET_NAME,
"SecretString": "foosecret",
# "VersionStages": ["AWSPENDING"],
},
headers={"X-Amz-Target": "secretsmanager.CreateSecret"}, headers={"X-Amz-Target": "secretsmanager.CreateSecret"},
) )
create_secret = json.loads(create_secret.data.decode("utf-8")) create_secret = json.loads(create_secret.data.decode("utf-8"))
@ -450,78 +453,77 @@ def test_rotate_secret_rotation_lambda_arn_too_long():
assert json_data["__type"] == "InvalidParameterException" assert json_data["__type"] == "InvalidParameterException"
if not settings.TEST_SERVER_MODE: @mock_iam
@mock_lambda
@mock_logs
@mock_secretsmanager
@requires_docker
def test_rotate_secret_lambda_invocations():
conn = boto3.client("iam", region_name="us-east-1")
logs_conn = boto3.client("logs", region_name="us-east-1")
role = conn.create_role(
RoleName="role", AssumeRolePolicyDocument="some policy", Path="/my-path/"
)
@mock_iam conn = boto3.client("lambda", region_name="us-east-1")
@mock_lambda func = conn.create_function(
@mock_logs FunctionName="testFunction",
@mock_secretsmanager Code={"ZipFile": get_test_zip_file1()},
@requires_docker Handler="lambda_function.lambda_handler",
def test_rotate_secret_lambda_invocations(): Runtime="python3.11",
conn = boto3.client("iam", region_name="us-east-1") Role=role["Role"]["Arn"],
logs_conn = boto3.client("logs", region_name="us-east-1") )
role = conn.create_role(
RoleName="role", AssumeRolePolicyDocument="some policy", Path="/my-path/"
)
conn = boto3.client("lambda", region_name="us-east-1") secretsmanager_backend = server.create_backend_app("secretsmanager")
func = conn.create_function( secretsmanager_client = secretsmanager_backend.test_client()
FunctionName="testFunction",
Code={"ZipFile": get_test_zip_file1()},
Handler="lambda_function.lambda_handler",
Runtime="python3.11",
Role=role["Role"]["Arn"],
)
secretsmanager_backend = server.create_backend_app("secretsmanager") secretsmanager_client.post(
secretsmanager_client = secretsmanager_backend.test_client() "/",
data={"Name": DEFAULT_SECRET_NAME, "SecretString": "foosecret"},
headers={"X-Amz-Target": "secretsmanager.CreateSecret"},
)
secretsmanager_client.post( with pytest.raises(logs_conn.exceptions.ResourceNotFoundException):
"/", # The log group doesn't exist yet
data={"Name": DEFAULT_SECRET_NAME, "SecretString": "foosecret"}, logs_conn.describe_log_streams(logGroupName="/aws/lambda/testFunction")
headers={"X-Amz-Target": "secretsmanager.CreateSecret"},
)
with pytest.raises(logs_conn.exceptions.ResourceNotFoundException): secretsmanager_client.post(
# The log group doesn't exist yet "/",
logs_conn.describe_log_streams(logGroupName="/aws/lambda/testFunction") data={
"SecretId": DEFAULT_SECRET_NAME,
"RotationLambdaARN": func["FunctionArn"],
},
headers={"X-Amz-Target": "secretsmanager.RotateSecret"},
)
secretsmanager_client.post( # The log group now exists and has been logged to 4 times (for each invocation)
"/", logs = logs_conn.describe_log_streams(logGroupName="/aws/lambda/testFunction")
data={ assert len(logs["logStreams"]) == 4
"SecretId": DEFAULT_SECRET_NAME,
"RotationLambdaARN": func["FunctionArn"],
},
headers={"X-Amz-Target": "secretsmanager.RotateSecret"},
)
# The log group now exists and has been logged to 4 times (for each invocation)
logs = logs_conn.describe_log_streams(logGroupName="/aws/lambda/testFunction")
assert len(logs["logStreams"]) == 4
@mock_iam @mock_iam
@mock_lambda @mock_lambda
@mock_logs @mock_logs
@mock_secretsmanager @mock_secretsmanager
def test_rotate_secret_with_incorrect_lambda_arn(): def test_rotate_secret_with_incorrect_lambda_arn():
secretsmanager_backend = server.create_backend_app("secretsmanager") secretsmanager_backend = server.create_backend_app("secretsmanager")
secretsmanager_client = secretsmanager_backend.test_client() secretsmanager_client = secretsmanager_backend.test_client()
secretsmanager_client.post( secretsmanager_client.post(
"/", "/",
data={"Name": DEFAULT_SECRET_NAME, "SecretString": "foosecret"}, data={"Name": DEFAULT_SECRET_NAME, "SecretString": "foosecret"},
headers={"X-Amz-Target": "secretsmanager.CreateSecret"}, headers={"X-Amz-Target": "secretsmanager.CreateSecret"},
) )
resp = secretsmanager_client.post( resp = secretsmanager_client.post(
"/", "/",
data={"SecretId": DEFAULT_SECRET_NAME, "RotationLambdaARN": "notarealarn"}, data={"SecretId": DEFAULT_SECRET_NAME, "RotationLambdaARN": "notarealarn"},
headers={"X-Amz-Target": "secretsmanager.RotateSecret"}, headers={"X-Amz-Target": "secretsmanager.RotateSecret"},
) )
json_data = json.loads(resp.data.decode("utf-8")) json_data = json.loads(resp.data.decode("utf-8"))
assert json_data["message"] == "Resource not found for ARN 'notarealarn'." assert json_data["message"] == "Resource not found for ARN 'notarealarn'."
assert json_data["__type"] == "ResourceNotFoundException" assert json_data["__type"] == "ResourceNotFoundException"
assert resp.status_code == 404 assert resp.status_code == 404
@mock_secretsmanager @mock_secretsmanager