Skip to content

Commit

Permalink
tests: drop Python2's u marker for unicode string (ansible-collecti…
Browse files Browse the repository at this point in the history
…ons#1017)

tests: drop Python2's `u` marker for unicode string

With Python3, all strings are now unicode by default. We can remove
the u markers and clean up the data structure.

Reviewed-by: Jill R <None>
Reviewed-by: Mike Graves <[email protected]>
  • Loading branch information
goneri authored Sep 21, 2022
1 parent ad22411 commit fcc920c
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 95 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/test-python3-unicode-string.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
trivial:
- "unit-tests: Drop some ``u`` (unicode) string prefix that are not required anymore with Python3 (https://github.com/ansible-collections/amazon.aws/pull/1017)."
10 changes: 5 additions & 5 deletions plugins/module_utils/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def _hashable_policy(policy, policy_list):
'Principal': {'AWS': ['arn:aws:iam::XXXXXXXXXXXX:user/username1', 'arn:aws:iam::XXXXXXXXXXXX:user/username2']}
}]}
Returned value:
[('Statement', ((('Action', (u's3:PutObjectAcl',)),
('Effect', (u'Allow',)),
('Principal', ('AWS', ((u'arn:aws:iam::XXXXXXXXXXXX:user/username1',), (u'arn:aws:iam::XXXXXXXXXXXX:user/username2',)))),
('Resource', (u'arn:aws:s3:::test_policy/*',)), ('Sid', (u'AddCannedAcl2',)))),
('Version', (u'2012-10-17',)))]
[('Statement', ((('Action', ('s3:PutObjectAcl',)),
('Effect', ('Allow',)),
('Principal', ('AWS', (('arn:aws:iam::XXXXXXXXXXXX:user/username1',), ('arn:aws:iam::XXXXXXXXXXXX:user/username2',)))),
('Resource', ('arn:aws:s3:::test_policy/*',)), ('Sid', ('AddCannedAcl2',)))),
('Version', ('2012-10-17',)))]
"""
# Amazon will automatically convert bool and int to strings for us
Expand Down
150 changes: 75 additions & 75 deletions tests/unit/plugins/inventory/test_aws_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,81 +30,81 @@


instances = {
u'Instances': [
{u'Monitoring': {u'State': 'disabled'},
u'PublicDnsName': 'ec2-12-345-67-890.compute-1.amazonaws.com',
u'State': {u'Code': 16, u'Name': 'running'},
u'EbsOptimized': False,
u'LaunchTime': datetime.datetime(2017, 10, 31, 12, 59, 25),
u'PublicIpAddress': '12.345.67.890',
u'PrivateIpAddress': '098.76.54.321',
u'ProductCodes': [],
u'VpcId': 'vpc-12345678',
u'StateTransitionReason': '',
u'InstanceId': 'i-00000000000000000',
u'EnaSupport': True,
u'ImageId': 'ami-12345678',
u'PrivateDnsName': 'ip-098-76-54-321.ec2.internal',
u'KeyName': 'testkey',
u'SecurityGroups': [{u'GroupName': 'default', u'GroupId': 'sg-12345678'}],
u'ClientToken': '',
u'SubnetId': 'subnet-12345678',
u'InstanceType': 't2.micro',
u'NetworkInterfaces': [
{u'Status': 'in-use',
u'MacAddress': '12:a0:50:42:3d:a4',
u'SourceDestCheck': True,
u'VpcId': 'vpc-12345678',
u'Description': '',
u'NetworkInterfaceId': 'eni-12345678',
u'PrivateIpAddresses': [
{u'PrivateDnsName': 'ip-098-76-54-321.ec2.internal',
u'PrivateIpAddress': '098.76.54.321',
u'Primary': True,
u'Association':
{u'PublicIp': '12.345.67.890',
u'PublicDnsName': 'ec2-12-345-67-890.compute-1.amazonaws.com',
u'IpOwnerId': 'amazon'}}],
u'PrivateDnsName': 'ip-098-76-54-321.ec2.internal',
u'Attachment':
{u'Status': 'attached',
u'DeviceIndex': 0,
u'DeleteOnTermination': True,
u'AttachmentId': 'eni-attach-12345678',
u'AttachTime': datetime.datetime(2017, 10, 31, 12, 59, 25)},
u'Groups': [
{u'GroupName': 'default',
u'GroupId': 'sg-12345678'}],
u'Ipv6Addresses': [],
u'OwnerId': '123456789000',
u'PrivateIpAddress': '098.76.54.321',
u'SubnetId': 'subnet-12345678',
u'Association':
{u'PublicIp': '12.345.67.890',
u'PublicDnsName': 'ec2-12-345-67-890.compute-1.amazonaws.com',
u'IpOwnerId': 'amazon'}}],
u'SourceDestCheck': True,
u'Placement':
{u'Tenancy': 'default',
u'GroupName': '',
u'AvailabilityZone': 'us-east-1c'},
u'Hypervisor': 'xen',
u'BlockDeviceMappings': [
{u'DeviceName': '/dev/xvda',
u'Ebs':
{u'Status': 'attached',
u'DeleteOnTermination': True,
u'VolumeId': 'vol-01234567890000000',
u'AttachTime': datetime.datetime(2017, 10, 31, 12, 59, 26)}}],
u'Architecture': 'x86_64',
u'RootDeviceType': 'ebs',
u'RootDeviceName': '/dev/xvda',
u'VirtualizationType': 'hvm',
u'Tags': [{u'Value': 'test', u'Key': 'ansible'}, {u'Value': 'aws_ec2', u'Key': 'Name'}],
u'AmiLaunchIndex': 0}],
u'ReservationId': 'r-01234567890000000',
u'Groups': [],
u'OwnerId': '123456789000'
'Instances': [
{'Monitoring': {'State': 'disabled'},
'PublicDnsName': 'ec2-12-345-67-890.compute-1.amazonaws.com',
'State': {'Code': 16, 'Name': 'running'},
'EbsOptimized': False,
'LaunchTime': datetime.datetime(2017, 10, 31, 12, 59, 25),
'PublicIpAddress': '12.345.67.890',
'PrivateIpAddress': '098.76.54.321',
'ProductCodes': [],
'VpcId': 'vpc-12345678',
'StateTransitionReason': '',
'InstanceId': 'i-00000000000000000',
'EnaSupport': True,
'ImageId': 'ami-12345678',
'PrivateDnsName': 'ip-098-76-54-321.ec2.internal',
'KeyName': 'testkey',
'SecurityGroups': [{'GroupName': 'default', 'GroupId': 'sg-12345678'}],
'ClientToken': '',
'SubnetId': 'subnet-12345678',
'InstanceType': 't2.micro',
'NetworkInterfaces': [
{'Status': 'in-use',
'MacAddress': '12:a0:50:42:3d:a4',
'SourceDestCheck': True,
'VpcId': 'vpc-12345678',
'Description': '',
'NetworkInterfaceId': 'eni-12345678',
'PrivateIpAddresses': [
{'PrivateDnsName': 'ip-098-76-54-321.ec2.internal',
'PrivateIpAddress': '098.76.54.321',
'Primary': True,
'Association':
{'PublicIp': '12.345.67.890',
'PublicDnsName': 'ec2-12-345-67-890.compute-1.amazonaws.com',
'IpOwnerId': 'amazon'}}],
'PrivateDnsName': 'ip-098-76-54-321.ec2.internal',
'Attachment':
{'Status': 'attached',
'DeviceIndex': 0,
'DeleteOnTermination': True,
'AttachmentId': 'eni-attach-12345678',
'AttachTime': datetime.datetime(2017, 10, 31, 12, 59, 25)},
'Groups': [
{'GroupName': 'default',
'GroupId': 'sg-12345678'}],
'Ipv6Addresses': [],
'OwnerId': '123456789000',
'PrivateIpAddress': '098.76.54.321',
'SubnetId': 'subnet-12345678',
'Association':
{'PublicIp': '12.345.67.890',
'PublicDnsName': 'ec2-12-345-67-890.compute-1.amazonaws.com',
'IpOwnerId': 'amazon'}}],
'SourceDestCheck': True,
'Placement':
{'Tenancy': 'default',
'GroupName': '',
'AvailabilityZone': 'us-east-1c'},
'Hypervisor': 'xen',
'BlockDeviceMappings': [
{'DeviceName': '/dev/xvda',
'Ebs':
{'Status': 'attached',
'DeleteOnTermination': True,
'VolumeId': 'vol-01234567890000000',
'AttachTime': datetime.datetime(2017, 10, 31, 12, 59, 26)}}],
'Architecture': 'x86_64',
'RootDeviceType': 'ebs',
'RootDeviceName': '/dev/xvda',
'VirtualizationType': 'hvm',
'Tags': [{'Value': 'test', 'Key': 'ansible'}, {'Value': 'aws_ec2', 'Key': 'Name'}],
'AmiLaunchIndex': 0}],
'ReservationId': 'r-01234567890000000',
'Groups': [],
'OwnerId': '123456789000'
}


Expand Down
30 changes: 15 additions & 15 deletions tests/unit/plugins/modules/test_ec2_security_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

def test_from_permission():
internal_http = {
u'FromPort': 80,
u'IpProtocol': 'tcp',
u'IpRanges': [
'FromPort': 80,
'IpProtocol': 'tcp',
'IpRanges': [
{
u'CidrIp': '10.0.0.0/8',
u'Description': 'Foo Bar Baz'
'CidrIp': '10.0.0.0/8',
'Description': 'Foo Bar Baz'
},
],
u'Ipv6Ranges': [
{u'CidrIpv6': 'fe80::94cc:8aff:fef6:9cc/64'},
'Ipv6Ranges': [
{'CidrIpv6': 'fe80::94cc:8aff:fef6:9cc/64'},
],
u'PrefixListIds': [],
u'ToPort': 80,
u'UserIdGroupPairs': [],
'PrefixListIds': [],
'ToPort': 80,
'UserIdGroupPairs': [],
}
perms = list(group_module.rule_from_group_permission(internal_http))
assert len(perms) == 2
Expand All @@ -42,13 +42,13 @@ def test_from_permission():
assert perms[0].port_range == (None, None)

internal_prefix_http = {
u'FromPort': 80,
u'IpProtocol': 'tcp',
u'PrefixListIds': [
'FromPort': 80,
'IpProtocol': 'tcp',
'PrefixListIds': [
{'PrefixListId': 'p-1234'}
],
u'ToPort': 80,
u'UserIdGroupPairs': [],
'ToPort': 80,
'UserIdGroupPairs': [],
}
perms = list(group_module.rule_from_group_permission(internal_prefix_http))
assert len(perms) == 1
Expand Down

0 comments on commit fcc920c

Please sign in to comment.