From acc3ca5f640043e9752578ba3b0ebcbb8d7f7c24 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Wed, 5 Jul 2023 22:47:50 +0000 Subject: [PATCH] Techdebt: Replace sure with regular asserts in EFS (#6486) --- tests/test_efs/test_access_point_tagging.py | 23 +++--- tests/test_efs/test_access_points.py | 79 +++++++++---------- tests/test_efs/test_file_system.py | 8 +- tests/test_efs/test_filesystem_tagging.py | 23 +++--- tests/test_efs/test_lifecycle_config.py | 14 ++-- tests/test_efs/test_mount_target.py | 6 +- .../test_mount_target_security_groups.py | 21 ++--- 7 files changed, 88 insertions(+), 86 deletions(-) diff --git a/tests/test_efs/test_access_point_tagging.py b/tests/test_efs/test_access_point_tagging.py index a92ab24a6..8b249c66a 100644 --- a/tests/test_efs/test_access_point_tagging.py +++ b/tests/test_efs/test_access_point_tagging.py @@ -17,7 +17,7 @@ def test_list_tags_for_resource__without_tags(efs, file_system): ] resp = efs.list_tags_for_resource(ResourceId=ap_id) - resp.should.have.key("Tags").equals([]) + assert resp["Tags"] == [] def test_list_tags_for_resource__with_tags(efs, file_system): @@ -30,9 +30,10 @@ def test_list_tags_for_resource__with_tags(efs, file_system): )["AccessPointId"] resp = efs.list_tags_for_resource(ResourceId=ap_id) - resp.should.have.key("Tags").equals( - [{"Key": "key", "Value": "value"}, {"Key": "Name", "Value": "myname"}] - ) + assert resp["Tags"] == [ + {"Key": "key", "Value": "value"}, + {"Key": "Name", "Value": "myname"}, + ] def test_tag_resource(efs, file_system): @@ -48,9 +49,10 @@ def test_tag_resource(efs, file_system): ) resp = efs.list_tags_for_resource(ResourceId=ap_id) - resp.should.have.key("Tags").equals( - [{"Key": "key", "Value": "value"}, {"Key": "Name", "Value": "myname"}] - ) + assert resp["Tags"] == [ + {"Key": "key", "Value": "value"}, + {"Key": "Name", "Value": "myname"}, + ] def test_untag_resource(efs, file_system): @@ -70,6 +72,7 @@ def test_untag_resource(efs, file_system): efs.untag_resource(ResourceId=ap_id, TagKeys=["key2"]) resp = efs.list_tags_for_resource(ResourceId=ap_id) - resp.should.have.key("Tags").equals( - [{"Key": "key1", "Value": "val1"}, {"Key": "key3", "Value": "val3"}] - ) + assert resp["Tags"] == [ + {"Key": "key1", "Value": "val1"}, + {"Key": "key3", "Value": "val3"}, + ] diff --git a/tests/test_efs/test_access_points.py b/tests/test_efs/test_access_points.py index 64061b042..be783a75c 100644 --- a/tests/test_efs/test_access_points.py +++ b/tests/test_efs/test_access_points.py @@ -14,21 +14,21 @@ def fixture_file_system(efs): def test_describe_access_points__initial(efs): resp = efs.describe_access_points() - resp.should.have.key("AccessPoints").equals([]) + assert resp["AccessPoints"] == [] def test_create_access_point__simple(efs, file_system): fs_id = file_system["FileSystemId"] resp = efs.create_access_point(ClientToken="ct", FileSystemId=fs_id) - resp.should.have.key("ClientToken").equals("ct") - resp.should.have.key("AccessPointId") - resp.should.have.key("AccessPointArn") - resp.should.have.key("FileSystemId").equals(fs_id) - resp.should.have.key("OwnerId").equals(ACCOUNT_ID) - resp.should.have.key("LifeCycleState").equals("available") + assert resp["ClientToken"] == "ct" + assert "AccessPointId" in resp + assert "AccessPointArn" in resp + assert resp["FileSystemId"] == fs_id + assert resp["OwnerId"] == ACCOUNT_ID + assert resp["LifeCycleState"] == "available" - resp.should.have.key("RootDirectory").equals({"Path": "/"}) + assert resp["RootDirectory"] == {"Path": "/"} def test_create_access_point__full(efs, file_system): @@ -49,29 +49,26 @@ def test_create_access_point__full(efs, file_system): }, ) - resp.should.have.key("ClientToken").equals("ct") - resp.should.have.key("Name").equals("myname") - resp.should.have.key("Tags").equals( - [{"Key": "key", "Value": "value"}, {"Key": "Name", "Value": "myname"}] - ) - resp.should.have.key("AccessPointId") - resp.should.have.key("AccessPointArn") - resp.should.have.key("FileSystemId").equals(fs_id) - resp.should.have.key("PosixUser").equals( - {"Uid": 123, "Gid": 123, "SecondaryGids": [124, 125]} - ) - resp.should.have.key("RootDirectory").equals( - { - "Path": "/root/path", - "CreationInfo": { - "OwnerUid": 987, - "OwnerGid": 986, - "Permissions": "root_permissions", - }, - } - ) - resp.should.have.key("OwnerId").equals(ACCOUNT_ID) - resp.should.have.key("LifeCycleState").equals("available") + assert resp["ClientToken"] == "ct" + assert resp["Name"] == "myname" + assert resp["Tags"] == [ + {"Key": "key", "Value": "value"}, + {"Key": "Name", "Value": "myname"}, + ] + assert "AccessPointId" in resp + assert "AccessPointArn" in resp + assert resp["FileSystemId"] == fs_id + assert resp["PosixUser"] == {"Uid": 123, "Gid": 123, "SecondaryGids": [124, 125]} + assert resp["RootDirectory"] == { + "Path": "/root/path", + "CreationInfo": { + "OwnerUid": 987, + "OwnerGid": 986, + "Permissions": "root_permissions", + }, + } + assert resp["OwnerId"] == ACCOUNT_ID + assert resp["LifeCycleState"] == "available" def test_describe_access_point(efs, file_system): @@ -82,15 +79,15 @@ def test_describe_access_point(efs, file_system): ] resp = efs.describe_access_points(AccessPointId=access_point_id) - resp.should.have.key("AccessPoints").length_of(1) + assert len(resp["AccessPoints"]) == 1 access_point = resp["AccessPoints"][0] - access_point.should.have.key("ClientToken").equals("ct") - access_point.should.have.key("AccessPointId") - access_point.should.have.key("AccessPointArn") - access_point.should.have.key("FileSystemId").equals(fs_id) - access_point.should.have.key("OwnerId").equals(ACCOUNT_ID) - access_point.should.have.key("LifeCycleState").equals("available") + assert access_point["ClientToken"] == "ct" + assert "AccessPointId" in access_point + assert "AccessPointArn" in access_point + assert access_point["FileSystemId"] == fs_id + assert access_point["OwnerId"] == ACCOUNT_ID + assert access_point["LifeCycleState"] == "available" def test_describe_access_points__multiple(efs, file_system): @@ -100,7 +97,7 @@ def test_describe_access_points__multiple(efs, file_system): efs.create_access_point(ClientToken="ct2", FileSystemId=fs_id) resp = efs.describe_access_points() - resp.should.have.key("AccessPoints").length_of(2) + assert len(resp["AccessPoints"]) == 2 def test_delete_access_points(efs, file_system): @@ -118,7 +115,7 @@ def test_delete_access_points(efs, file_system): # We can only find one resp = efs.describe_access_points() - resp.should.have.key("AccessPoints").length_of(1) + assert len(resp["AccessPoints"]) == 1 # The first one still exists efs.describe_access_points(AccessPointId=ap_id1) @@ -127,4 +124,4 @@ def test_delete_access_points(efs, file_system): with pytest.raises(ClientError) as exc_info: efs.describe_access_points(AccessPointId=ap_id2) err = exc_info.value.response["Error"] - err["Code"].should.equal("AccessPointNotFound") + assert err["Code"] == "AccessPointNotFound" diff --git a/tests/test_efs/test_file_system.py b/tests/test_efs/test_file_system.py index 9525b727f..324bfb0cb 100644 --- a/tests/test_efs/test_file_system.py +++ b/tests/test_efs/test_file_system.py @@ -171,8 +171,8 @@ def test_describe_file_systems_using_identifier(efs): # Describe the file system. desc_fs_resp = efs.describe_file_systems(FileSystemId=fs_id) - desc_fs_resp.should.have.key("FileSystems").length_of(1) - desc_fs_resp["FileSystems"][0].should.have.key("FileSystemId").equals(fs_id) + assert len(desc_fs_resp["FileSystems"]) == 1 + assert desc_fs_resp["FileSystems"][0]["FileSystemId"] == fs_id assert desc_fs_resp["FileSystems"][0]["Name"] == "" @@ -180,9 +180,9 @@ def test_describe_file_systems_using_unknown_identifier(efs): with pytest.raises(ClientError) as exc: efs.describe_file_systems(FileSystemId="unknown") err = exc.value.response["Error"] - err["Code"].should.equal("FileSystemNotFound") + assert err["Code"] == "FileSystemNotFound" # Verified against AWS - err["Message"].should.equal("File system 'unknown' does not exist.") + assert err["Message"] == "File system 'unknown' does not exist." def test_describe_file_systems_minimal_case(efs): diff --git a/tests/test_efs/test_filesystem_tagging.py b/tests/test_efs/test_filesystem_tagging.py index c5e025d10..6b18c4cd0 100644 --- a/tests/test_efs/test_filesystem_tagging.py +++ b/tests/test_efs/test_filesystem_tagging.py @@ -6,7 +6,7 @@ def test_list_tags_for_resource__without_tags(efs): fs_id = file_system["FileSystemId"] resp = efs.list_tags_for_resource(ResourceId=fs_id) - resp.should.have.key("Tags").equals([]) + assert resp["Tags"] == [] def test_list_tags_for_resource__with_tags(efs): @@ -17,9 +17,10 @@ def test_list_tags_for_resource__with_tags(efs): fs_id = file_system["FileSystemId"] resp = efs.list_tags_for_resource(ResourceId=fs_id) - resp.should.have.key("Tags").equals( - [{"Key": "key", "Value": "value"}, {"Key": "Name", "Value": "myname"}] - ) + assert resp["Tags"] == [ + {"Key": "key", "Value": "value"}, + {"Key": "Name", "Value": "myname"}, + ] def test_tag_resource(efs): @@ -35,9 +36,10 @@ def test_tag_resource(efs): ) resp = efs.list_tags_for_resource(ResourceId=fs_id) - resp.should.have.key("Tags").equals( - [{"Key": "key", "Value": "value"}, {"Key": "Name", "Value": "myname"}] - ) + assert resp["Tags"] == [ + {"Key": "key", "Value": "value"}, + {"Key": "Name", "Value": "myname"}, + ] def test_untag_resource(efs): @@ -54,6 +56,7 @@ def test_untag_resource(efs): efs.untag_resource(ResourceId=fs_id, TagKeys=["key2"]) resp = efs.list_tags_for_resource(ResourceId=fs_id) - resp.should.have.key("Tags").equals( - [{"Key": "key1", "Value": "val1"}, {"Key": "key3", "Value": "val3"}] - ) + assert resp["Tags"] == [ + {"Key": "key1", "Value": "val1"}, + {"Key": "key3", "Value": "val3"}, + ] diff --git a/tests/test_efs/test_lifecycle_config.py b/tests/test_efs/test_lifecycle_config.py index 6c1f7f896..1b92fa51e 100644 --- a/tests/test_efs/test_lifecycle_config.py +++ b/tests/test_efs/test_lifecycle_config.py @@ -8,8 +8,8 @@ def test_describe_filesystem_config__unknown(efs): with pytest.raises(ClientError) as exc_info: efs.describe_lifecycle_configuration(FileSystemId="unknown") err = exc_info.value.response["Error"] - err["Code"].should.equal("FileSystemNotFound") - err["Message"].should.equal("File system 'unknown' does not exist.") + assert err["Code"] == "FileSystemNotFound" + assert err["Message"] == "File system 'unknown' does not exist." def test_describe_filesystem_config__initial(efs): @@ -17,7 +17,7 @@ def test_describe_filesystem_config__initial(efs): fs_id = create_fs_resp["FileSystemId"] resp = efs.describe_lifecycle_configuration(FileSystemId=fs_id) - resp.should.have.key("LifecyclePolicies").equals([]) + assert resp["LifecyclePolicies"] == [] def test_put_lifecycle_configuration(efs): @@ -30,10 +30,10 @@ def test_put_lifecycle_configuration(efs): resp = efs.put_lifecycle_configuration( FileSystemId=fs_id, LifecyclePolicies=[{"TransitionToIA": "AFTER_30_DAYS"}] ) - resp.should.have.key("LifecyclePolicies").length_of(1) - resp["LifecyclePolicies"][0].should.equal({"TransitionToIA": "AFTER_30_DAYS"}) + assert len(resp["LifecyclePolicies"]) == 1 + assert resp["LifecyclePolicies"][0] == {"TransitionToIA": "AFTER_30_DAYS"} # Describe the lifecycle configuration resp = efs.describe_lifecycle_configuration(FileSystemId=fs_id) - resp.should.have.key("LifecyclePolicies").length_of(1) - resp["LifecyclePolicies"][0].should.equal({"TransitionToIA": "AFTER_30_DAYS"}) + assert len(resp["LifecyclePolicies"]) == 1 + assert resp["LifecyclePolicies"][0] == {"TransitionToIA": "AFTER_30_DAYS"} diff --git a/tests/test_efs/test_mount_target.py b/tests/test_efs/test_mount_target.py index b5f1209b0..e168a2440 100644 --- a/tests/test_efs/test_mount_target.py +++ b/tests/test_efs/test_mount_target.py @@ -258,10 +258,8 @@ def test_describe_mount_targets__by_access_point_id( ap_resp = efs.describe_mount_targets(AccessPointId=access_point_id) # Check the list results. - ap_resp.should.have.key("MountTargets").length_of(1) - ap_resp["MountTargets"][0]["MountTargetId"].should.equal( - create_resp["MountTargetId"] - ) + assert len(ap_resp["MountTargets"]) == 1 + assert ap_resp["MountTargets"][0]["MountTargetId"] == create_resp["MountTargetId"] def test_describe_mount_targets_paging(efs, ec2, file_system): diff --git a/tests/test_efs/test_mount_target_security_groups.py b/tests/test_efs/test_mount_target_security_groups.py index 552fe544b..b5858fa17 100644 --- a/tests/test_efs/test_mount_target_security_groups.py +++ b/tests/test_efs/test_mount_target_security_groups.py @@ -22,8 +22,8 @@ def test_describe_mount_target_security_groups__unknown(efs): with pytest.raises(ClientError) as exc_info: efs.describe_mount_target_security_groups(MountTargetId="mt-asdf1234asdf") err = exc_info.value.response["Error"] - err["Code"].should.equal("MountTargetNotFound") - err["Message"].should.equal("Mount target 'mt-asdf1234asdf' does not exist.") + assert err["Code"] == "MountTargetNotFound" + assert err["Message"] == "Mount target 'mt-asdf1234asdf' does not exist." def test_describe_mount_target_security_groups(efs, ec2, file_system, subnet): @@ -44,7 +44,7 @@ def test_describe_mount_target_security_groups(efs, ec2, file_system, subnet): # Describe it's Security Groups resp = efs.describe_mount_target_security_groups(MountTargetId=mount_target_id) - resp.should.have.key("SecurityGroups").equals([security_group_id]) + assert resp["SecurityGroups"] == [security_group_id] def test_modify_mount_target_security_groups__unknown(efs): @@ -53,8 +53,8 @@ def test_modify_mount_target_security_groups__unknown(efs): MountTargetId="mt-asdf1234asdf", SecurityGroups=[] ) err = exc_info.value.response["Error"] - err["Code"].should.equal("MountTargetNotFound") - err["Message"].should.equal("Mount target 'mt-asdf1234asdf' does not exist.") + assert err["Code"] == "MountTargetNotFound" + assert err["Message"] == "Mount target 'mt-asdf1234asdf' does not exist." def test_modify_mount_target_security_groups(efs, ec2, file_system, subnet): @@ -89,12 +89,13 @@ def test_modify_mount_target_security_groups(efs, ec2, file_system, subnet): # Describe it's Security Groups resp = efs.describe_mount_target_security_groups(MountTargetId=mount_target_id) - resp.should.have.key("SecurityGroups").equals([sg_id_2, sg_id_3]) + assert resp["SecurityGroups"] == [sg_id_2, sg_id_3] # Verify EC2 reflects this change resp = ec2.describe_network_interfaces(NetworkInterfaceIds=[network_interface_id]) network_interface = resp["NetworkInterfaces"][0] - network_interface["Groups"].should.have.length_of(2) - set([sg["GroupId"] for sg in network_interface["Groups"]]).should.equal( - {sg_id_2, sg_id_3} - ) + assert len(network_interface["Groups"]) == 2 + assert set([sg["GroupId"] for sg in network_interface["Groups"]]) == { + sg_id_2, + sg_id_3, + }