Skip to content

Commit

Permalink
test invalid yaml syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
aabouzaid committed Sep 17, 2017
1 parent d5c6f63 commit 127176a
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions netbox/tests/test_netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@
# env: env
'''

# Netbox config.
netbox_config_data = yaml.safe_load(netbox_config)

# Mock open Netbox config file.
netbox_config_file = tempfile.NamedTemporaryFile(delete=False, mode='a')
netbox_config_file.write(netbox_config)
netbox_config_file.close()
netbox_config_data = yaml.safe_load(netbox_config)

# Invalid yaml file.
netbox_config_file_invalid = tempfile.NamedTemporaryFile(delete=False, mode='a')
netbox_config_file_invalid.write("invalid yaml syntax: ][")
netbox_config_file_invalid.close()

# Fake Netbox api output.
netbox_api_output = json.loads('''
Expand Down Expand Up @@ -324,9 +331,20 @@ def test_open_yaml_file_not_exists(self, yaml_file):
netbox.open_yaml_file(yaml_file)
assert file_not_exists

# @classmethod
# def teardown_class(cls):
# os.unlink(netbox_config_file.name)
@pytest.mark.parametrize("yaml_file", [
netbox_config_file_invalid.name
])
def test_open_yaml_file_invalid(self, yaml_file):
"""
Test open invalid yaml file.
"""
with pytest.raises(SystemExit) as yaml_error:
config_output = netbox.open_yaml_file(yaml_file)
assert yaml_error

@staticmethod
def teardown_function():
os.unlink(netbox_config_file_invalid.name)


# Test NetboxAsInventory class.
Expand Down

0 comments on commit 127176a

Please sign in to comment.