def test_remove(self): object = ObjectFactory.getInstance().getObject('PosixUser', '78475884-c7f2-1035-8262-f535be14d43a') with pytest.raises(ObjectException): object.remove() object = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') with mock.patch("gosa.backend.objects.object.ObjectBackendRegistry.getBackend") as mb, \ mock.patch("zope.event.notify") as me: object.remove() assert mb.return_value.remove.called assert me.called
def test_getAttrType(self): obj = ObjectFactory.getInstance().getObject( 'User', '78475884-c7f2-1035-8262-f535be14d43a') assert obj.getAttrType('uid') == "String" with pytest.raises(AttributeError): obj.getAttrType('unknown')
def test_remove_refs(self): object = ObjectFactory.getInstance().getObject( 'User', '78475884-c7f2-1035-8262-f535be14d43a') with mock.patch.object(object, "get_references", return_value=[('memberUid', 'uid', 'freich', ['78475884-c7f2-1035-8262-f535be14d43a'], False, "replace", {"identify": None, "replace": None, "delete": None})]) as m, \ mock.patch.object(object, "_delattr_"), \ mock.patch("gosa.backend.objects.object.ObjectProxy") as c_obj: c_obj.return_value.memberUid = 'Test' object.remove_refs() assert c_obj.return_value.memberUid is None assert c_obj.return_value.commit.called c_obj.return_value.memberUid = ['Test', 'freich'] object.remove_refs() assert c_obj.return_value.memberUid == ['Test'] m.return_value = [('memberUid', 'uid', ['freich'], ['78475884-c7f2-1035-8262-f535be14d43a' ], True, "replace", { "identify": None, "replace": None, "delete": None })] c_obj.return_value.memberUid = ['Test', 'freich'] object.remove_refs() assert c_obj.return_value.memberUid == ['Test']
def test_listMethods(self): obj = ObjectFactory.getInstance().getObject( 'User', '78475884-c7f2-1035-8262-f535be14d43a') res = obj.listMethods() # just test if something is there assert 'lock' in res assert 'unlock' in res
def test_remove_inline_refs(self): object = ObjectFactory.getInstance().getObject( 'User', '78475884-c7f2-1035-8262-f535be14d43a') with mock.patch.object(object, "get_references", return_value=[('gotoMenu', 'cn', 'chrome', ['78475884-c7f2-1035-8262-f535be14d43a'], False, "inline", { "identify": "\"cn\":\"###VALUE###\"", "replace": "\"cn\":\"###VALUE###\"", "delete": ",{[^{]*\"cn\":\"###VALUE###\"[^}]*}|{[^{]*\"cn\":\"###VALUE###\"[^}]*},?" }) ]) as m, \ mock.patch.object(object, "_delattr_"), \ mock.patch("gosa.backend.objects.object.ObjectProxy") as c_obj: # delete first child c_obj.return_value.gotoMenu = '[{"name":"Browsers","children":[{"name":"Chrome browser","cn":"chrome","gosaApplicationParameter":["chrome.test:12345"]},{"name":"Firefox","cn":"firefox","gosaApplicationParameter":[]}]}]' object.remove_refs() assert c_obj.return_value.gotoMenu == '[{"name":"Browsers","children":[{"name":"Firefox","cn":"firefox","gosaApplicationParameter":[]}]}]' # delete middle child c_obj.return_value.gotoMenu = '[{"name":"Browsers","children":[{"name":"Test browser","cn":"test","gosaApplicationParameter":[]},{"name":"Chrome browser","cn":"chrome","gosaApplicationParameter":["chrome.test:12345"]},{"name":"Firefox","cn":"firefox","gosaApplicationParameter":[]}]}]' object.remove_refs() assert c_obj.return_value.gotoMenu == '[{"name":"Browsers","children":[{"name":"Test browser","cn":"test","gosaApplicationParameter":[]},{"name":"Firefox","cn":"firefox","gosaApplicationParameter":[]}]}]' # delete last child c_obj.return_value.gotoMenu = '[{"name":"Browsers","children":[{"name":"Firefox","cn":"firefox","gosaApplicationParameter":[]},{"name":"Chrome browser","cn":"chrome","gosaApplicationParameter":["chrome.test:12345"]}]}]' object.remove_refs() assert c_obj.return_value.gotoMenu == '[{"name":"Browsers","children":[{"name":"Firefox","cn":"firefox","gosaApplicationParameter":[]}]}]'
def test_update_refs(self): object = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') with mock.patch.object(object, "get_references", return_value=[('memberUid', 'uid', 'freich', ['78475884-c7f2-1035-8262-f535be14d43a'], False)]) as m, \ mock.patch.object(object, "_delattr_"), \ mock.patch("gosa.backend.objects.object.ObjectProxy") as c_obj: c_obj.return_value.memberUid = 'Test' c_obj.return_value.sn = 'Test' object.update_refs({'sn': {'value': ['Tester'], 'orig': ['Reich']}}) assert c_obj.return_value.sn == 'Test' object.update_refs({'uid': {'value': ['frank'], 'orig': ['freich']}}) assert c_obj.return_value.memberUid == 'frank' c_obj.return_value.memberUid = ['Test'] object.update_refs({'uid': {'value': ['frank'], 'orig': ['freich']}}) assert 'Test' in c_obj.return_value.memberUid assert 'frank' in c_obj.return_value.memberUid c_obj.return_value.memberUid = ['Test'] object.update_refs({'uid': {'value': ['frank'], 'orig': 'freich'}}) assert 'Test' in c_obj.return_value.memberUid assert 'frank' in c_obj.return_value.memberUid # multivalue m.return_value = [('memberUid', 'uid', 'freich', ['78475884-c7f2-1035-8262-f535be14d43a'], True)] c_obj.return_value.memberUid = ['Test'] object.update_refs({'uid': {'value': ['frank', 'more'], 'orig': ['freich']}}) assert 'Test' in c_obj.return_value.memberUid assert 'frank' in c_obj.return_value.memberUid assert 'more' in c_obj.return_value.memberUid
def process(self, all_props, key, value, objectType, attribute, comp=None): errors = [] index = PluginRegistry.getInstance("ObjectIndex") factory = ObjectFactory.getInstance() query = {attribute: ""} if factory.isBaseType(objectType): query["_type"] = objectType else: query["extension"] = objectType for val in value: if val in all_props[key]['value']: # do not check existing values continue in_creation = False for obj in index.currently_in_creation: if hasattr(obj, attribute) and val == getattr(obj, attribute) and objectType == obj.get_type(): # this object has been created but is not in the DB yet in_creation = True break if in_creation is True: continue query[attribute] = val if not len(index.search(query, {'dn': 1})): errors.append(dict(index=value.index(val), detail=N_("no '%(type)s' object with '%(attribute)s' property matching '%(value)s' found"), type=objectType, attribute=attribute, value=val)) return len(errors) == 0, errors
def load(self, uuid, info, back_attrs=None, needed=None): """ Load attributes for the given object-uuid. This method resolves relations between objects, e.g. user-group-memberships. For example, to have an attribute called groupMembership for 'User' objects we've to collect all 'Group->cn' attributes where 'Group->memberUid' includes the 'User->uid' attribute. Example: User->uid = 'herbert' Group->cn = "admins" Group->memberUid = ['klaus', 'herbert', '...'] Group->cn = "support" Group->memberUid = ['manfred', 'herbert'] User->groupMembership = ['admins', 'support', '..,', 'and', 'maybe', 'others'] Due to the fact that not all groups may already be loaded during indexing, we have to postpone this process after the index-process has finished and all objects were inserted to the index. Take a look at the 'ObjectIndex' and its static variable 'importing' for details. """ self.log.debug("load(%s, %s, %s)" % ( uuid, info, back_attrs)) result = {} if ObjectIndex.importing: ObjectIndex.to_be_updated.append(uuid) else: # Extract backend attrs mapping = self.extractBackAttrs(back_attrs) # Load related objects from the index and add the required attribute-values # as values for 'targetAttr' index = PluginRegistry.getInstance("ObjectIndex") for targetAttr in mapping: result[targetAttr] = [] foreignObject, foreignAttr, foreignMatchAttr, matchAttr = mapping[targetAttr] results = index.search({'uuid': uuid, matchAttr: "%"}, {matchAttr: 1}) if len(results): matchValue = results[0][matchAttr] query = {foreignMatchAttr: matchValue} if foreignObject != "*": if ObjectFactory.getInstance().isBaseType(foreignObject): query["_type"] = foreignObject else: query["extension"] = foreignObject xq = index.search(query, {foreignAttr: 1}) if foreignAttr == "dn": result[targetAttr] = [x[foreignAttr] for x in xq] else: result[targetAttr] = list(itertools.chain.from_iterable([x[foreignAttr] for x in xq])) self.log.debug("load result %s" % result) return result
def test_getNamedTemplate(self): assert Object.getNamedTemplate({}, []) == [] obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') res = Object.getNamedTemplate(obj.env, obj._templates) assert res[0][0:3] == "{\n " with mock.patch('os.path.exists', return_value=False): assert Object.getNamedTemplate(obj.env, obj._templates) is None
def test_simulate_move(self): object = ObjectFactory.getInstance().getObject('PosixUser', '78475884-c7f2-1035-8262-f535be14d43a') with pytest.raises(ObjectException): object.simulate_move('orig_dn') object = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') with mock.patch("zope.event.notify") as me, \ mock.patch.object(object, "get_dn_references", return_value=[('member', ['78475884-c7f2-1035-8262-f535be14d43a'])]), \ mock.patch.object(object, "_delattr_"), \ mock.patch("gosa.backend.objects.object.ObjectProxy") as c_obj: c_obj.return_value.member = 'old dn' object.simulate_move('orig_dn') assert me.called assert c_obj.return_value.member == object.dn
def test_attributes(self): obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') assert obj.gender == 'M' # just test the change obj.gender = 'F' assert obj.gender == 'F' # cannot delete mandatory attribute with pytest.raises(AttributeError): del obj.uid # cannot delete readonly attribute with pytest.raises(AttributeError): del obj.passwordMethod # cannot delete blockedBy attribute with pytest.raises(AttributeError): del obj.displayName # cannot delete unknown attribute with pytest.raises(AttributeError): del obj.unknown # cannot get unknown attribute with pytest.raises(AttributeError): obj.unknown del obj.gender assert obj.gender is None # try to set some wrong types with pytest.raises(TypeError): obj.gender = True with pytest.raises(TypeError): obj.gender = "T" obj.gender = 'M' assert obj.gender == 'M' # delete by setting None obj.gender = None assert obj.gender is None # cannot change readonly attribute with pytest.raises(AttributeError): obj.passwordMethod = 'MD5' # cannot change blockedBy attribute with pytest.raises(AttributeError): obj.displayName = "Name" # cannot change unknown attribute with pytest.raises(AttributeError): obj.unknown = "Test" # multivalue (no list) with pytest.raises(TypeError): obj.telephoneNumber = "0123456789" # validation error with pytest.raises(ValueError): obj.telephoneNumber = ["wrong"]
def test_get_dn_references(self): object = ObjectFactory.getInstance().getObject( 'User', '78475884-c7f2-1035-8262-f535be14d43a') mocked_index = mock.MagicMock() mocked_index.search.return_value = [{'dn': 'dn1'}, {'dn': 'dn2'}] with mock.patch.dict(PluginRegistry.modules, {'ObjectIndex': mocked_index}): res = object.get_dn_references() assert len(res) == 2 for entry in res: assert entry[0] in ["member", "gotoLastSystem"]
def test_move(self): object = ObjectFactory.getInstance().getObject('PosixUser', '78475884-c7f2-1035-8262-f535be14d43a') with pytest.raises(ObjectException): object.move('orig_dn') object = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') with mock.patch("zope.event.notify") as me, \ mock.patch.object(object, "get_dn_references", return_value=[('member', ['78475884-c7f2-1035-8262-f535be14d43a'])]), \ mock.patch.object(object, "_delattr_"), \ mock.patch("gosa.backend.objects.object.ObjectBackendRegistry.getBackend") as mb, \ mock.patch("gosa.backend.objects.object.ObjectProxy") as c_obj: mb.return_value.uuid2dn.return_value = 'new dn' c_obj.return_value.member = 'old dn' object.move('new base') assert me.called mb.return_value.move.assert_called_with(object.uuid, 'new base') assert c_obj.return_value.member == 'new dn'
def test_retract(self): object = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') with pytest.raises(ObjectException): object.retract() object = ObjectFactory.getInstance().getObject('PosixUser', '78475884-c7f2-1035-8262-f535be14d43a') with mock.patch("zope.event.notify") as me, \ mock.patch.object(object, "remove_dn_refs") as mdn, \ mock.patch.object(object, "remove_refs") as mrem, \ mock.patch.object(object, "_delattr_"), \ mock.patch("gosa.backend.objects.object.ObjectBackendRegistry.getBackend") as mb, \ mock.patch("gosa.backend.objects.object.ObjectProxy") as c_obj: object.retract() assert me.called assert mdn.called assert mrem.called assert mb.return_value.retract.called
def test_get_references(self): obj = ObjectFactory.getInstance().getObject( 'PosixUser', '78475884-c7f2-1035-8262-f535be14d43a') res = obj.get_references() for rel in res: if rel[0] == "memberUid": assert rel == ('memberUid', 'uid', 'freich', [], False, "replace", { "identify": None, "replace": None, "delete": None })
def __init__(self): self.env = Environment.getInstance() # Remove old lock if exists if GlobalLock.exists("scan_index"): GlobalLock.release("scan_index") self.log = logging.getLogger(__name__) self.log.info("initializing object index handler") self.factory = ObjectFactory.getInstance() # Listen for object events zope.event.subscribers.append(self.__handle_events)
def test_get_dn_references(self): object = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') res = object.get_dn_references() assert len(res) == 1 assert 'member' in res[0] mocked_index = mock.MagicMock() mocked_index.search.return_value = [{'dn': 'dn1'}, {'dn': 'dn2'}] with mock.patch.dict(PluginRegistry.modules, {'ObjectIndex': mocked_index}): res = object.get_dn_references() assert len(res) == 1 assert 'member' in res[0] assert 'dn1' in res[0][1] assert 'dn2' in res[0][1]
def openObjectByType(self, user, session_id, key, value, type, *args, **kwargs): index = PluginRegistry.getInstance("ObjectIndex") query = {key: value} if ObjectFactory.getInstance().isBaseType(type): query["_type"] = type else: query["extension"] = type res = index.search(query, {"dn": 1}) if len(res) == 0: raise Exception(C.make_error("OBJECT_NOT_FOUND", object=args[0], id="%s(%s='%s')" % (type, key, value))) args = list(args) args.insert(0, res[0]["dn"]) return self.openObject(user, session_id, "object", *tuple(args), **kwargs)
def test_commit(self): object = ObjectFactory.getInstance().getObject('PosixUser', '78475884-c7f2-1035-8262-f535be14d43a') with mock.patch("gosa.backend.objects.object.ObjectBackendRegistry.getBackend") as mb, \ mock.patch("zope.event.notify") as me: object.homePhone = '023456' object.autoIDs = False object.uidNumber = 999 res = object.commit() assert mb.return_value.update.called assert me.called assert res['homePhone']['value'][0] == '023456' assert res['uidNumber']['value'][0] == 999
def test_update_dn_refs(self): object = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') with mock.patch.object(object, "get_dn_references", return_value=[('member', ['78475884-c7f2-1035-8262-f535be14d43a'])]) as m, \ mock.patch.object(object, "_delattr_"), \ mock.patch("gosa.backend.objects.object.ObjectProxy") as c_obj: c_obj.return_value.member = 'old dn' object.update_dn_refs('new dn') assert c_obj.return_value.member == 'new dn' c_obj.return_value.member = ['old dn'] object.update_dn_refs('new dn') assert 'new dn' in c_obj.return_value.member assert 'old dn' in c_obj.return_value.member assert c_obj.return_value.commit.called
def openObjectByType(self, user, session_id, key, value, type, *args, **kwargs): index = PluginRegistry.getInstance("ObjectIndex") query = {key: value} if ObjectFactory.getInstance().isBaseType(type): query["_type"] = type else: query["extension"] = type res = index.search(query, {"dn": 1}) if len(res) == 0: raise Exception( C.make_error("OBJECT_NOT_FOUND", object=args[0], id="%s(%s='%s')" % (type, key, value))) args = list(args) args.insert(0, res[0]["dn"]) return self.openObject(user, session_id, "object", *tuple(args), **kwargs)
def traverse_groups(self, value, type, attribute, attribute_content, group_type="GroupOfNames"): """ do a BFS search in sub-groups for object type """ index = PluginRegistry.getInstance("ObjectIndex") # check if the type can by found in a group res = index.search({"_type": group_type, attribute_content: {"in_": value}}, {attribute: 1}) sub_values = [x[attribute] for x in res] res = [] if len(sub_values): query = {attribute_content: {"in_": sub_values}} if ObjectFactory.getInstance().isBaseType(type): query["_type"] = type else: query["extension"] = type res = index.search(query, {"dn": 1}) if len(res) == 0 and len(sub_values): return self.traverse_groups(sub_values, type, attribute, attribute_content, group_type) else: return True
def test_remove_refs(self): object = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') with mock.patch.object(object, "get_references", return_value=[('memberUid', 'uid', 'freich', ['78475884-c7f2-1035-8262-f535be14d43a'], False)]) as m, \ mock.patch.object(object, "_delattr_"), \ mock.patch("gosa.backend.objects.object.ObjectProxy") as c_obj: c_obj.return_value.memberUid = 'Test' object.remove_refs() assert c_obj.return_value.memberUid is None assert c_obj.return_value.commit.called c_obj.return_value.memberUid = ['Test', 'freich'] object.remove_refs() assert c_obj.return_value.memberUid == ['Test'] m.return_value = [('memberUid', 'uid', ['freich'], ['78475884-c7f2-1035-8262-f535be14d43a'], True)] c_obj.return_value.memberUid = ['Test', 'freich'] object.remove_refs() assert c_obj.return_value.memberUid == ['Test']
def test_check(self): # wrong mode for base object obj = ObjectFactory.getInstance().getObject( 'User', '78475884-c7f2-1035-8262-f535be14d43a', 'delete') with pytest.raises(ObjectException): obj.check() # remove a non base object obj = ObjectFactory.getInstance().getObject( 'PosixUser', '78475884-c7f2-1035-8262-f535be14d43a', 'remove') with pytest.raises(ObjectException): obj.check() # update base object obj = ObjectFactory.getInstance().getObject( 'User', '78475884-c7f2-1035-8262-f535be14d43a') res = obj.check() # just test if something is there assert 'uid' in res # create new object with wrong dn obj = ObjectFactory.getInstance().getObject( 'User', 'cn=Test User,ou=people,dc=example,dc=net', 'create') with pytest.raises(ObjectException): obj.check() # create new SambaDomain object with base dn for User obj = ObjectFactory.getInstance().getObject( 'SambaDomain', 'ou=people,dc=example,dc=net', 'create') with pytest.raises(ObjectException): obj.check() # create new user object, missing mandatory attributes obj = ObjectFactory.getInstance().getObject( 'User', 'ou=people,dc=example,dc=net', 'create') with pytest.raises(ObjectException): obj.check() # add mandatory values obj.givenName = "Test" obj.sn = "User" obj.uid = "tuser" res = obj.check() assert 'uid' in res assert res['uid']['value'][0] == "tuser"
def remove_type(self, object_type, oid): ForemanBackend.modifier = "foreman" factory = ObjectFactory.getInstance() foreman_object = self.get_object(object_type, oid, create=False) if foreman_object is not None: types = factory.getObjectTypes()[object_type] base_type = object_type if types["base"] is True else types["extends"][0] if base_type is False: if not foreman_object.is_extended_by(object_type): # do not delete object which does not have the extension self.log.debug("device '%s' has no '%s' extension, deletion skipped" % (foreman_object.dn, object_type)) raise ForemanException(C.make_error('NO_FOREMAN_OBJECT')) # delete the complete object foreman_object.remove() # else: # # no base type just retract # foreman_object.retract(object_type) # foreman_object.commit() ForemanBackend.modifier = None
def __init__(self): self.env = Environment.getInstance() self.log = logging.getLogger(__name__) self.factory = ObjectFactory.getInstance() incoming_base = self.env.config.get("foreman.host-rdn") if incoming_base is None or len(incoming_base) == 0: incoming_base = self.env.base else: incoming_base = "%s,%s" % (incoming_base, self.env.base) group_rdn = self.env.config.get("foreman.group-rdn") self.type_bases = {"ForemanHost": incoming_base} if group_rdn is not None and len(group_rdn) > 0: self.type_bases["ForemanHostGroup"] = "%s,%s" % (group_rdn, self.env.base) else: self.type_bases["ForemanHostGroup"] = self.env.base self.__marked_hosts = {} if self.env.config.get("foreman.host") is None: self.log.warning("no foreman host configured") else: self.init_client(self.env.config.get("foreman.host")) self.gosa_server = "%s/rpc" % get_server_url() self.mqtt_host = None mqtt_host = self.env.config.get('mqtt.host') if mqtt_host is not None: if mqtt_host == "localhost": mqtt_host = socket.getfqdn() self.mqtt_host = "%s:%s" % (mqtt_host, self.env.config.get('mqtt.port', default=1883)) # Listen for object events self.log.info("Initial-Sync: %s, startpassive: %s" % (self.env.config.getboolean("foreman.initial-sync", default=True), self.env.config.getboolean("core.startpassive", default=False))) if not hasattr(sys, '_called_from_test') and \ self.env.config.getboolean("foreman.initial-sync", default=True) is True and \ self.env.mode != "proxy": zope.event.subscribers.append(self.__handle_events)
def process(self, all_props, key, value, type, attribute, attribute_content): errors = [] if key == "extension": # extension validation mode, use value from props value = all_props[attribute]["value"] if len(value) == 0: errors.append(dict(index=0, detail=N_("Object has no member of type '%(type)s'."), type=type)) else: index = PluginRegistry.getInstance("ObjectIndex") query = {attribute_content: {"in_": value}} if ObjectFactory.getInstance().isBaseType(type): query["_type"] = type else: query["extension"] = type res = index.search(query, {"dn": 1}) if len(res) > 0: return len(errors) == 0, errors if len(index.currently_in_creation) > 0: # check if the referenced object we are looking for is currently being created found_types = [x.__class__.__name__ for x in index.currently_in_creation if getattr(x, attribute_content) in value] if type in found_types: return True, errors if self.traverse_groups(value, type, attribute, attribute_content): # found type in subgroup member return True, errors errors.append(dict(index=0, detail=N_("Object has no member of type '%(type)s'."), type=type)) return len(errors) == 0, errors
def test_check(self): # wrong mode for base object obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a', 'delete') with pytest.raises(ObjectException): obj.check() # remove a non base object obj = ObjectFactory.getInstance().getObject('PosixUser', '78475884-c7f2-1035-8262-f535be14d43a', 'remove') with pytest.raises(ObjectException): obj.check() # update base object obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') res = obj.check() # just test if something is there assert 'uid' in res assert 'gender' in res # create new object with wrong dn obj = ObjectFactory.getInstance().getObject('User', 'cn=Test User,ou=people,dc=example,dc=net', 'create') with pytest.raises(ObjectException): obj.check() # create new SambaDomain object with base dn for User obj = ObjectFactory.getInstance().getObject('SambaDomain', 'ou=people,dc=example,dc=net', 'create') with pytest.raises(ObjectException): obj.check() # create new user object, missing mandatory attributes obj = ObjectFactory.getInstance().getObject('User', 'ou=people,dc=example,dc=net', 'create') with pytest.raises(ObjectException): obj.check() # add mandatory values obj.givenName = "Test" obj.sn = "User" obj.uid = "tuser" res = obj.check() assert 'uid' in res assert res['uid']['value'][0] == "tuser"
def test_getProperties(self): obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') res = obj.getProperties() # just test if something is there assert res['uid']['value'][0] == "freich"
def test_revert(self): obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') obj.uid = 'frank' obj.revert() assert obj.uid == 'freich'
def test_getForeignProperties(self): obj = ObjectFactory.getInstance().getObject('PosixUser', '78475884-c7f2-1035-8262-f535be14d43a') res = obj.getForeignProperties() assert 'uid' in res assert 'groupMembership' not in res
def test_listProperties(self): obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') res = obj.listProperties() # just test if something is there assert 'uid' in res assert 'gender' in res
def test_getAttrType(self): obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') assert obj.getAttrType('uid') == "String" with pytest.raises(AttributeError): obj.getAttrType('unknown')
def test_object_type_by_dn(self): obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') assert obj.get_object_type_by_dn("ou=people,dc=example,dc=net") == "PeopleContainer" assert obj.get_object_type_by_dn("ou=people,dc=example,dc=de") is None
def test_getTemplate(self): obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') res = obj.getTemplate() assert res[0][0:3] == "{\n "
def test_get_references(self): obj = ObjectFactory.getInstance().getObject('PosixUser', '78475884-c7f2-1035-8262-f535be14d43a') res = obj.get_references() assert res[0] == ('memberUid', 'uid', 'freich', [], False)
def test_is_attr_using_default(self): object = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') assert object.is_attr_using_default('uid') is False assert object.is_attr_using_default('autoDisplayName') is True
def test_is_attr_set(self): object = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') assert object.is_attr_set('uid') is True assert object.is_attr_set('pager') is False
def test_listMethods(self): obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') res = obj.listMethods() # just test if something is there assert obj.hasattr('uid') is True assert obj.hasattr('gender') is True
def test_listMethods(self): obj = ObjectFactory.getInstance().getObject('User', '78475884-c7f2-1035-8262-f535be14d43a') res = obj.listMethods() # just test if something is there assert 'lock' in res assert 'unlock' in res