fix terraform import cmd is a reseved word of python

This commit is contained in:
beelit94 2017-05-09 15:39:09 +08:00
parent ddc9a1ed34
commit 38222a42f5
2 changed files with 33 additions and 7 deletions

View file

@ -16,6 +16,18 @@ python-terraform is a python module provide a wrapper of `terraform` command lin
t = Terraform()
return_code, stdout, stderr = t.<cmd_name>(*arguments, **options)
**Note**: method name same as reserved keyword like `import` could be called directly by using the following
from python_terraform import Terraform
t = Terraform()
return_code, stdout, stderr = t.<cmd_name>_method(*arguments, **options)
or just call cmd method directly
from python_terraform import Terraform
t = Terraform()
return_code, stdout, stderr = t.cmd(<cmd_name>, *arguments, **options)
#### For any argument
simply pass the string to arguments of the method, for example,

View file

@ -6,6 +6,8 @@ import re
import shutil
logging.basicConfig(level=logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
logging.getLogger().addHandler(ch)
current_path = os.path.dirname(os.path.realpath(__file__))
STRING_CASES = [
@ -23,11 +25,18 @@ STRING_CASES = [
]
CMD_CASES = [
['method', 'expected_output'],
['method', 'expected_output', 'expected_ret_code'],
[
[
lambda x: x.cmd('plan', 'var_to_output', no_color=IsFlagged, var={'test_var': 'test'}) ,
"doesn't need to do anything"
"doesn't need to do anything",
0
],
# try import aws instance
[
lambda x: x.cmd('import', 'aws_instance.foo', 'i-abcd1234', no_color=IsFlagged),
'Import complete!',
1
]
]
]
@ -73,11 +82,11 @@ class TestTerraform(object):
assert s in result
@pytest.mark.parametrize(*CMD_CASES)
def test_cmd(self, method, expected_output):
def test_cmd(self, method, expected_output, expected_ret_code):
tf = Terraform(working_dir=current_path)
ret, out, err = method(tf)
assert expected_output in out
assert ret == 0
assert expected_ret_code == ret
@pytest.mark.parametrize(
("folder", "variables", "var_files", "expected_output", "options"),
@ -161,3 +170,8 @@ class TestTerraform(object):
tf = Terraform(working_dir=current_path, variables={'test_var': 'test'})
ret, out, err = tf.fmt(diff=True)
assert ret == 0
def test_import(self):
tf = Terraform(working_dir=current_path)
tf.cmd('import', 'aws_instance.foo', 'i-abc123')
assert False