def test_output_every_host_has_group(self):
     inventory = Inventory()
     inventory.add_host('superhost',
                        hostvars={'ansible_connection': 'local'})
     output = inventory.write_output_json()
     assert 'superhost' in output['ungrouped']['hosts']
     inventory.add_group('awesome')
     inventory.groups['awesome'].add_host(inventory.hosts['superhost'])
     output = inventory.write_output_json()
     assert 'superhost' in output['awesome'].get('hosts', [])
     assert 'superhost' not in output['ungrouped'].get('hosts', [])
 def test_output_has_hostvars(self):
     inventory = Inventory()
     inventory.add_host('superhost',
                        hostvars={'ansible_connection': 'local'})
     output = inventory.write_output_json()
     assert output['_meta']['hostvars']['superhost'][
         'ansible_connection'] == 'local'
 def test_output_has_no_host_twice(self):
     inventory = Inventory()
     inventory.add_host('superhost',
                        hostvars={'ansible_connection': 'local'})
     inventory.add_host('superhost',
                        hostvars={'ansible_connection': 'local'})
     inventory.add_group('awesome')
     inventory.add_group('awesome')
     inventory.groups['awesome'].add_host(inventory.hosts['superhost'])
     inventory.groups['awesome'].add_host(inventory.hosts['superhost'])
     output = inventory.write_output_json()
     assert len(output['_meta']['hostvars']) == 1
 def test_output_vs_expectations(self):
     """ Computes the number of groups, and compares
     to expected value
     """
     inventory = Inventory()
     inventory.add_host('superhost',
                        hostvars={'ansible_connection': 'local'})
     inventory.add_host('superhost2',
                        hostvars={'ansible_connection': 'local'})
     inventory.add_group('awesome')
     inventory.add_group('awesome2')
     inventory.groups['awesome'].add_host(inventory.hosts['superhost'])
     inventory.groups['awesome'].add_host(inventory.hosts['superhost2'])
     output = inventory.write_output_json()
     assert len(output['_meta']['hostvars']) == 2
     output.pop('_meta')
     assert len(output) == 4  #awesome, awesome2, all, ungrouped
 def test_ungrouped_is_child_of_all(self):
     inventory = Inventory()
     inventory.add_host('superhost',
                        hostvars={'ansible_connection': 'local'})
     output = inventory.write_output_json()
     assert 'ungrouped' in output['all']['children']
 def test_output_always_has_ungrouped(self):
     inventory = Inventory()
     inventory.add_host('superhost',
                        hostvars={'ansible_connection': 'local'})
     output = inventory.write_output_json()
     assert 'ungrouped' in output