From 737636f9df9f1614cd81ad3ae6659969cee5985f Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Tue, 2 Feb 2021 16:31:26 +0000 Subject: [PATCH] Tech debt (#3653) --- moto/cognitoidp/models.py | 23 +------------------ moto/sagemaker/models.py | 4 +--- .../test_cloudwatch/test_cloudwatch_boto3.py | 16 ------------- tests/test_ec2/test_amis.py | 1 - tests/test_ec2/test_dhcp_options.py | 1 - tests/test_ec2/test_elastic_block_store.py | 1 - tests/test_ec2/test_elastic_ip_addresses.py | 1 - .../test_elastic_network_interfaces.py | 1 - tests/test_ec2/test_general.py | 1 - .../test_iam_instance_profile_associations.py | 1 - tests/test_ec2/test_instances.py | 1 - tests/test_ec2/test_internet_gateways.py | 1 - tests/test_ec2/test_key_pairs.py | 1 - tests/test_ec2/test_route_tables.py | 1 - tests/test_ec2/test_security_groups.py | 1 - tests/test_ec2/test_subnets.py | 1 - tests/test_ec2/test_vpc_peering.py | 1 - tests/test_ec2/test_vpcs.py | 1 - tests/test_sagemaker/test_sagemaker_models.py | 8 +++++++ tests/test_sqs/test_sqs.py | 2 +- 20 files changed, 11 insertions(+), 57 deletions(-) diff --git a/moto/cognitoidp/models.py b/moto/cognitoidp/models.py index b51888cb3..bab677903 100644 --- a/moto/cognitoidp/models.py +++ b/moto/cognitoidp/models.py @@ -699,28 +699,7 @@ class CognitoIdpBackend(BaseBackend): if not client: raise ResourceNotFoundError(client_id) - if auth_flow == "ADMIN_NO_SRP_AUTH": - username = auth_parameters.get("USERNAME") - password = auth_parameters.get("PASSWORD") - user = user_pool.users.get(username) - if not user: - raise UserNotFoundError(username) - - if user.password != password: - raise NotAuthorizedError(username) - - if user.status == UserStatus["FORCE_CHANGE_PASSWORD"]: - session = str(uuid.uuid4()) - self.sessions[session] = user_pool - - return { - "ChallengeName": "NEW_PASSWORD_REQUIRED", - "ChallengeParameters": {}, - "Session": session, - } - - return self._log_user_in(user_pool, client, username) - elif auth_flow == "ADMIN_USER_PASSWORD_AUTH": + if auth_flow in ("ADMIN_USER_PASSWORD_AUTH", "ADMIN_NO_SRP_AUTH"): username = auth_parameters.get("USERNAME") password = auth_parameters.get("PASSWORD") user = user_pool.users.get(username) diff --git a/moto/sagemaker/models.py b/moto/sagemaker/models.py index f53cc3eec..8fef306b8 100644 --- a/moto/sagemaker/models.py +++ b/moto/sagemaker/models.py @@ -580,9 +580,7 @@ class SageMakerModelBackend(BaseBackend): message = "Could not find model '{}'.".format( Model.arn_for_model_name(model_name, self.region_name) ) - raise RESTError( - error_type="ValidationException", message=message, template="error_json", - ) + raise ValidationError(message=message) def list_models(self): models = [] diff --git a/tests/test_cloudwatch/test_cloudwatch_boto3.py b/tests/test_cloudwatch/test_cloudwatch_boto3.py index c15805964..7c4e94904 100644 --- a/tests/test_cloudwatch/test_cloudwatch_boto3.py +++ b/tests/test_cloudwatch/test_cloudwatch_boto3.py @@ -387,22 +387,6 @@ def test_duplicate_put_metric_data(): Namespace="tester", Dimensions=[{"Name": "Name", "Value": "B"}] )["Metrics"] len(result).should.equal(1) - - conn.put_metric_data( - Namespace="tester", - MetricData=[ - dict( - MetricName="metric", - Dimensions=[{"Name": "Name", "Value": "B"}], - Value=1.5, - Timestamp=utc_now, - ) - ], - ) - - result = conn.list_metrics( - Namespace="tester", Dimensions=[{"Name": "Name", "Value": "B"}] - )["Metrics"] result.should.equal( [ { diff --git a/tests/test_ec2/test_amis.py b/tests/test_ec2/test_amis.py index ac0e7fe11..da9a80a2b 100644 --- a/tests/test_ec2/test_amis.py +++ b/tests/test_ec2/test_amis.py @@ -6,7 +6,6 @@ import boto3 from boto.exception import EC2ResponseError from botocore.exceptions import ClientError -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import sure # noqa diff --git a/tests/test_ec2/test_dhcp_options.py b/tests/test_ec2/test_dhcp_options.py index 85bc7f244..703a2f9a1 100644 --- a/tests/test_ec2/test_dhcp_options.py +++ b/tests/test_ec2/test_dhcp_options.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import boto3 diff --git a/tests/test_ec2/test_elastic_block_store.py b/tests/test_ec2/test_elastic_block_store.py index 7bf9f7c18..f7b8277bc 100644 --- a/tests/test_ec2/test_elastic_block_store.py +++ b/tests/test_ec2/test_elastic_block_store.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals import boto import boto3 -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import sure # noqa from boto.exception import EC2ResponseError diff --git a/tests/test_ec2/test_elastic_ip_addresses.py b/tests/test_ec2/test_elastic_ip_addresses.py index cb89c025c..584ec3516 100644 --- a/tests/test_ec2/test_elastic_ip_addresses.py +++ b/tests/test_ec2/test_elastic_ip_addresses.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import boto diff --git a/tests/test_ec2/test_elastic_network_interfaces.py b/tests/test_ec2/test_elastic_network_interfaces.py index a5bb019b0..db6dcc04f 100644 --- a/tests/test_ec2/test_elastic_network_interfaces.py +++ b/tests/test_ec2/test_elastic_network_interfaces.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import boto3 diff --git a/tests/test_ec2/test_general.py b/tests/test_ec2/test_general.py index 4d509e73b..0abe12b78 100644 --- a/tests/test_ec2/test_general.py +++ b/tests/test_ec2/test_general.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import boto diff --git a/tests/test_ec2/test_iam_instance_profile_associations.py b/tests/test_ec2/test_iam_instance_profile_associations.py index bf44deb6d..379f614f3 100644 --- a/tests/test_ec2/test_iam_instance_profile_associations.py +++ b/tests/test_ec2/test_iam_instance_profile_associations.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import time diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 53ebfe745..62a4b7350 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -# Ensure 'pytest.raises' context manager support for Python 2.6 from botocore.exceptions import ClientError import pytest diff --git a/tests/test_ec2/test_internet_gateways.py b/tests/test_ec2/test_internet_gateways.py index 49cc6e38c..c7f92b8a3 100644 --- a/tests/test_ec2/test_internet_gateways.py +++ b/tests/test_ec2/test_internet_gateways.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import re diff --git a/tests/test_ec2/test_key_pairs.py b/tests/test_ec2/test_key_pairs.py index dcca8b116..753cc8040 100644 --- a/tests/test_ec2/test_key_pairs.py +++ b/tests/test_ec2/test_key_pairs.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import boto diff --git a/tests/test_ec2/test_route_tables.py b/tests/test_ec2/test_route_tables.py index 62d330d1c..697fedd76 100644 --- a/tests/test_ec2/test_route_tables.py +++ b/tests/test_ec2/test_route_tables.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import boto diff --git a/tests/test_ec2/test_security_groups.py b/tests/test_ec2/test_security_groups.py index 3ba2be5eb..6558ca6d6 100644 --- a/tests/test_ec2/test_security_groups.py +++ b/tests/test_ec2/test_security_groups.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals import copy import json -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import boto3 diff --git a/tests/test_ec2/test_subnets.py b/tests/test_ec2/test_subnets.py index e5baf2e2d..77fe3e0ad 100644 --- a/tests/test_ec2/test_subnets.py +++ b/tests/test_ec2/test_subnets.py @@ -6,7 +6,6 @@ import boto import boto3 import boto.vpc -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest import sure # noqa from boto.exception import EC2ResponseError diff --git a/tests/test_ec2/test_vpc_peering.py b/tests/test_ec2/test_vpc_peering.py index 2ffe89fca..20f07f724 100644 --- a/tests/test_ec2/test_vpc_peering.py +++ b/tests/test_ec2/test_vpc_peering.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest from moto.ec2.exceptions import EC2ClientError from botocore.exceptions import ClientError diff --git a/tests/test_ec2/test_vpcs.py b/tests/test_ec2/test_vpcs.py index 657b0f863..5484a34dd 100644 --- a/tests/test_ec2/test_vpcs.py +++ b/tests/test_ec2/test_vpcs.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -# Ensure 'pytest.raises' context manager support for Python 2.6 import pytest from moto.ec2.exceptions import EC2ClientError from botocore.exceptions import ClientError diff --git a/tests/test_sagemaker/test_sagemaker_models.py b/tests/test_sagemaker/test_sagemaker_models.py index 91fc3bb5b..975811be4 100644 --- a/tests/test_sagemaker/test_sagemaker_models.py +++ b/tests/test_sagemaker/test_sagemaker_models.py @@ -45,6 +45,14 @@ def test_describe_model(): assert model.get("ModelName").should.equal("blah") +@mock_sagemaker +def test_describe_model_not_found(): + client = boto3.client("sagemaker", region_name="us-east-1") + with pytest.raises(ClientError) as err: + client.describe_model(ModelName="unknown") + assert err.value.response["Error"]["Message"].should.contain("Could not find model") + + @mock_sagemaker def test_create_model(): client = boto3.client("sagemaker", region_name="us-east-1") diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index b7cbc793a..5b71e5328 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -2349,7 +2349,7 @@ def test_fifo_queue_deduplication_withoutid(msg_1, msg_2, expected_count): @mock_sqs def test_fifo_queue_send_duplicate_messages_after_deduplication_time_limit(): if settings.TEST_SERVER_MODE: - raise SkipTest("Cant manipulate time in server mode") + raise SkipTest("Cant patch env variables in server mode") sqs = boto3.resource("sqs", region_name="us-east-1") msg_queue = sqs.create_queue(