def test_missing_required_keys(self): """Verify that moleculerize will reject JSON Ansible inventory files missing required keys.""" # Setup json_inventory_missing_meta = json.loads('{ "invalid": {} }') json_inventory_missing_hostvars = json.loads( '{ "_meta": { "invalid": {} } }') # Test with pytest.raises(RuntimeError): moleculerize.generate_hosts_inventory(json_inventory_missing_meta) with pytest.raises(RuntimeError): moleculerize.generate_hosts_inventory( json_inventory_missing_hostvars)
def test_load_parse_json_inventory(self, groups, json_inventory): """Verify that moleculerize can successfully load a JSON Ansible inventory file.""" # Setup hosts_inventory = moleculerize.generate_hosts_inventory(json_inventory) # Test for host in groups.keys(): assert hosts_inventory[host] == set(groups[host])
def test01_load_parse_json_inventory(self): """Verify that moleculerize can successfully load a JSON Ansible inventory file.""" # Setup hosts_inventory = moleculerize.generate_hosts_inventory( self.json_inventory) # Test for host in self.groups.keys(): self.assertItemsEqual(hosts_inventory[host], self.groups[host])
def test_invalid_template_path(self, json_inventory): """Verify that moleculerize will fail gracefully if the template file cannot be found.""" # Setup hosts_inventory = moleculerize.generate_hosts_inventory(json_inventory) scenario = 'default' # Test with pytest.raises(RuntimeError): moleculerize.render_molecule_template(scenario, hosts_inventory, 'MISSING_TEMPLATE')
def test04_invalid_template_path(self): """Verify that moleculerize will fail gracefully if the template file cannot be found.""" # Setup hosts_inventory = moleculerize.generate_hosts_inventory( self.json_inventory) # Test with self.assertRaises(RuntimeError): moleculerize.render_molecule_template(hosts_inventory, 'MISSING_TEMPLATE')
def test02_render_template(self): """Verify that moleculerize can create a YAML template with correct syntax.""" # Setup hosts_inventory = moleculerize.generate_hosts_inventory( self.json_inventory) render_yaml = yaml.load( moleculerize.render_molecule_template(hosts_inventory, moleculerize.TEMPLATE)) # Expectations platforms_exp = [{ 'name': host, 'groups': self.groups[host] } for host in self.groups.keys() if host != 'host6'] platforms_exp.append({'name': 'host6'}) # Test self.assertItemsEqual(platforms_exp, render_yaml['platforms'])
def test_render_template(self, groups, json_inventory): """Verify that moleculerize can create a YAML template with correct syntax.""" # Setup hosts_inventory = moleculerize.generate_hosts_inventory(json_inventory) scenario = 'groovy' render_yaml = yaml.load( moleculerize.render_molecule_template(scenario, hosts_inventory, moleculerize.TEMPLATE)) # Expectations platforms_exp = [{ 'name': host, 'groups': groups[host] } for host in groups.keys() if host != 'host6'] platforms_exp.append({'name': 'host6'}) observed = render_yaml['platforms'] # Test for platform in platforms_exp: assert platform in observed assert scenario == render_yaml['scenario']['name']