Skip to content

Commit

Permalink
Merge branch 'rename-assert-params-for-cmd2' into develop
Browse files Browse the repository at this point in the history
* rename-assert-params-for-cmd2:
  Rename assert_params_for_cmd2 to assert_params_for_cmd
  • Loading branch information
jamesls committed Feb 28, 2015
2 parents bd14d17 + 86260d3 commit b7707d6
Show file tree
Hide file tree
Showing 67 changed files with 312 additions and 346 deletions.
34 changes: 0 additions & 34 deletions awscli/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,40 +269,6 @@ def patch_make_request(self):
def assert_params_for_cmd(self, cmd, params=None, expected_rc=0,
stderr_contains=None, ignore_params=None):
stdout, stderr, rc = self.run_cmd(cmd, expected_rc)
if stderr_contains is not None:
self.assertIn(stderr_contains, stderr)
if params is not None:
last_params = self.last_params
if isinstance(last_params, dict):
last_params = copy.copy(self.last_params)
extra_params_to_ignore = ['Action', 'Version']
if ignore_params is None:
ignore_params = extra_params_to_ignore
else:
ignore_params.extend(extra_params_to_ignore)
for key in ignore_params:
try:
del last_params[key]
except KeyError:
pass
if params != last_params:
self.fail("Actual params did not match expected params.\n"
"Expected:\n\n"
"%s\n"
"Actual:\n\n%s\n" % (
pformat(params), pformat(last_params)))
return stdout, stderr, rc

def assert_params_for_cmd2(self, cmd, params=None, expected_rc=0,
stderr_contains=None, ignore_params=None):
# XXX: This has a terrible name because it's intended to be
# temporary. I want to switch everything off of
# assert_params_for_cmd and then I'll rename this to
# assert_params_for_cmd2. The difference between this command
# and the other one is that we verify the kwargs that are sent
# to botocore's Operation.call(), *not* the serialized parameters
# onto the HTTP request. We're one level up from that.
stdout, stderr, rc = self.run_cmd(cmd, expected_rc)
if stderr_contains is not None:
self.assertIn(stderr_contains, stderr)
if params is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def test_true(self):
cmdline += ' --should-decrement-desired-capacity'
params = {'InstanceId': 'i-12345678',
'ShouldDecrementDesiredCapacity': True}
self.assert_params_for_cmd2(cmdline, params)
self.assert_params_for_cmd(cmdline, params)

def test_false(self):
cmdline = self.PREFIX
cmdline += ' --instance-id i-12345678'
cmdline += ' --no-should-decrement-desired-capacity'
params = {'InstanceId': 'i-12345678',
'ShouldDecrementDesiredCapacity': False}
self.assert_params_for_cmd2(cmdline, params)
self.assert_params_for_cmd(cmdline, params)

def test_last_arg_wins(self):
cmdline = self.PREFIX
Expand All @@ -43,4 +43,4 @@ def test_last_arg_wins(self):
# was added last, it wins.
params = {'InstanceId': 'i-12345678',
'ShouldDecrementDesiredCapacity': False}
self.assert_params_for_cmd2(cmdline, params)
self.assert_params_for_cmd(cmdline, params)
8 changes: 4 additions & 4 deletions tests/unit/cloudformation/test_create_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_basic_create_stack(self):
cmdline = self.prefix
cmdline += ' --stack-name test-stack --template-url http://foo'
result = {'StackName': 'test-stack', 'TemplateURL': 'http://foo'}
self.assert_params_for_cmd2(cmdline, result)
self.assert_params_for_cmd(cmdline, result)

def test_create_stack_string_params(self):
cmdline = self.prefix
Expand All @@ -34,7 +34,7 @@ def test_create_stack_string_params(self):
{'ParameterKey': 'foo', 'ParameterValue': 'bar'},
{'ParameterKey': 'foo2', 'ParameterValue': 'bar2'},
]}
self.assert_params_for_cmd2(cmdline, result)
self.assert_params_for_cmd(cmdline, result)

def test_create_stack_for_csv_params_escaping(self):
# If a template is specified as a comma delimited list,
Expand All @@ -45,7 +45,7 @@ def test_create_stack_for_csv_params_escaping(self):
result = {'StackName': 'test-stack', 'TemplateURL': 'http://foo',
'Parameters': [{'ParameterKey': 'foo',
'ParameterValue': 'one,two'}]}
self.assert_params_for_cmd2(cmdline, result)
self.assert_params_for_cmd(cmdline, result)

def test_create_stack_for_csv_with_quoting(self):
cmdline = self.prefix
Expand All @@ -55,4 +55,4 @@ def test_create_stack_for_csv_with_quoting(self):
result = {'StackName': 'test-stack', 'TemplateURL': 'http://foo',
'Parameters': [{'ParameterKey': 'foo',
'ParameterValue': 'one,two'}]}
self.assert_params_for_cmd2(cmdline, result)
self.assert_params_for_cmd(cmdline, result)
6 changes: 3 additions & 3 deletions tests/unit/cloudsearch/test_cloudsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_flattened(self):
'DomainName': 'abc123',
'expression': {'ExpressionName': 'foo',
'ExpressionValue': '10'}}
self.assert_params_for_cmd2(cmdline, result)
self.assert_params_for_cmd(cmdline, result)


class TestCloudSearchDefineIndexField(BaseAWSCommandParamsTest):
Expand All @@ -47,7 +47,7 @@ def test_flattened(self):
'IndexFieldType': 'int',
'IntOptions': {'DefaultValue': 10,
'SearchEnabled': False}}}
self.assert_params_for_cmd2(cmdline, result)
self.assert_params_for_cmd(cmdline, result)

def test_latlon(self):
cmdline = self.prefix
Expand All @@ -63,5 +63,5 @@ def test_latlon(self):
'IndexFieldType': 'latlon',
'LatLonOptions': {
'DefaultValue': '10', 'SearchEnabled': False}}}
self.assert_params_for_cmd2(cmdline, result)
self.assert_params_for_cmd(cmdline, result)

6 changes: 3 additions & 3 deletions tests/unit/cloudwatch/test_put_metric_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_using_json(self):
'"Timestamp":"2013-08-22T10:58:12.283Z",'
'"Value":9130160128}]')
cmdline = self.prefix + args
self.assert_params_for_cmd2(cmdline, self.expected_output)
self.assert_params_for_cmd(cmdline, self.expected_output)

def test_using_promoted_params(self):
# This is equivalent to the json version in test_using_json
Expand All @@ -47,7 +47,7 @@ def test_using_promoted_params(self):
'--timestamp 2013-08-22T10:58:12.283Z '
'--value 9130160128')
cmdline = self.prefix + args
self.assert_params_for_cmd2(cmdline, self.expected_output)
self.assert_params_for_cmd(cmdline, self.expected_output)

def test_using_shorthand_syntax(self):
args = (
Expand All @@ -69,4 +69,4 @@ def test_using_shorthand_syntax(self):
],
'Namespace': 'MyService'
}
self.assert_params_for_cmd2(cmdline, expected)
self.assert_params_for_cmd(cmdline, expected)
4 changes: 2 additions & 2 deletions tests/unit/customizations/datapipeline/test_arg_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def test_put_pipeline_definition_with_json(self):
},
]}]
}
self.assert_params_for_cmd2(cmdline, result)
self.assert_params_for_cmd(cmdline, result)


class TestErrorMessages(BaseAWSCommandParamsTest):
prefix = 'datapipeline list-runs'

def test_unknown_status(self):
self.assert_params_for_cmd2(
self.assert_params_for_cmd(
self.prefix + ' --pipeline-id foo --status foo',
expected_rc=255,
stderr_contains=('Invalid status: foo, must be one of: waiting, '
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/customizations/emr/test_add_instance_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_instance_groups_default_name_market(self):
result = {'JobFlowId': 'J-ABCD',
'InstanceGroups': DEFAULT_INSTANCE_GROUPS}

self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_instance_groups_missing_instance_group_type_error(self):
cmd = self.prefix + ' Name=Task,InstanceType=m1.small,' +\
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_instance_groups_all_fields(self):
result = {'JobFlowId': 'J-ABCD',
'InstanceGroups': expected_instance_groups}

self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

@patch('awscli.customizations.emr.emrutils.call')
def test_constructed_result(self, call_patch):
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/customizations/emr/test_add_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_default_step_type_name_action_on_failure(self):
}
]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_custom_jar_step_missing_jar(self):
cmd = self.prefix + 'Name=CustomJarMissingJar'
Expand Down Expand Up @@ -147,7 +147,7 @@ def test_custom_jar_step_with_all_fields(self):
}
]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_streaming_step_with_default_fields(self):
cmd = self.prefix + 'Type=Streaming,' + self.STREAMING_ARGS
Expand All @@ -160,7 +160,7 @@ def test_streaming_step_with_default_fields(self):
}
]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_streaming_step_missing_args(self):
cmd = self.prefix + 'Type=Streaming'
Expand All @@ -184,7 +184,7 @@ def test_streaming_jar_with_all_fields(self):
}
]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_hive_step_with_default_fields(self):
cmd = self.prefix + 'Type=Hive,' + self.HIVE_BASIC_ARGS
Expand All @@ -196,7 +196,7 @@ def test_hive_step_with_default_fields(self):
'HadoopJarStep': self.HIVE_DEFAULT_HADOOP_JAR_STEP
}]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_hive_step_missing_args(self):
cmd = self.prefix + 'Type=Hive'
Expand All @@ -220,7 +220,7 @@ def test_hive_step_with_all_fields(self):
'HadoopJarStep': self.HIVE_DEFAULT_HADOOP_JAR_STEP
}]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_pig_step_with_default_fields(self):
cmd = self.prefix + 'Type=Pig,' + self.PIG_BASIC_ARGS
Expand All @@ -232,7 +232,7 @@ def test_pig_step_with_default_fields(self):
'HadoopJarStep': self.PIG_DEFAULT_HADOOP_JAR_STEP
}]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_pig_missing_args(self):
cmd = self.prefix + 'Type=Pig'
Expand All @@ -257,7 +257,7 @@ def test_pig_step_with_all_fields(self):
}
]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_impala_step_with_default_fields(self):
test_step_config = 'Type=Impala,' + \
Expand All @@ -271,7 +271,7 @@ def test_impala_step_with_default_fields(self):
'HadoopJarStep': self.IMPALA_BASIC_HADOOP_JAR_STEP
}]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_impala_missing_args(self):
cmd = self.prefix + 'Type=Impala'
Expand All @@ -296,7 +296,7 @@ def test_impala_step_with_all_fields(self):
}
]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_empty_step_args(self):
cmd = self.prefix + 'Type=Streaming,Args='
Expand Down Expand Up @@ -351,7 +351,7 @@ def test_all_step_types(self):
}
]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

def test_all_step_types_from_json(self):
data_path = os.path.join(
Expand Down Expand Up @@ -399,7 +399,7 @@ def test_all_step_types_from_json(self):
}
]
}
self.assert_params_for_cmd2(cmd, result)
self.assert_params_for_cmd(cmd, result)

if __name__ == "__main__":
unittest.main()
6 changes: 3 additions & 3 deletions tests/unit/customizations/emr/test_add_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_add_tags_key_value(self):
result = {'ResourceId': 'j-ABC123456',
'Tags': [{'Key': 'k1', 'Value': 'v1'},
{'Key': 'k2', 'Value': 'v2'}]}
self.assert_params_for_cmd2(cmdline, result)
self.assert_params_for_cmd(cmdline, result)

def test_add_tags_key_with_empty_value(self):
args = ' --resource-id j-ABC123456 --tags k1=v1 k2 k3=v3'
Expand All @@ -33,7 +33,7 @@ def test_add_tags_key_with_empty_value(self):
'Tags': [{'Key': 'k1', 'Value': 'v1'},
{'Key': 'k2', 'Value': ''},
{'Key': 'k3', 'Value': 'v3'}]}
self.assert_params_for_cmd2(cmdline, result)
self.assert_params_for_cmd(cmdline, result)

def test_add_tags_key_value_space(self):
cmdline = ['emr', 'add-tags', '--resource-id', 'j-ABC123456', '--tags',
Expand All @@ -42,7 +42,7 @@ def test_add_tags_key_value_space(self):
'Tags': [{'Key': 'k1', 'Value': 'v1'},
{'Key': 'k2', 'Value': ''},
{'Key': 'k3', 'Value': 'v3 v4'}]}
self.assert_params_for_cmd2(cmdline, result)
self.assert_params_for_cmd(cmdline, result)

if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit b7707d6

Please sign in to comment.