def testGetPathName(self): """ L{getPathName} returns the final segment in the path, for non-root-level paths. """ self.assertEqual(u'bar', getPathName(u'foo/bar')) self.assertEqual(u'baz', getPathName(u'foo/bar/baz'))
def _createTags(self, values, parentNamespaces): """Create new tags. @param values: A sequence of C{(Tag.path, description)} 2-tuples. @param parentNamespaces: A C{dict} mapping L{Namespace.path}s to L{Namespace} instances, the parents of the new L{Tag}s. @return: A C{list} of C{(objectID, Tag.path)} 2-tuples. """ admin = getUser(u'fluiddb') objects = self._factory.objects(admin) systemValues = {} result = [] tags = [] for path, description in values: parentPath = getParentPath(path) name = getPathName(path) parentNamespace = parentNamespaces.get(parentPath) tag = createTag(self._user, parentNamespace, name) tag.objectID = objects.create( u'Object for the attribute %s' % path) result.append((tag.objectID, path)) systemValues[tag.objectID] = { u'fluiddb/tags/description': description, u'fluiddb/tags/path': path } tags.append(tag) self._createPermissions(tags) if systemValues: self._factory.tagValues(admin).set(systemValues) return result
def _createTags(self): """Create tags.""" superuser = self.users[u'fluiddb'] for tag in self._data['tags']: path = tag['path'] parentPath = getParentPath(path) name = getPathName(path) parentNamespace = self.namespaces[parentPath] tagObject = createTag(superuser, parentNamespace, name) self._createTagPermissions(tagObject) self.tags[path] = tagObject
def createNamespace(creator, path, parentID=None): """Create a new root-level L{Namespace}. @param creator: The L{User} that owns the namespace. @param path: The C{unicode} path (and name) of the namespace. @param parentID: Optionally, the L{Namespace.id} of the parent namespace. @raise MalformedPathError: Raised if C{path} is empty or has unacceptable characters. @return: A new L{Namespace} instance persisted in the main store. """ if not isValidPath(path): raise MalformedPathError("'%s' is not a valid path." % path) store = getMainStore() name = getPathName(path) namespace = Namespace(creator, path, name, parentID) return store.add(namespace)
def testGetPathNameWithRootPath(self): """L{getPathName} returns the path, unchanged, for root-level paths.""" self.assertEqual(u'foo', getPathName(u'foo'))