def test_clean_update_on_launch_update_on_project_update(self): inv_src = InventorySource(update_on_project_update=True, update_on_launch=True, source='scm') with pytest.raises(ValidationError): inv_src.clean_update_on_launch()
def _mk_inventory_update(created=None): kwargs = {} if created: kwargs['created'] = created source = InventorySource(source='ec2') source.save() iu = InventoryUpdate(inventory_source=source, source='e2', **kwargs) return iu
def test_automatic_project_update_on_create(self, inventory, project): inv_src = InventorySource(source_project=project, source_path='inventory_file', inventory=inventory, update_on_project_update=True, source='scm') with mock.patch.object(inv_src, 'update') as mck_update: inv_src.save() mck_update.assert_called_once_with()
def test_inventory_update_event_websocket_notifications(emit, inventory): source = InventorySource() source.save() iu = InventoryUpdate(id=123, inventory_source=source) iu.save() InventoryUpdateEvent.create_from_data(inventory_update_id=iu.pk) assert len(emit.call_args_list) == 1 topic, payload = emit.call_args_list[0][0] assert topic == 'inventory_update_events-123' assert payload['inventory_update'] == 123
def test_group_by_azure(self): injector = InventorySource.injectors['azure_rm']('2.9') inv_src = InventorySource(name='azure source', source='azure_rm', source_vars={'group_by_os_family': True}) group_by_on = injector.inventory_as_dict(inv_src, '/tmp/foo') # suspicious, yes, that is just what the script did expected_groups = 6 assert len(group_by_on['keyed_groups']) == expected_groups inv_src.source_vars = json.dumps({'group_by_os_family': False}) group_by_off = injector.inventory_as_dict(inv_src, '/tmp/foo') # much better, everyone should turn off the flag and live in the future assert len(group_by_off['keyed_groups']) == expected_groups - 1
def test_satellite_plugin_backwards_support_for_ssl_verify( source_vars, validate_certs): injector = InventorySource.injectors['satellite6']('2.9') inv_src = InventorySource(name='satellite source', source='satellite6', source_vars=source_vars) ret = injector.inventory_as_dict(inv_src, '/tmp/foo') assert 'validate_certs' in ret assert ret['validate_certs'] in (validate_certs, str(validate_certs))
def test_tower_plugin_named_url(self): injector = InventorySource.injectors['tower']('2.9') inv_src = InventorySource( name='my tower source', source='tower', # named URL pattern "inventory++organization" instance_filters='Designer hair 읰++Cosmetic_products䵆') result = injector.inventory_as_dict(inv_src, '/tmp/foo') assert result[ 'inventory_id'] == 'Designer%20hair%20%EC%9D%B0++Cosmetic_products%E4%B5%86'
def test_tower_version_compare(): cmd = inventory_import.Command() cmd.inventory_source = InventorySource(source='tower') cmd.all_group = MemGroup('all') # mimic example from https://github.com/ansible/ansible/pull/52747 # until that is merged, this is the best testing we can do cmd.all_group.variables = { 'tower_metadata': { "ansible_version": "2.7.5", "license_type": "open", "version": "2.0.1-1068-g09684e2c41" } } with pytest.raises(PermissionDenied): cmd.remote_tower_license_compare('very_supported') cmd.remote_tower_license_compare('open')
def test_clean_update_on_project_update_multiple(self, inventory): inv_src1 = InventorySource(inventory=inventory, update_on_project_update=True, source='scm') inv_src1.clean_update_on_project_update() inv_src1.save() inv_src1.source_vars = '---\nhello: world' inv_src1.clean_update_on_project_update() inv_src2 = InventorySource(inventory=inventory, update_on_project_update=True, source='scm') with pytest.raises(ValidationError): inv_src2.clean_update_on_project_update()
def _mk_inventory_update(): source = InventorySource() source.save() iu = InventoryUpdate(inventory_source=source) return iu
admin ) assert response.status_code == 200 cred = Credential.objects.all()[:1].get() assert cred.inputs['username'] == 'joe' assert 'password' not in cred.inputs @pytest.mark.django_db @pytest.mark.parametrize('relation, related_obj', [ ['ad_hoc_commands', AdHocCommand()], ['insights_inventories', Inventory()], ['unifiedjobs', Job()], ['unifiedjobtemplates', JobTemplate()], ['unifiedjobtemplates', InventorySource(source='ec2')], ['projects', Project()], ['workflowjobnodes', WorkflowJobNode()], ]) def test_credential_type_mutability(patch, organization, admin, credentialtype_ssh, credentialtype_aws, relation, related_obj): cred = Credential( credential_type=credentialtype_ssh, name='Best credential ever', organization=organization, inputs={ 'username': u'jim', 'password': u'pass' } ) cred.save()
def test_inventory_friend_cancel(self, inventory, admin_user, inv_updater): inventory_update = InventoryUpdate(inventory_source=InventorySource( name=inventory.name, inventory=inventory, source='gce'), created_by=admin_user) access = InventoryUpdateAccess(inv_updater) assert not access.can_cancel(inventory_update)
assert response.status_code == 200 cred = Credential.objects.all()[:1].get() assert cred.inputs['username'] == 'joe' assert 'password' not in cred.inputs @pytest.mark.django_db @pytest.mark.parametrize( 'relation, related_obj', [ ['ad_hoc_commands', AdHocCommand()], ['unifiedjobs', Job()], ['unifiedjobtemplates', JobTemplate()], ['unifiedjobtemplates', InventorySource(source='ec2')], ['projects', Project()], ['workflowjobnodes', WorkflowJobNode()], ], ) def test_credential_type_mutability(patch, organization, admin, credentialtype_ssh, credentialtype_aws, relation, related_obj): cred = Credential(credential_type=credentialtype_ssh, name='Best credential ever', organization=organization, inputs={ 'username': u'jim', 'password': u'pass' }) cred.save()
admin ) assert response.status_code == 200 cred = Credential.objects.all()[:1].get() assert cred.inputs['username'] == 'joe' assert 'password' not in cred.inputs @pytest.mark.django_db @pytest.mark.parametrize('relation, related_obj', [ ['ad_hoc_commands', AdHocCommand()], ['insights_inventories', Inventory()], ['unifiedjobs', Job()], ['unifiedjobtemplates', JobTemplate()], ['unifiedjobtemplates', InventorySource()], ['projects', Project()], ['workflowjobnodes', WorkflowJobNode()], ]) def test_credential_type_mutability(patch, organization, admin, credentialtype_ssh, credentialtype_aws, relation, related_obj): cred = Credential( credential_type=credentialtype_ssh, name='Best credential ever', organization=organization, inputs={ 'username': u'jim', 'password': u'pass' } ) cred.save()
def test_clean_overwrite_vars_valid(self, source): inv_src = InventorySource(overwrite_vars=True, source=source) inv_src.clean_overwrite_vars()
def test_clean_source_path_valid(self): inv_src = InventorySource(source_path='/not_real/', source='scm') inv_src.clean_source_path()
def test_clean_source_path_invalid(self, source): inv_src = InventorySource(source_path='/not_real/', source=source) with pytest.raises(ValidationError): inv_src.clean_source_path()
def test_inventory_source_unique_together_with_inv(inventory_factory): inv1 = inventory_factory('foo') inv2 = inventory_factory('bar') is1 = InventorySource(name='foo', source='file', inventory=inv1) is1.save() is2 = InventorySource(name='foo', source='file', inventory=inv1) with pytest.raises(ValidationError): is2.validate_unique() is2 = InventorySource(name='foo', source='file', inventory=inv2) is2.validate_unique()
def _mk_inventory_update(): source = InventorySource(source='ec2') source.save() iu = InventoryUpdate(inventory_source=source, source='e2') return iu