Merge branch 'master' into batch
This commit is contained in:
commit
d67ef8d128
22 changed files with 961 additions and 88 deletions
|
|
@ -8,7 +8,7 @@ from boto.ec2.autoscale import Tag
|
|||
import boto.ec2.elb
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_autoscaling, mock_ec2_deprecated, mock_elb_deprecated, mock_autoscaling_deprecated, mock_ec2
|
||||
from moto import mock_autoscaling, mock_ec2_deprecated, mock_elb_deprecated, mock_elb, mock_autoscaling_deprecated, mock_ec2
|
||||
from tests.helpers import requires_boto_gte
|
||||
|
||||
|
||||
|
|
@ -484,6 +484,168 @@ Boto3
|
|||
'''
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_elb
|
||||
def test_describe_load_balancers():
|
||||
INSTANCE_COUNT = 2
|
||||
|
||||
elb_client = boto3.client('elb', region_name='us-east-1')
|
||||
elb_client.create_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Listeners=[
|
||||
{'Protocol': 'tcp', 'LoadBalancerPort': 80, 'InstancePort': 8080}],
|
||||
AvailabilityZones=['us-east-1a', 'us-east-1b']
|
||||
)
|
||||
|
||||
client = boto3.client('autoscaling', region_name='us-east-1')
|
||||
client.create_launch_configuration(
|
||||
LaunchConfigurationName='test_launch_configuration'
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName='test_asg',
|
||||
LaunchConfigurationName='test_launch_configuration',
|
||||
LoadBalancerNames=['my-lb'],
|
||||
MinSize=0,
|
||||
MaxSize=INSTANCE_COUNT,
|
||||
DesiredCapacity=INSTANCE_COUNT,
|
||||
Tags=[{
|
||||
"ResourceId": 'test_asg',
|
||||
"Key": 'test_key',
|
||||
"Value": 'test_value',
|
||||
"PropagateAtLaunch": True
|
||||
}]
|
||||
)
|
||||
|
||||
response = client.describe_load_balancers(AutoScalingGroupName='test_asg')
|
||||
list(response['LoadBalancers']).should.have.length_of(1)
|
||||
response['LoadBalancers'][0]['LoadBalancerName'].should.equal('my-lb')
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_elb
|
||||
def test_create_elb_and_autoscaling_group_no_relationship():
|
||||
INSTANCE_COUNT = 2
|
||||
ELB_NAME = 'my-elb'
|
||||
|
||||
elb_client = boto3.client('elb', region_name='us-east-1')
|
||||
elb_client.create_load_balancer(
|
||||
LoadBalancerName=ELB_NAME,
|
||||
Listeners=[
|
||||
{'Protocol': 'tcp', 'LoadBalancerPort': 80, 'InstancePort': 8080}],
|
||||
AvailabilityZones=['us-east-1a', 'us-east-1b']
|
||||
)
|
||||
|
||||
client = boto3.client('autoscaling', region_name='us-east-1')
|
||||
client.create_launch_configuration(
|
||||
LaunchConfigurationName='test_launch_configuration'
|
||||
)
|
||||
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName='test_asg',
|
||||
LaunchConfigurationName='test_launch_configuration',
|
||||
MinSize=0,
|
||||
MaxSize=INSTANCE_COUNT,
|
||||
DesiredCapacity=INSTANCE_COUNT,
|
||||
)
|
||||
|
||||
# autoscaling group and elb should have no relationship
|
||||
response = client.describe_load_balancers(
|
||||
AutoScalingGroupName='test_asg'
|
||||
)
|
||||
list(response['LoadBalancers']).should.have.length_of(0)
|
||||
response = elb_client.describe_load_balancers(
|
||||
LoadBalancerNames=[ELB_NAME]
|
||||
)
|
||||
list(response['LoadBalancerDescriptions'][0]['Instances']).should.have.length_of(0)
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_elb
|
||||
def test_attach_load_balancer():
|
||||
INSTANCE_COUNT = 2
|
||||
|
||||
elb_client = boto3.client('elb', region_name='us-east-1')
|
||||
elb_client.create_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Listeners=[
|
||||
{'Protocol': 'tcp', 'LoadBalancerPort': 80, 'InstancePort': 8080}],
|
||||
AvailabilityZones=['us-east-1a', 'us-east-1b']
|
||||
)
|
||||
|
||||
client = boto3.client('autoscaling', region_name='us-east-1')
|
||||
client.create_launch_configuration(
|
||||
LaunchConfigurationName='test_launch_configuration'
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName='test_asg',
|
||||
LaunchConfigurationName='test_launch_configuration',
|
||||
MinSize=0,
|
||||
MaxSize=INSTANCE_COUNT,
|
||||
DesiredCapacity=INSTANCE_COUNT,
|
||||
Tags=[{
|
||||
"ResourceId": 'test_asg',
|
||||
"Key": 'test_key',
|
||||
"Value": 'test_value',
|
||||
"PropagateAtLaunch": True
|
||||
}]
|
||||
)
|
||||
|
||||
response = client.attach_load_balancers(
|
||||
AutoScalingGroupName='test_asg',
|
||||
LoadBalancerNames=['my-lb'])
|
||||
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
||||
|
||||
response = elb_client.describe_load_balancers(
|
||||
LoadBalancerNames=['my-lb']
|
||||
)
|
||||
list(response['LoadBalancerDescriptions'][0]['Instances']).should.have.length_of(INSTANCE_COUNT)
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_elb
|
||||
def test_detach_load_balancer():
|
||||
INSTANCE_COUNT = 2
|
||||
|
||||
elb_client = boto3.client('elb', region_name='us-east-1')
|
||||
elb_client.create_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Listeners=[
|
||||
{'Protocol': 'tcp', 'LoadBalancerPort': 80, 'InstancePort': 8080}],
|
||||
AvailabilityZones=['us-east-1a', 'us-east-1b']
|
||||
)
|
||||
|
||||
client = boto3.client('autoscaling', region_name='us-east-1')
|
||||
client.create_launch_configuration(
|
||||
LaunchConfigurationName='test_launch_configuration'
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName='test_asg',
|
||||
LaunchConfigurationName='test_launch_configuration',
|
||||
LoadBalancerNames=['my-lb'],
|
||||
MinSize=0,
|
||||
MaxSize=INSTANCE_COUNT,
|
||||
DesiredCapacity=INSTANCE_COUNT,
|
||||
Tags=[{
|
||||
"ResourceId": 'test_asg',
|
||||
"Key": 'test_key',
|
||||
"Value": 'test_value',
|
||||
"PropagateAtLaunch": True
|
||||
}]
|
||||
)
|
||||
|
||||
response = client.detach_load_balancers(
|
||||
AutoScalingGroupName='test_asg',
|
||||
LoadBalancerNames=['my-lb'])
|
||||
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
||||
|
||||
response = elb_client.describe_load_balancers(
|
||||
LoadBalancerNames=['my-lb']
|
||||
)
|
||||
list(response['LoadBalancerDescriptions'][0]['Instances']).should.have.length_of(0)
|
||||
|
||||
response = client.describe_load_balancers(AutoScalingGroupName='test_asg')
|
||||
list(response['LoadBalancers']).should.have.length_of(0)
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
def test_create_autoscaling_group_boto3():
|
||||
client = boto3.client('autoscaling', region_name='us-east-1')
|
||||
|
|
@ -653,3 +815,147 @@ def test_autoscaling_describe_policies_boto3():
|
|||
response['ScalingPolicies'].should.have.length_of(1)
|
||||
response['ScalingPolicies'][0][
|
||||
'PolicyName'].should.equal('test_policy_down')
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_detach_one_instance_decrement():
|
||||
client = boto3.client('autoscaling', region_name='us-east-1')
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName='test_launch_configuration'
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName='test_asg',
|
||||
LaunchConfigurationName='test_launch_configuration',
|
||||
MinSize=0,
|
||||
MaxSize=2,
|
||||
DesiredCapacity=2,
|
||||
Tags=[
|
||||
{'ResourceId': 'test_asg',
|
||||
'ResourceType': 'auto-scaling-group',
|
||||
'Key': 'propogated-tag-key',
|
||||
'Value': 'propogate-tag-value',
|
||||
'PropagateAtLaunch': True
|
||||
}]
|
||||
)
|
||||
response = client.describe_auto_scaling_groups(
|
||||
AutoScalingGroupNames=['test_asg']
|
||||
)
|
||||
instance_to_detach = response['AutoScalingGroups'][0]['Instances'][0]['InstanceId']
|
||||
instance_to_keep = response['AutoScalingGroups'][0]['Instances'][1]['InstanceId']
|
||||
|
||||
ec2_client = boto3.client('ec2', region_name='us-east-1')
|
||||
|
||||
response = ec2_client.describe_instances(InstanceIds=[instance_to_detach])
|
||||
|
||||
response = client.detach_instances(
|
||||
AutoScalingGroupName='test_asg',
|
||||
InstanceIds=[instance_to_detach],
|
||||
ShouldDecrementDesiredCapacity=True
|
||||
)
|
||||
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(
|
||||
AutoScalingGroupNames=['test_asg']
|
||||
)
|
||||
response['AutoScalingGroups'][0]['Instances'].should.have.length_of(1)
|
||||
|
||||
# test to ensure tag has been removed
|
||||
response = ec2_client.describe_instances(InstanceIds=[instance_to_detach])
|
||||
tags = response['Reservations'][0]['Instances'][0]['Tags']
|
||||
tags.should.have.length_of(1)
|
||||
|
||||
# test to ensure tag is present on other instance
|
||||
response = ec2_client.describe_instances(InstanceIds=[instance_to_keep])
|
||||
tags = response['Reservations'][0]['Instances'][0]['Tags']
|
||||
tags.should.have.length_of(2)
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_detach_one_instance():
|
||||
client = boto3.client('autoscaling', region_name='us-east-1')
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName='test_launch_configuration'
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName='test_asg',
|
||||
LaunchConfigurationName='test_launch_configuration',
|
||||
MinSize=0,
|
||||
MaxSize=2,
|
||||
DesiredCapacity=2,
|
||||
Tags=[
|
||||
{'ResourceId': 'test_asg',
|
||||
'ResourceType': 'auto-scaling-group',
|
||||
'Key': 'propogated-tag-key',
|
||||
'Value': 'propogate-tag-value',
|
||||
'PropagateAtLaunch': True
|
||||
}]
|
||||
)
|
||||
response = client.describe_auto_scaling_groups(
|
||||
AutoScalingGroupNames=['test_asg']
|
||||
)
|
||||
instance_to_detach = response['AutoScalingGroups'][0]['Instances'][0]['InstanceId']
|
||||
instance_to_keep = response['AutoScalingGroups'][0]['Instances'][1]['InstanceId']
|
||||
|
||||
ec2_client = boto3.client('ec2', region_name='us-east-1')
|
||||
|
||||
response = ec2_client.describe_instances(InstanceIds=[instance_to_detach])
|
||||
|
||||
response = client.detach_instances(
|
||||
AutoScalingGroupName='test_asg',
|
||||
InstanceIds=[instance_to_detach],
|
||||
ShouldDecrementDesiredCapacity=False
|
||||
)
|
||||
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(
|
||||
AutoScalingGroupNames=['test_asg']
|
||||
)
|
||||
# test to ensure instance was replaced
|
||||
response['AutoScalingGroups'][0]['Instances'].should.have.length_of(2)
|
||||
|
||||
response = ec2_client.describe_instances(InstanceIds=[instance_to_detach])
|
||||
tags = response['Reservations'][0]['Instances'][0]['Tags']
|
||||
tags.should.have.length_of(1)
|
||||
|
||||
response = ec2_client.describe_instances(InstanceIds=[instance_to_keep])
|
||||
tags = response['Reservations'][0]['Instances'][0]['Tags']
|
||||
tags.should.have.length_of(2)
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_attach_one_instance():
|
||||
client = boto3.client('autoscaling', region_name='us-east-1')
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName='test_launch_configuration'
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName='test_asg',
|
||||
LaunchConfigurationName='test_launch_configuration',
|
||||
MinSize=0,
|
||||
MaxSize=4,
|
||||
DesiredCapacity=2,
|
||||
Tags=[
|
||||
{'ResourceId': 'test_asg',
|
||||
'ResourceType': 'auto-scaling-group',
|
||||
'Key': 'propogated-tag-key',
|
||||
'Value': 'propogate-tag-value',
|
||||
'PropagateAtLaunch': True
|
||||
}]
|
||||
)
|
||||
response = client.describe_auto_scaling_groups(
|
||||
AutoScalingGroupNames=['test_asg']
|
||||
)
|
||||
|
||||
ec2 = boto3.resource('ec2', 'us-east-1')
|
||||
instances_to_add = [x.id for x in ec2.create_instances(ImageId='', MinCount=1, MaxCount=1)]
|
||||
|
||||
response = client.attach_instances(
|
||||
AutoScalingGroupName='test_asg',
|
||||
InstanceIds=instances_to_add
|
||||
)
|
||||
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(
|
||||
AutoScalingGroupNames=['test_asg']
|
||||
)
|
||||
response['AutoScalingGroups'][0]['Instances'].should.have.length_of(3)
|
||||
|
|
|
|||
|
|
@ -581,24 +581,24 @@ def test_filter_expression():
|
|||
row2 = moto.dynamodb2.models.Item(None, None, None, None, {'Id': {'N': '8'}, 'Subs': {'N': '10'}, 'Desc': {'S': 'A description'}, 'KV': {'SS': ['test3', 'test4']}})
|
||||
|
||||
# AND test
|
||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id > 5 AND Subs < 7', {}, {})
|
||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id > :v0 AND Subs < :v1', {}, {':v0': {'N': 5}, ':v1': {'N': 7}})
|
||||
filter_expr.expr(row1).should.be(True)
|
||||
filter_expr.expr(row2).should.be(False)
|
||||
|
||||
# OR test
|
||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id = 5 OR Id=8', {}, {})
|
||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id = :v0 OR Id=:v1', {}, {':v0': {'N': 5}, ':v1': {'N': 8}})
|
||||
filter_expr.expr(row1).should.be(True)
|
||||
|
||||
# BETWEEN test
|
||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id BETWEEN 5 AND 10', {}, {})
|
||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id BETWEEN :v0 AND :v1', {}, {':v0': {'N': 5}, ':v1': {'N': 10}})
|
||||
filter_expr.expr(row1).should.be(True)
|
||||
|
||||
# PAREN test
|
||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id = 8 AND (Subs = 8 OR Subs = 5)', {}, {})
|
||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id = :v0 AND (Subs = :v0 OR Subs = :v1)', {}, {':v0': {'N': 8}, ':v1': {'N': 5}})
|
||||
filter_expr.expr(row1).should.be(True)
|
||||
|
||||
# IN test
|
||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id IN (7,8, 9)', {}, {})
|
||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id IN :v0', {}, {':v0': {'NS': [7, 8, 9]}})
|
||||
filter_expr.expr(row1).should.be(True)
|
||||
|
||||
# attribute function tests
|
||||
|
|
@ -655,6 +655,63 @@ def test_scan_filter():
|
|||
assert response['Count'] == 1
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_scan_filter2():
|
||||
client = boto3.client('dynamodb', region_name='us-east-1')
|
||||
|
||||
# Create the DynamoDB table.
|
||||
client.create_table(
|
||||
TableName='test1',
|
||||
AttributeDefinitions=[{'AttributeName': 'client', 'AttributeType': 'S'}, {'AttributeName': 'app', 'AttributeType': 'N'}],
|
||||
KeySchema=[{'AttributeName': 'client', 'KeyType': 'HASH'}, {'AttributeName': 'app', 'KeyType': 'RANGE'}],
|
||||
ProvisionedThroughput={'ReadCapacityUnits': 123, 'WriteCapacityUnits': 123}
|
||||
)
|
||||
client.put_item(
|
||||
TableName='test1',
|
||||
Item={
|
||||
'client': {'S': 'client1'},
|
||||
'app': {'N': '1'}
|
||||
}
|
||||
)
|
||||
|
||||
response = client.scan(
|
||||
TableName='test1',
|
||||
Select='ALL_ATTRIBUTES',
|
||||
FilterExpression='#tb >= :dt',
|
||||
ExpressionAttributeNames={"#tb": "app"},
|
||||
ExpressionAttributeValues={":dt": {"N": str(1)}}
|
||||
)
|
||||
assert response['Count'] == 1
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_scan_filter3():
|
||||
client = boto3.client('dynamodb', region_name='us-east-1')
|
||||
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
|
||||
|
||||
# Create the DynamoDB table.
|
||||
client.create_table(
|
||||
TableName='test1',
|
||||
AttributeDefinitions=[{'AttributeName': 'client', 'AttributeType': 'S'}, {'AttributeName': 'app', 'AttributeType': 'N'}],
|
||||
KeySchema=[{'AttributeName': 'client', 'KeyType': 'HASH'}, {'AttributeName': 'app', 'KeyType': 'RANGE'}],
|
||||
ProvisionedThroughput={'ReadCapacityUnits': 123, 'WriteCapacityUnits': 123}
|
||||
)
|
||||
client.put_item(
|
||||
TableName='test1',
|
||||
Item={
|
||||
'client': {'S': 'client1'},
|
||||
'app': {'N': '1'},
|
||||
'active': {'BOOL': True}
|
||||
}
|
||||
)
|
||||
|
||||
table = dynamodb.Table('test1')
|
||||
response = table.scan(
|
||||
FilterExpression=Attr('active').eq(True)
|
||||
)
|
||||
assert response['Count'] == 1
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_bad_scan_filter():
|
||||
client = boto3.client('dynamodb', region_name='us-east-1')
|
||||
|
|
@ -680,7 +737,6 @@ def test_bad_scan_filter():
|
|||
raise RuntimeError('Should of raised ResourceInUseException')
|
||||
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_duplicate_create():
|
||||
client = boto3.client('dynamodb', region_name='us-east-1')
|
||||
|
|
|
|||
|
|
@ -1113,3 +1113,20 @@ def test_get_instance_by_security_group():
|
|||
|
||||
assert len(security_group_instances) == 1
|
||||
assert security_group_instances[0].id == instance.id
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_modify_delete_on_termination():
|
||||
ec2_client = boto3.resource('ec2', region_name='us-west-1')
|
||||
result = ec2_client.create_instances(ImageId='ami-12345678', MinCount=1, MaxCount=1)
|
||||
instance = result[0]
|
||||
instance.load()
|
||||
instance.block_device_mappings[0]['Ebs']['DeleteOnTermination'].should.be(False)
|
||||
instance.modify_attribute(
|
||||
BlockDeviceMappings=[{
|
||||
'DeviceName': '/dev/sda1',
|
||||
'Ebs': {'DeleteOnTermination': True}
|
||||
}]
|
||||
)
|
||||
instance.load()
|
||||
instance.block_device_mappings[0]['Ebs']['DeleteOnTermination'].should.be(True)
|
||||
|
|
|
|||
|
|
@ -414,7 +414,8 @@ def test_get_authorization_token_assume_region():
|
|||
client = boto3.client('ecr', region_name='us-east-1')
|
||||
auth_token_response = client.get_authorization_token()
|
||||
|
||||
list(auth_token_response.keys()).should.equal(['authorizationData', 'ResponseMetadata'])
|
||||
auth_token_response.should.contain('authorizationData')
|
||||
auth_token_response.should.contain('ResponseMetadata')
|
||||
auth_token_response['authorizationData'].should.equal([
|
||||
{
|
||||
'authorizationToken': 'QVdTOnVzLWVhc3QtMS1hdXRoLXRva2Vu',
|
||||
|
|
@ -429,7 +430,8 @@ def test_get_authorization_token_explicit_regions():
|
|||
client = boto3.client('ecr', region_name='us-east-1')
|
||||
auth_token_response = client.get_authorization_token(registryIds=['us-east-1', 'us-west-1'])
|
||||
|
||||
list(auth_token_response.keys()).should.equal(['authorizationData', 'ResponseMetadata'])
|
||||
auth_token_response.should.contain('authorizationData')
|
||||
auth_token_response.should.contain('ResponseMetadata')
|
||||
auth_token_response['authorizationData'].should.equal([
|
||||
{
|
||||
'authorizationToken': 'QVdTOnVzLWVhc3QtMS1hdXRoLXRva2Vu',
|
||||
|
|
|
|||
|
|
@ -1364,6 +1364,29 @@ def test_boto3_head_object_with_versioning():
|
|||
old_head_object['ContentLength'].should.equal(len(old_content))
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_boto3_copy_object_with_versioning():
|
||||
client = boto3.client('s3', region_name='us-east-1')
|
||||
|
||||
client.create_bucket(Bucket='blah', CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'})
|
||||
client.put_bucket_versioning(Bucket='blah', VersioningConfiguration={'Status': 'Enabled'})
|
||||
|
||||
client.put_object(Bucket='blah', Key='test1', Body=b'test1')
|
||||
client.put_object(Bucket='blah', Key='test2', Body=b'test2')
|
||||
|
||||
obj1_version = client.get_object(Bucket='blah', Key='test1')['VersionId']
|
||||
obj2_version = client.get_object(Bucket='blah', Key='test2')['VersionId']
|
||||
|
||||
# Versions should be the same
|
||||
obj1_version.should.equal(obj2_version)
|
||||
|
||||
client.copy_object(CopySource={'Bucket': 'blah', 'Key': 'test1'}, Bucket='blah', Key='test2')
|
||||
obj2_version_new = client.get_object(Bucket='blah', Key='test2')['VersionId']
|
||||
|
||||
# Version should be different to previous version
|
||||
obj2_version_new.should_not.equal(obj2_version)
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_boto3_head_object_if_modified_since():
|
||||
s3 = boto3.client('s3', region_name='us-east-1')
|
||||
|
|
|
|||
72
tests/test_xray/test_xray_client.py
Normal file
72
tests/test_xray/test_xray_client.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
from __future__ import unicode_literals
|
||||
from moto import mock_xray_client, XRaySegment, mock_dynamodb2
|
||||
import sure # noqa
|
||||
import boto3
|
||||
|
||||
from moto.xray.mock_client import MockEmitter
|
||||
import aws_xray_sdk.core as xray_core
|
||||
import aws_xray_sdk.core.patcher as xray_core_patcher
|
||||
|
||||
import botocore.client
|
||||
import botocore.endpoint
|
||||
original_make_api_call = botocore.client.BaseClient._make_api_call
|
||||
original_encode_headers = botocore.endpoint.Endpoint._encode_headers
|
||||
|
||||
import requests
|
||||
original_session_request = requests.Session.request
|
||||
original_session_prep_request = requests.Session.prepare_request
|
||||
|
||||
|
||||
@mock_xray_client
|
||||
@mock_dynamodb2
|
||||
def test_xray_dynamo_request_id():
|
||||
# Could be ran in any order, so we need to tell sdk that its been unpatched
|
||||
xray_core_patcher._PATCHED_MODULES = set()
|
||||
xray_core.patch_all()
|
||||
|
||||
client = boto3.client('dynamodb', region_name='us-east-1')
|
||||
|
||||
with XRaySegment():
|
||||
resp = client.list_tables()
|
||||
resp['ResponseMetadata'].should.contain('RequestId')
|
||||
id1 = resp['ResponseMetadata']['RequestId']
|
||||
|
||||
with XRaySegment():
|
||||
client.list_tables()
|
||||
resp = client.list_tables()
|
||||
id2 = resp['ResponseMetadata']['RequestId']
|
||||
|
||||
id1.should_not.equal(id2)
|
||||
|
||||
setattr(botocore.client.BaseClient, '_make_api_call', original_make_api_call)
|
||||
setattr(botocore.endpoint.Endpoint, '_encode_headers', original_encode_headers)
|
||||
setattr(requests.Session, 'request', original_session_request)
|
||||
setattr(requests.Session, 'prepare_request', original_session_prep_request)
|
||||
|
||||
|
||||
@mock_xray_client
|
||||
def test_xray_udp_emitter_patched():
|
||||
# Could be ran in any order, so we need to tell sdk that its been unpatched
|
||||
xray_core_patcher._PATCHED_MODULES = set()
|
||||
xray_core.patch_all()
|
||||
|
||||
assert isinstance(xray_core.xray_recorder._emitter, MockEmitter)
|
||||
|
||||
setattr(botocore.client.BaseClient, '_make_api_call', original_make_api_call)
|
||||
setattr(botocore.endpoint.Endpoint, '_encode_headers', original_encode_headers)
|
||||
setattr(requests.Session, 'request', original_session_request)
|
||||
setattr(requests.Session, 'prepare_request', original_session_prep_request)
|
||||
|
||||
|
||||
@mock_xray_client
|
||||
def test_xray_context_patched():
|
||||
# Could be ran in any order, so we need to tell sdk that its been unpatched
|
||||
xray_core_patcher._PATCHED_MODULES = set()
|
||||
xray_core.patch_all()
|
||||
|
||||
xray_core.xray_recorder._context.context_missing.should.equal('LOG_ERROR')
|
||||
|
||||
setattr(botocore.client.BaseClient, '_make_api_call', original_make_api_call)
|
||||
setattr(botocore.endpoint.Endpoint, '_encode_headers', original_encode_headers)
|
||||
setattr(requests.Session, 'request', original_session_request)
|
||||
setattr(requests.Session, 'prepare_request', original_session_prep_request)
|
||||
Loading…
Add table
Add a link
Reference in a new issue