Exemple #1
0
    def testCreateNamespacePermissionWithTemplate(self):
        """
        L{createNamespacePermission} can optionally use an existing
        L{NamespacePermission} as a template for the new one.
        """
        user = createUser(u'name', u'password', u'Name', u'*****@*****.**')
        namespace1 = createNamespace(user, u'name1')
        permission1 = createNamespacePermission(namespace1)
        permission1.set(Operation.CREATE_NAMESPACE, Policy.OPEN, [])
        permission1.set(Operation.UPDATE_NAMESPACE, Policy.OPEN, [])
        permission1.set(Operation.DELETE_NAMESPACE, Policy.OPEN, [])
        permission1.set(Operation.LIST_NAMESPACE, Policy.CLOSED, [user.id])
        permission1.set(Operation.CONTROL_NAMESPACE, Policy.OPEN, [])

        namespace2 = createNamespace(user, u'name2')
        permission2 = createNamespacePermission(namespace2, permission1)
        self.assertEqual((Policy.OPEN, []),
                         permission2.get(Operation.CREATE_NAMESPACE))
        self.assertEqual((Policy.OPEN, []),
                         permission2.get(Operation.UPDATE_NAMESPACE))
        self.assertEqual((Policy.OPEN, []),
                         permission2.get(Operation.DELETE_NAMESPACE))
        self.assertEqual((Policy.CLOSED, [user.id]),
                         permission2.get(Operation.LIST_NAMESPACE))
        self.assertEqual((Policy.OPEN, []),
                         permission2.get(Operation.CONTROL_NAMESPACE))
Exemple #2
0
 def testGetChildNamespaces(self):
     """
     L{getChildNamespace} returns the child L{Namespace}s for the specified
     parent paths.
     """
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     createNamespace(user, u'ignored')
     parent = createNamespace(user, u'parent')
     child = createNamespace(user, u'parent/child', parent.id)
     self.assertEqual(child, getChildNamespaces([u'parent']).one())
Exemple #3
0
 def testGetChildNamespacesOnlyConsidersDirectDescendants(self):
     """
     L{getChildNamespace} only returns L{Namespace}s that are direct
     descendants of the specified parent paths.
     """
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     parent = createNamespace(user, u'parent')
     child = createNamespace(user, u'parent/child', parent.id)
     createNamespace(user, u'parent/child/grandchild', child.id)
     self.assertEqual(child, getChildNamespaces([u'parent']).one())
Exemple #4
0
    def testCreateNamespaceWithUnknownParent(self):
        """
        L{Facade.createNamespace} raises a L{TNonexistentNamespace} exception
        if a non-existent parent L{Namespace} is specified.
        """
        createNamespace(self.user, u'username/name', self.user.namespace.id)
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            deferred = self.facade.createNamespace(session, u'unknown/parent',
                                                   u'name', u'A  namespace.')
            yield self.assertFailure(deferred, TNonexistentNamespace)
Exemple #5
0
    def testCreateNamespaceWithUnknownParent(self):
        """
        L{Facade.createNamespace} raises a L{TNonexistentNamespace} exception
        if a non-existent parent L{Namespace} is specified.
        """
        createNamespace(self.user, u'username/name', self.user.namespace.id)
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            deferred = self.facade.createNamespace(session, u'unknown/parent',
                                                   u'name', u'A  namespace.')
            yield self.assertFailure(deferred, TNonexistentNamespace)
Exemple #6
0
    def testCreateNamespaceWithExistingPath(self):
        """
        L{Facade.createNamespace} raises a L{TNamespaceAlreadyExists}
        exception if the new L{Namespace} already exists.
        """
        createNamespace(self.user, u'username/name', self.user.namespace.id)
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            deferred = self.facade.createNamespace(session, u'username',
                                                   u'name', u'A namespace.')
            yield self.assertFailure(deferred, TNamespaceAlreadyExists)
Exemple #7
0
 def testGetChildTags(self):
     """
     L{getChildTag} returns the child L{Namespace}s for the specified
     parent L{Namespace} paths.
     """
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     namespace = createNamespace(user, u'ignored')
     createTag(user, namespace, u'child')
     tag = createTag(user, user.namespace, u'child')
     self.assertEqual(tag, getChildTags([u'username']).one())
Exemple #8
0
    def testCreateNamespaceWithExistingPath(self):
        """
        L{Facade.createNamespace} raises a L{TNamespaceAlreadyExists}
        exception if the new L{Namespace} already exists.
        """
        createNamespace(self.user, u'username/name', self.user.namespace.id)
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            deferred = self.facade.createNamespace(session, u'username',
                                                   u'name', u'A namespace.')
            yield self.assertFailure(deferred, TNamespaceAlreadyExists)
Exemple #9
0
 def testGetNamespaces(self):
     """
     L{getNamespaces} returns all L{Namespace}s in the database, by
     default.
     """
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     namespace = createNamespace(user, u'name')
     result = getNamespaces()
     self.assertEqual([namespace, user.namespace],
                      list(result.order_by(Namespace.path)))
Exemple #10
0
 def testGetWithNamespaces(self):
     """
     L{NamespaceAPI.get} can optionally include the names of child
     L{Namespace} in the result.
     """
     createNamespace(self.user, u'username/child', self.user.namespace.id)
     result = self.namespaces.get([u'username'], withNamespaces=True)
     result['username']['namespaceNames'].sort()
     self.assertEqual({'username': {'id': self.user.namespace.objectID,
                                    'namespaceNames': [u'child',
                                                       u'private']}},
                      result)
Exemple #11
0
 def testCreateWithExistingNamespacePath(self):
     """
     L{TagAPI.create} can be used to create L{Tag}s with the same path as
     an existing L{Namespace}.
     """
     createNamespace(self.user, u'username/name', self.user.namespace.id)
     values = [(u'username/name', u'A description')]
     self.tags.create(values)
     systemTags = self.system.tags.keys()
     tag = self.store.find(Tag, Not(Tag.path.is_in(systemTags))).one()
     self.assertEqual(u'username/name', tag.path)
     self.assertEqual(u'name', tag.name)
     self.assertIdentical(self.user.namespace, tag.namespace)
Exemple #12
0
 def testGetNamespacePermissions(self):
     """
     L{getNamespacePermissions} returns the L{Namespace}s and
     L{NamespacePermission}s that match the specified L{Namespace.path}s.
     """
     user = createUser(u'name', u'password', u'Name', u'*****@*****.**')
     parentNamespace = createNamespace(user, u'name')
     parentPermission = createNamespacePermission(parentNamespace)
     childNamespace = createNamespace(user,
                                      u'name/child',
                                      parentID=parentNamespace.id)
     createNamespacePermission(childNamespace)
     self.assertEqual((parentNamespace, parentPermission),
                      getNamespacePermissions([u'name']).one())
Exemple #13
0
 def testGetWithNamespaces(self):
     """
     L{NamespaceAPI.get} can optionally include the names of child
     L{Namespace} in the result.
     """
     createNamespace(self.user, u'username/child', self.user.namespace.id)
     result = self.namespaces.get([u'username'], withNamespaces=True)
     result['username']['namespaceNames'].sort()
     self.assertEqual(
         {
             'username': {
                 'id': self.user.namespace.objectID,
                 'namespaceNames': [u'child', u'private']
             }
         }, result)
Exemple #14
0
    def testCreateTagPermissionInheritsFromNamespace(self):
        """
        L{createTagPermission} inherits permissions from its parent's
        L{NamespacePermission}s.
        """
        user = createUser(u'name', u'password', u'Name', u'*****@*****.**')
        namespace = createNamespace(user, u'name')
        permission1 = createNamespacePermission(namespace)
        permission1.set(Operation.CREATE_NAMESPACE, Policy.OPEN, [])
        permission1.set(Operation.UPDATE_NAMESPACE, Policy.OPEN, [])
        permission1.set(Operation.DELETE_NAMESPACE, Policy.OPEN, [])
        permission1.set(Operation.LIST_NAMESPACE, Policy.CLOSED, [user.id])
        permission1.set(Operation.CONTROL_NAMESPACE, Policy.OPEN, [])

        tag = createTag(user, namespace, u'tag')
        permission2 = createTagPermission(tag)
        self.assertEqual((Policy.OPEN, []),
                         permission2.get(Operation.UPDATE_TAG))
        self.assertEqual((Policy.OPEN, []),
                         permission2.get(Operation.DELETE_TAG))
        self.assertEqual((Policy.OPEN, []),
                         permission2.get(Operation.CONTROL_TAG))
        self.assertEqual((Policy.OPEN, []),
                         permission2.get(Operation.WRITE_TAG_VALUE))
        self.assertEqual((Policy.CLOSED, [user.id]),
                         permission2.get(Operation.READ_TAG_VALUE))
        self.assertEqual((Policy.OPEN, []),
                         permission2.get(Operation.DELETE_TAG_VALUE))
        self.assertEqual((Policy.OPEN, []),
                         permission2.get(Operation.CONTROL_TAG_VALUE))
Exemple #15
0
    def testCreateTagWithDefaultPermissions(self):
        """
        L{createTagPermission} creates a default set of permissions based on
        the default L{Namespace}s with permissions.
        """
        user = createUser(u'name', u'password', u'Name', u'*****@*****.**')
        namespace = createNamespace(user, u'name')
        createNamespacePermission(namespace)

        tag = createTag(user, namespace, u'tag')
        permission2 = createTagPermission(tag)
        self.assertEqual((Policy.CLOSED, [user.id]),
                         permission2.get(Operation.UPDATE_TAG))
        self.assertEqual((Policy.CLOSED, [user.id]),
                         permission2.get(Operation.DELETE_TAG))
        self.assertEqual((Policy.CLOSED, [user.id]),
                         permission2.get(Operation.CONTROL_TAG))
        self.assertEqual((Policy.CLOSED, [user.id]),
                         permission2.get(Operation.WRITE_TAG_VALUE))
        self.assertEqual((Policy.OPEN, []),
                         permission2.get(Operation.READ_TAG_VALUE))
        self.assertEqual((Policy.CLOSED, [user.id]),
                         permission2.get(Operation.DELETE_TAG_VALUE))
        self.assertEqual((Policy.CLOSED, [user.id]),
                         permission2.get(Operation.CONTROL_TAG_VALUE))
Exemple #16
0
 def testCreateTagPermission(self):
     """
     L{createTagPermission} creates a new L{TagPermission} using the
     system-wide default permission settings.
     """
     user = createUser(u'name', u'password', u'Name', u'*****@*****.**')
     namespace = createNamespace(user, u'name')
     tag = createTag(user, namespace, u'tag')
     permission = createTagPermission(tag)
     self.assertNotIdentical(None, permission.tagID)
     self.assertEqual(tag.id, permission.tagID)
     self.assertEqual(Policy.CLOSED, permission.updatePolicy)
     self.assertEqual([user.id], permission.updateExceptions)
     self.assertEqual(Policy.CLOSED, permission.deletePolicy)
     self.assertEqual([user.id], permission.deleteExceptions)
     self.assertEqual(Policy.CLOSED, permission.controlPolicy)
     self.assertEqual([user.id], permission.controlExceptions)
     self.assertEqual(Policy.CLOSED, permission.writeValuePolicy)
     self.assertEqual([user.id], permission.writeValueExceptions)
     self.assertEqual(Policy.OPEN, permission.readValuePolicy)
     self.assertEqual([], permission.readValueExceptions)
     self.assertEqual(Policy.CLOSED, permission.deleteValuePolicy)
     self.assertEqual([user.id], permission.deleteValueExceptions)
     self.assertEqual(Policy.CLOSED, permission.controlValuePolicy)
     self.assertEqual([user.id], permission.controlValueExceptions)
Exemple #17
0
 def testGetTags(self):
     """L{getTags} returns all L{Tag}s in the database, by default."""
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     tag = createTag(user, user.namespace, u'name')
     self.assertEqual(tag, getTags().one())
Exemple #18
0
    def testUniqueFileIDAndValueID(self):
        """
        An C{IntegrityError} is raised if an L{OpaqueValueLink} with the same
        fileID and valueID is added to the database. Duplicated C{tag_id} or
        C{file_id} can be added as long as the pair is unique.
        """
        user = createUser(u'name', u'password', u'User', u'*****@*****.**')
        user.namespaceID = createNamespace(user, user.username, None).id
        tag = createTag(user, user.namespace, u'tag')
        value1 = TagValue(user.id, tag.id, uuid4(), None)
        value2 = TagValue(user.id, tag.id, uuid4(), None)
        self.store.add(value1)
        self.store.add(value2)
        self.store.flush()

        fileID1 = 'f' * 64
        fileID2 = '0' * 64

        self.store.add(OpaqueValue(fileID1, 'content1'))
        self.store.add(OpaqueValue(fileID2, 'content2'))

        # Add an initial link
        self.store.add(OpaqueValueLink(value1.id, fileID1))

        # Add link with the same fileID but different valueID. It should work.
        self.store.add(OpaqueValueLink(value2.id, fileID1))
        # Add link with the same valueID but different fileID. It should work.
        self.store.add(OpaqueValueLink(value1.id, fileID2))
        self.store.flush()

        # Add link with same fileID and valueID. It should fail.
        self.store.add(OpaqueValueLink(value1.id, fileID1))
        self.assertRaises(IntegrityError, self.store.flush)
        self.store.rollback()
Exemple #19
0
 def testCreateNamespaceAddsToStore(self):
     """L{createNamespace} adds the new L{Namespace} to the main store."""
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     namespace = createNamespace(user, u'name')
     result = self.store.find(Namespace, Namespace.name == u'name')
     self.assertIdentical(namespace, result.one())
Exemple #20
0
    def create(self, values):
        """Create new L{Namespace}s.

        Missing parent L{Namespace}s are created automatically.  For example,
        if C{foo/bar/baz} is requested, and C{foo/bar} doesn't already exist,
        it will be created before C{foo/bar/baz} is created.  Associated
        L{NamespacePermission}s are created automatically with the system-wide
        default permissions.

        @param values: A sequence of C{(path, description)} 2-tuples.
        @raises DuplicatePathError: Raised if the path for a new L{Namespace}
            collides with an existing one.
        @raise MalformedPathError: Raised if one of the given paths is empty
            or has unacceptable characters.
        @return: A C{list} of C{(objectID, path)} 2-tuples for the new
            L{Namespace}s.
        """
        from fluiddb.model.user import getUser

        if not values:
            return []

        paths = [path for path, description in values]
        descriptions = dict(values)

        self._checkForDuplicates(paths)

        admin = getUser(u'fluiddb')
        objects = self._factory.objects(admin)
        systemValues = {}

        paths = getPathHierarchy(paths)
        existingNamespaces = dict((namespace.path, namespace)
                                  for namespace in getNamespaces(paths=paths))
        newNamespaces = []

        for path in sorted(paths):
            if path in existingNamespaces:
                continue

            parentPath = getParentPath(path)
            parentID = (existingNamespaces[parentPath].id
                        if parentPath is not None
                        else None)
            namespace = createNamespace(self._user, path, parentID)
            aboutValue = u'Object for the namespace %s' % path
            description = descriptions.get(path, aboutValue)
            namespace.objectID = objects.create(aboutValue)
            systemValues[namespace.objectID] = {
                u'fluiddb/namespaces/description': description,
                u'fluiddb/namespaces/path': path,
                u'fluiddb/about': aboutValue}
            existingNamespaces[path] = namespace
            newNamespaces.append(namespace)

        self._createPermissions(newNamespaces)
        self._factory.tagValues(admin).set(systemValues)
        values = [(namespace.objectID, namespace.path)
                  for namespace in newNamespaces]
        return values
Exemple #21
0
 def testGetBinaryValue(self):
     """
     L{TagValueAPI.get} returns the MIME type and file contents for binary
     L{TagValue}s.
     """
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     objectID = uuid4()
     # NOTE: we use 'Hello \xA2' as value to test that a non utf-8 string
     # will work properly.
     values = {
         objectID: {
             u'name/tag': {
                 'mime-type': 'text/plain',
                 'contents': 'Hello \xA2'
             }
         }
     }
     self.tagValues.set(values)
     result = self.tagValues.get([objectID], [u'name/tag'])
     self.assertEqual(values[objectID][u'name/tag']['mime-type'],
                      result[objectID][u'name/tag'].value['mime-type'])
     self.assertEqual(values[objectID][u'name/tag']['contents'],
                      result[objectID][u'name/tag'].value['contents'])
Exemple #22
0
 def testCreateTagAddsToStore(self):
     """L{createTag} adds the new L{Tag} to the main store."""
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     tag = createTag(user, user.namespace, u'tag')
     result = self.store.find(Tag, Tag.path == u'username/tag')
     self.assertIdentical(tag, result.one())
 def setUp(self):
     super(GetRecentActivityTest, self).setUp()
     self.user1 = createUser(u'user1', 'hash', u'User', u'*****@*****.**')
     self.user2 = createUser(u'user2', 'hash', u'User', u'*****@*****.**')
     self.user3 = createUser(u'user3', 'hash', u'User', u'*****@*****.**')
     self.user1.namespaceID = createNamespace(self.user1,
                                              self.user1.username, None).id
     self.user2.namespaceID = createNamespace(self.user2,
                                              self.user2.username, None).id
     self.user3.namespaceID = createNamespace(self.user3,
                                              self.user3.username, None).id
     self.user1tag1 = createTag(self.user1, self.user1.namespace, u'tag1')
     self.user1tag2 = createTag(self.user1, self.user1.namespace, u'tag2')
     self.user2tag1 = createTag(self.user2, self.user2.namespace, u'tag1')
     self.user2tag2 = createTag(self.user2, self.user2.namespace, u'tag2')
     self.user3tag1 = createTag(self.user3, self.user3.namespace, u'tag1')
     self.user3tag2 = createTag(self.user3, self.user3.namespace, u'tag2')
Exemple #24
0
 def testUnicodeSetValue(self):
     """A L{TagValue} can store a C{list} of C{unicode} values."""
     objectID = uuid4()
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     namespace = createNamespace(user, u'name')
     tag = createTag(user, namespace, u'tag')
     self.store.add(TagValue(user.id, tag.id, objectID, [u'foo', u'bar']))
Exemple #25
0
 def setUp(self):
     super(TagValueIntegrityCheckerTest, self).setUp()
     self.system = createSystemData()
     self.user = createUser(u'user', u'pass', u'Name', u'*****@*****.**')
     self.parent = createNamespace(self.user, u'user', None)
     self.user.namespaceID = self.parent.id
     self.checker = TagValueIntegrityChecker()
     self.superuser = self.system.users[u'fluiddb']
Exemple #26
0
 def testGet(self):
     """
     L{NamespaceAPI.get} returns L{Namespace}s that match the specified
     paths.
     """
     namespace = createNamespace(self.user, u'namespace')
     self.assertEqual({'namespace': {'id': namespace.objectID}},
                      self.namespaces.get([u'namespace']))
Exemple #27
0
 def testFloatValue(self):
     """A L{TagValue} can store a C{float} value."""
     objectID = uuid4()
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     namespace = createNamespace(user, u'name')
     tag = createTag(user, namespace, u'tag')
     self.store.add(TagValue(user.id, tag.id, objectID, 42.1))
Exemple #28
0
 def setUp(self):
     super(TagValueIntegrityCheckerTest, self).setUp()
     self.system = createSystemData()
     self.user = createUser(u'user', u'pass', u'Name', u'*****@*****.**')
     self.parent = createNamespace(self.user, u'user', None)
     self.user.namespaceID = self.parent.id
     self.checker = TagValueIntegrityChecker()
     self.superuser = self.system.users[u'fluiddb']
Exemple #29
0
 def setUp(self):
     super(GetRecentActivityTest, self).setUp()
     self.user1 = createUser(u'user1', 'hash', u'User', u'*****@*****.**')
     self.user2 = createUser(u'user2', 'hash', u'User', u'*****@*****.**')
     self.user3 = createUser(u'user3', 'hash', u'User', u'*****@*****.**')
     self.user1.namespaceID = createNamespace(self.user1,
                                              self.user1.username, None).id
     self.user2.namespaceID = createNamespace(self.user2,
                                              self.user2.username, None).id
     self.user3.namespaceID = createNamespace(self.user3,
                                              self.user3.username, None).id
     self.user1tag1 = createTag(self.user1, self.user1.namespace, u'tag1')
     self.user1tag2 = createTag(self.user1, self.user1.namespace, u'tag2')
     self.user2tag1 = createTag(self.user2, self.user2.namespace, u'tag1')
     self.user2tag2 = createTag(self.user2, self.user2.namespace, u'tag2')
     self.user3tag1 = createTag(self.user3, self.user3.namespace, u'tag1')
     self.user3tag2 = createTag(self.user3, self.user3.namespace, u'tag2')
Exemple #30
0
 def testGet(self):
     """
     L{NamespaceAPI.get} returns L{Namespace}s that match the specified
     paths.
     """
     namespace = createNamespace(self.user, u'namespace')
     self.assertEqual({'namespace': {
         'id': namespace.objectID
     }}, self.namespaces.get([u'namespace']))
Exemple #31
0
    def testWrongParent(self):
        """
        L{NamespaceIntegrityChecker.check} logs an error if the given
        L{Namespace} has a wrong associated parent.
        """
        parent = createNamespace(self.user.id, u'parent', None)
        test = createNamespace(self.user.id, u'user/test', parent.id)
        createNamespacePermission(test)
        createTagValue(self.user.id, self.descriptionTag.id, test.objectID,
                       u'Description for test tag')
        createTagValue(self.user.id, self.pathTag.id, test.objectID,
                       u'user/test')
        createTagValue(self.user.id, self.aboutTag.id, test.objectID,
                       u'Object for the namespace %s' % test.path)

        self.checker.check([test])
        self.assertEqual("Integrity Error in namespace u'user/test': "
                         'Assigned parent is incorrect.\n',
                         self.log.getvalue())
Exemple #32
0
 def testCreateTagWithMalformedPath(self):
     """
     L{createTag} raises a L{MalformedPathError} if an invalid path is
     provided.
     """
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     self.assertRaises(MalformedPathError, createTag, user, user.namespace,
                       u'')
Exemple #33
0
 def testAllowWithInvalidOperation(self):
     """
     L{NamespacePermission.allow} raises a C{RuntimeError} if the request
     L{Operation} is not a namespace operation.
     """
     user = createUser(u'name', u'password', u'Name', u'*****@*****.**')
     namespace = createNamespace(user, u'name')
     permission = createNamespacePermission(namespace)
     self.assertRaises(RuntimeError, permission.allow, user.id,
                       Operation.WRITE_TAG_VALUE)
Exemple #34
0
 def testCreateTag(self):
     """L{createTag} creates a new L{Tag}."""
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     tag = createTag(user, user.namespace, u'tag')
     self.assertIdentical(user, tag.creator)
     self.assertIdentical(user.namespace, tag.namespace)
     self.assertEqual(u'username/tag', tag.path)
     self.assertEqual(u'tag', tag.name)
Exemple #35
0
 def testGetWithInvalidOperation(self):
     """
     L{NamespacePermission.get} raises a C{RuntimeError} if an invalid
     L{Operation} is provided.
     """
     user = createUser(u'name', u'password', u'Name', u'*****@*****.**')
     namespace = createNamespace(user, u'name')
     permission = createNamespacePermission(namespace)
     self.assertRaises(RuntimeError, permission.get,
                       Operation.WRITE_TAG_VALUE)
Exemple #36
0
 def testGetObjectIDsWithUnknownObjectID(self):
     """
     L{getObjectIDs} doesn't return any results if unknown tag paths are
     provided.
     """
     user = createUser(u'user', u'secret', u'User', u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     tag = createTag(user, user.namespace, u'name1')
     createTagValue(user.id, tag.id, uuid4(), 42)
     self.assertEqual([], list(getObjectIDs([u'user/name2'])))
Exemple #37
0
 def testGetNamespacesWithObjectIDs(self):
     """
     When L{Namespace.objectIDs}s are provided L{getNamespaces} returns
     matching L{Namespace}s.
     """
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     namespace = createNamespace(user, u'name')
     result = getNamespaces(objectIDs=[namespace.objectID])
     self.assertIdentical(namespace, result.one())
Exemple #38
0
 def testGetTagsWithPaths(self):
     """
     When L{Tag.path}s are provided L{getTags} returns matching L{Tag}s.
     """
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     tag = createTag(user, user.namespace, u'name1')
     createTag(user, user.namespace, u'name2')
     result = getTags(paths=[u'username/name1'])
     self.assertIdentical(tag, result.one())
Exemple #39
0
 def testDeleteOnlyDirtiesRemovedObjects(self):
     """L{TagValueAPI.delete} only marks affected objects as being dirty."""
     objectID = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     result = self.tagValues.delete([(objectID, u'name/tag')])
     self.assertEqual(0, result)
     self.assertNotIn(objectID,
                      getDirtyObjects().values(DirtyObject.objectID))
Exemple #40
0
 def testGetWithDescriptions(self):
     """
     L{NamespaceAPI.get} can optionally include L{Namespace.description}s
     in the result.
     """
     descriptionTag = self.system.tags[u'fluiddb/namespaces/description']
     namespace = createNamespace(self.user, u'namespace')
     createTagValue(self.user.id, descriptionTag.id, namespace.objectID,
                    u'A namespace')
     result = self.namespaces.get([u'namespace'], withDescriptions=True)
     self.assertEqual(namespace.objectID, result['namespace']['id'])
     self.assertEqual(u'A namespace', result['namespace']['description'])
Exemple #41
0
 def setUp(self):
     super(NamespaceIntegrityCheckerTest, self).setUp()
     system = createSystemData()
     self.user = createUser(u'user', u'pass', u'Name', u'*****@*****.**')
     self.superuser = system.users[u'fluiddb']
     self.anonymous = system.users[u'anon']
     self.parent = createNamespace(self.user, u'user', None)
     self.user.namespaceID = self.parent.id
     self.descriptionTag = system.tags['fluiddb/namespaces/description']
     self.pathTag = system.tags['fluiddb/namespaces/path']
     self.aboutTag = system.tags['fluiddb/about']
     self.checker = NamespaceIntegrityChecker()
Exemple #42
0
 def testUniquePathConstraint(self):
     """
     An C{IntegrityError} is raised if a L{Tag} with a duplicate path is
     added to the database.
     """
     user = createUser(u'name', u'password', u'User', u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     self.store.add(Tag(user, user.namespace, u'name/tag', u'tag'))
     self.store.flush()
     self.store.add(Tag(user, user.namespace, u'name/tag', u'tag'))
     self.assertRaises(IntegrityError, self.store.flush)
     self.store.rollback()
Exemple #43
0
 def testSetUpdates(self):
     """L{TagValueAPI.set} updates an existing value with a new one."""
     objectID = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     self.tagValues.set({objectID: {u'name/tag': 5}})
     self.tagValues.set({objectID: {u'name/tag': None}})
     value = getTagValues([(objectID, tag.id)]).one()
     self.assertEqual(tag.id, value.tagID)
     self.assertEqual(objectID, value.objectID)
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
Exemple #44
0
 def testDeleteReturnsRowCount(self):
     """
     L{TagValueAPI.delete} returns the number of rows that were deleted.
     """
     objectID = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     createTagValue(self.user.id, tag.id, objectID, 42)
     result = self.tagValues.delete([(objectID, u'name/tag')])
     self.assertEqual(1, result)
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
Exemple #45
0
 def testDelete(self):
     """L{TagValueAPI.delete} deletes L{TagValue}s."""
     objectID = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     createTagValue(self.user.id, tag.id, objectID, None)
     self.tagValues.delete([(objectID, u'name/tag')])
     values = self.store.find(TagValue, TagValue.tagID == Tag.id,
                              Not(Tag.path.is_in(self.system.tags)))
     self.assertEqual([], list(values))
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
Exemple #46
0
 def _createNamespaces(self):
     """Create L{Namespace}s."""
     superuser = self.users[u'fluiddb']
     for namespaceData in self._data['namespaces']:
         path = namespaceData['path']
         parentPath = getParentPath(path)
         parentNamespace = self.namespaces.get(parentPath, None)
         parentID = parentNamespace.id if parentNamespace else None
         namespace = createNamespace(superuser, path, parentID)
         self._createNamespacePermissions(namespace)
         self.namespaces[path] = namespace
         if path in self.users:
             self.users[path].namespaceID = namespace.id
Exemple #47
0
    def setUp(self):
        super(BatchIndexTest, self).setUp()

        # We use low-level functions here instead of model API methods because
        # we want to avoid an automatic update of the objects table.
        user = createUser(u'username', u'secret', u'User', u'*****@*****.**')
        namespace = createNamespace(user, u'username', None)
        tag = createTag(user, namespace, u'tag')

        self.userID = user.id
        self.tagID = tag.id
        tempPath = self.config.get('service', 'temp-path')
        self.objectsFilename = os.path.join(tempPath, 'objects.txt')
Exemple #48
0
 def testCreateNamespace(self):
     """L{createNamespace} creates a new L{Namespace}."""
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     namespace = createNamespace(user, u'name')
     self.assertEqual(u'name', namespace.path)
     self.assertEqual(u'name', namespace.name)
     self.assertIdentical(None, namespace.parentID)
     self.assertNotIdentical(None, namespace.objectID)
     self.assertNotIdentical(None, namespace.creationTime)
     self.assertIdentical(user, namespace.creator)
     self.assertIdentical(None, namespace.parent)
     self.assertIdentical(None, namespace.children.one())
Exemple #49
0
 def testSet(self):
     """L{TagValueAPI.set} stores new L{TagValue}s."""
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     objectID = uuid4()
     values = {objectID: {u'name/tag': 42}}
     self.tagValues.set(values)
     value = getTagValues([(objectID, tag.id)]).one()
     self.assertEqual(tag.id, value.tagID)
     self.assertEqual(objectID, value.objectID)
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
Exemple #50
0
 def testUniqueObjectIDConstraint(self):
     """
     An C{IntegrityError} is raised if a L{Tag} with a duplicate object ID
     is added to the database.
     """
     user = createUser(u'name', u'password', u'User', u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     tag1 = Tag(user, user.namespace, u'name/tag1', u'tag1')
     self.store.add(tag1)
     self.store.flush()
     tag2 = Tag(user, user.namespace, u'name/tag2', u'tag2')
     tag2.objectID = tag1.objectID
     self.store.add(tag2)
     self.assertRaises(IntegrityError, self.store.flush)
     self.store.rollback()