コード例 #1
0
ファイル: test_index.py プロジェクト: xanixon/fluiddb
    def testBatchIndexTouchesAllObjects(self):
        """C{batchIndex} touches all objects in the given file."""
        createTagValue(self.userID, self.tagID, uuid4(), 10)
        createTagValue(self.userID, self.tagID, uuid4(), 20)

        allObjects = set(getTagValues().values(TagValue.objectID))
        self.createObjectsFile()
        batchIndex(self.objectsFilename, 0, 10)
        touchedObjects = set(getDirtyObjects().values(DirtyObject.objectID))
        self.assertEqual(allObjects, touchedObjects)
コード例 #2
0
ファイル: test_value.py プロジェクト: fluidinfo/fluiddb
 def testGetFilteredByUnknownObjectIDs(self):
     """
     L{TagValueAPI.get} doesn't return any L{Tag} values if none of the
     requested object IDs exist.
     """
     tag = createTag(self.user, self.user.namespace, u'tag')
     createTagPermission(tag)
     createTagValue(self.user.id, tag.id, uuid4(), 42)
     self.assertEqual({}, self.tagValues.get(objectIDs=[uuid4()],
                                             paths=[u'username/tag']))
コード例 #3
0
ファイル: test_index.py プロジェクト: fluidinfo/fluiddb
    def testBatchIndexTouchesAllObjects(self):
        """C{batchIndex} touches all objects in the given file."""
        createTagValue(self.userID, self.tagID, uuid4(), 10)
        createTagValue(self.userID, self.tagID, uuid4(), 20)

        allObjects = set(getTagValues().values(TagValue.objectID))
        self.createObjectsFile()
        batchIndex(self.objectsFilename, 0, 10)
        touchedObjects = set(getDirtyObjects().values(DirtyObject.objectID))
        self.assertEqual(allObjects, touchedObjects)
コード例 #4
0
ファイル: test_value.py プロジェクト: xanixon/fluiddb
 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'])))
コード例 #5
0
ファイル: test_tag.py プロジェクト: xanixon/fluiddb
 def testGetWithDescriptions(self):
     """
     L{TagAPI.get} can optionally include L{Tag.description}s in the
     result.
     """
     descriptionTag = self.system.tags[u'fluiddb/tags/description']
     tag = createTag(self.user, self.user.namespace, u'tag')
     createTagValue(self.user.id, descriptionTag.id, tag.objectID, u'A tag')
     result = self.tags.get([u'username/tag'], withDescriptions=True)
     self.assertEqual(tag.objectID, result[u'username/tag']['id'])
     self.assertEqual(u'A tag', result[u'username/tag']['description'])
コード例 #6
0
 def testGetFilteredByUnknownObjectIDs(self):
     """
     L{TagValueAPI.get} doesn't return any L{Tag} values if none of the
     requested object IDs exist.
     """
     tag = createTag(self.user, self.user.namespace, u'tag')
     createTagPermission(tag)
     createTagValue(self.user.id, tag.id, uuid4(), 42)
     self.assertEqual({},
                      self.tagValues.get(objectIDs=[uuid4()],
                                         paths=[u'username/tag']))
コード例 #7
0
ファイル: test_namespace.py プロジェクト: fluidinfo/fluiddb
 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'])
コード例 #8
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'])
コード例 #9
0
ファイル: test_value.py プロジェクト: fluidinfo/fluiddb
 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))
コード例 #10
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))
コード例 #11
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))
コード例 #12
0
ファイル: test_value.py プロジェクト: xanixon/fluiddb
 def testGetObjectIDs(self):
     """
     L{getObjectIDs} returns a sequence of object IDs that match the
     specified paths.
     """
     objectID1 = uuid4()
     user = createUser(u'user', u'secret', u'User', u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     tag1 = createTag(user, user.namespace, u'name1')
     tag2 = createTag(user, user.namespace, u'name2')
     createTagValue(user.id, tag1.id, objectID1, 42)
     createTagValue(user.id, tag2.id, uuid4(), 17)
     self.assertEqual(objectID1, getObjectIDs([u'user/name1']).one())
コード例 #13
0
ファイル: test_value.py プロジェクト: fluidinfo/fluiddb
 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))
コード例 #14
0
ファイル: test_value.py プロジェクト: xanixon/fluiddb
 def testGetTagPathsAndObjectIDs(self):
     """
     L{getTagPathsAndObjectIDs} returns a C{(Tag.path, objectID)} 2-tuples
     that match the specified object IDs.
     """
     objectID = uuid4()
     user = createUser(u'user', u'secret', u'User', u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     tag = createTag(user, user.namespace, u'name1')
     createTag(user, user.namespace, u'name2')
     createTagValue(user.id, tag.id, objectID, 42)
     createTagValue(user.id, tag.id, uuid4(), 17)
     self.assertEqual((tag.path, objectID),
                      getTagPathsAndObjectIDs([objectID]).one())
コード例 #15
0
ファイル: test_value.py プロジェクト: xanixon/fluiddb
 def testGetOpaqueValues(self):
     """
     L{getOpaqueValues} returns L{OpaqueValue}s for the given L{TagValue}s.
     """
     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 = createTagValue(user.id, tag.id, uuid4(), None)
     value2 = createTagValue(user.id, tag.id, uuid4(), None)
     self.store.commit()
     opaque1 = createOpaqueValue(value1.id, 'content1')
     opaque2 = createOpaqueValue(value2.id, 'content2')
     self.assertEqual(sorted([opaque1, opaque2]),
                      sorted(getOpaqueValues([value1.id, value2.id])))
コード例 #16
0
ファイル: test_object.py プロジェクト: fluidinfo/fluiddb
 def testGetTagsForObjects(self):
     """
     L{ObjectAPI.getTagsForObjects} returns a C{list} of L{Tag.path}s that
     are associated with the given objects.
     """
     tag = createTag(self.user, self.user.namespace, u'tag')
     createTagPermission(tag)
     objectID1 = uuid4()
     objectID2 = uuid4()
     createTagValue(self.user.id, tag.id, objectID1, u'value1')
     createTagValue(self.user.id, tag.id, objectID2, u'value2')
     self.assertEqual(
         [u'user/tag'],
         self.objects.getTagsForObjects([objectID1, objectID2]))
コード例 #17
0
ファイル: test_object.py プロジェクト: xanixon/fluiddb
 def testGetTagsForObjects(self):
     """
     L{ObjectAPI.getTagsForObjects} returns a C{list} of L{Tag.path}s that
     are associated with the given objects.
     """
     tag = createTag(self.user, self.user.namespace, u'tag')
     createTagPermission(tag)
     objectID1 = uuid4()
     objectID2 = uuid4()
     createTagValue(self.user.id, tag.id, objectID1, u'value1')
     createTagValue(self.user.id, tag.id, objectID2, u'value2')
     self.assertEqual([u'user/tag'],
                      self.objects.getTagsForObjects([objectID1,
                                                      objectID2]))
コード例 #18
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
 def testMissingAboutValue(self):
     """
     L{NamespaceIntegrityChecker.check} logs an error if the given
     L{Namespace} doesn't have a C{fluiddb/about} value.
     """
     test = createNamespace(self.user.id, u'user/test', self.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')
     self.checker.check([test])
     self.assertEqual(u"Integrity Error in namespace u'user/test': "
                      u'About tag is missing.\n',
                      self.log.getvalue())
コード例 #19
0
ファイル: test_index.py プロジェクト: xanixon/fluiddb
 def testBatchIndexLogsErrorIfObjectIDIsNotWellFormed(self):
     """
     If C{batchIndex} encounters a malformed objectID in the file it will
     continue the process after printing an error in the logs.
     """
     createTagValue(self.userID, self.tagID, uuid4(), 10)
     createTagValue(self.userID, self.tagID, uuid4(), 20)
     allObjects = set(getTagValues().values(TagValue.objectID))
     self.createObjectsFile()
     with open(self.objectsFilename, 'a') as objectsFilename:
         objectsFilename.write('wrong-id')
     batchIndex(self.objectsFilename, 0, 10)
     touchedObjects = set(getDirtyObjects().values(DirtyObject.objectID))
     self.assertEqual(allObjects, touchedObjects)
     self.assertIn("Invalid objectID: 'wrong-id'", self.log.getvalue())
コード例 #20
0
ファイル: test_index.py プロジェクト: fluidinfo/fluiddb
 def testBatchIndexLogsErrorIfObjectIDIsNotWellFormed(self):
     """
     If C{batchIndex} encounters a malformed objectID in the file it will
     continue the process after printing an error in the logs.
     """
     createTagValue(self.userID, self.tagID, uuid4(), 10)
     createTagValue(self.userID, self.tagID, uuid4(), 20)
     allObjects = set(getTagValues().values(TagValue.objectID))
     self.createObjectsFile()
     with open(self.objectsFilename, 'a') as objectsFilename:
         objectsFilename.write('wrong-id')
     batchIndex(self.objectsFilename, 0, 10)
     touchedObjects = set(getDirtyObjects().values(DirtyObject.objectID))
     self.assertEqual(allObjects, touchedObjects)
     self.assertIn("Invalid objectID: 'wrong-id'", self.log.getvalue())
コード例 #21
0
 def testMissingAboutValue(self):
     """
     L{NamespaceIntegrityChecker.check} logs an error if the given
     L{Namespace} doesn't have a C{fluiddb/about} value.
     """
     test = createNamespace(self.user.id, u'user/test', self.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')
     self.checker.check([test])
     self.assertEqual(
         u"Integrity Error in namespace u'user/test': "
         u'About tag is missing.\n', self.log.getvalue())
コード例 #22
0
ファイル: test_value.py プロジェクト: xanixon/fluiddb
 def testGetTagPathsForObjectIDs(self):
     """
     L{getTagPathsForObjectIDs} returns the unique set of L{Tag.path}s that
     match the specified object IDs.
     """
     objectID1 = uuid4()
     objectID2 = uuid4()
     user = createUser(u'user', u'secret', u'User', u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     tag = createTag(user, user.namespace, u'name1')
     createTag(user, user.namespace, u'name2')
     createTagValue(user.id, tag.id, objectID1, 42)
     createTagValue(user.id, tag.id, objectID2, 17)
     result = getTagPathsForObjectIDs([objectID1, objectID2])
     self.assertEqual(u'user/name1', result.one())
コード例 #23
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
    def testMissingDescriptionTagValue(self):
        """
        L{TagIntegrityChecker.check} logs an error if the given L{Tag} doesn't
        have C{fluiddb/tags/description} value.
        """
        test = createTag(self.user, self.parent, u'test')
        createTagPermission(test)
        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 attribute %s' % test.path)

        self.checker.check([test])
        self.assertEqual("Integrity Error in tag u'user/test': "
                         'Description tag is missing.\n',
                         self.log.getvalue())
コード例 #24
0
    def testMissingDescriptionTagValue(self):
        """
        L{NamespaceIntegrityChecker.check} logs an error if the given
        L{Namespace} doesn't have C{fluiddb/namespaces/description} value.
        """
        test = createNamespace(self.user.id, u'user/test', self.parent.id)
        createNamespacePermission(test)
        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': "
            'Description tag is missing.\n', self.log.getvalue())
コード例 #25
0
    def testMissingDescriptionTagValue(self):
        """
        L{TagIntegrityChecker.check} logs an error if the given L{Tag} doesn't
        have C{fluiddb/tags/description} value.
        """
        test = createTag(self.user, self.parent, u'test')
        createTagPermission(test)
        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 attribute %s' % test.path)

        self.checker.check([test])
        self.assertEqual(
            "Integrity Error in tag u'user/test': "
            'Description tag is missing.\n', self.log.getvalue())
コード例 #26
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
    def testMissingDescriptionTagValue(self):
        """
        L{NamespaceIntegrityChecker.check} logs an error if the given
        L{Namespace} doesn't have C{fluiddb/namespaces/description} value.
        """
        test = createNamespace(self.user.id, u'user/test', self.parent.id)
        createNamespacePermission(test)
        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': "
                         'Description tag is missing.\n',
                         self.log.getvalue())
コード例 #27
0
    def testAboutTagValueWithoutValue(self):
        """
        L{AboutTagValueIntegrityChecker.check} logs an error if the given
        L{AboutTagValue} doesn't have an associated L{TagValue}.
        """
        object1 = uuid4()
        object2 = uuid4()
        aboutTagValue1 = createAboutTagValue(object1, u'Test object 1')
        aboutTagValue2 = createAboutTagValue(object2, u'Test object 2')
        createTagValue(self.superuser.id, self.aboutTag.id, object2,
                       u'Test object 2')

        self.checker.check([aboutTagValue1, aboutTagValue2])
        self.assertEqual(
            'Integrity Error in object %s: '
            "AboutTagValue doesn't have an associated TagValue.\n" % object1,
            self.log.getvalue())
コード例 #28
0
    def testAboutValueWithoutAboutTagValue(self):
        """
        L{TagValueIntegrityChecker.check} logs an error if a given L{TagValue}
        for fluiddb/about doesn't have an associated L{AboutTagValue} row.
        """
        tag = self.system.tags[u'fluiddb/about']
        tagValue1 = createTagValue(self.superuser.id, tag.id, uuid4(),
                                   u'Test object 1')
        tagValue2 = createTagValue(self.superuser.id, tag.id, uuid4(),
                                   u'Test object 2')
        createAboutTagValue(tagValue2.objectID, u'Test object 2')

        self.checker.check([tagValue1, tagValue2])
        self.assertEqual(
            'Integrity Error in object %s: '
            "fluiddb/about TagValue doesn't have an associated "
            'AboutTagValue.\n' % tagValue1.objectID, self.log.getvalue())
コード例 #29
0
ファイル: test_object.py プロジェクト: xanixon/fluiddb
    def testGetTagsByObjects(self):
        """
        L{ObjectAPI.getTagsByObjects} returns a C{dict} of L{Tag.path}s that
        are associated with the given objects.
        """
        tag1 = createTag(self.user, self.user.namespace, u'tag1')
        tag2 = createTag(self.user, self.user.namespace, u'tag2')
        createTagPermission(tag1)
        createTagPermission(tag2)
        objectID = uuid4()
        createTagValue(self.user.id, tag1.id, objectID, u'value1')
        createTagValue(self.user.id, tag2.id, objectID, u'value2')

        tagPaths = self.objects.getTagsByObjects([objectID])
        expected = {objectID: [u'user/tag1', u'user/tag2']}
        tagPaths[objectID] = sorted(tagPaths[objectID])
        self.assertEqual(expected, tagPaths)
コード例 #30
0
ファイル: test_object.py プロジェクト: fluidinfo/fluiddb
    def testGetTagsByObjects(self):
        """
        L{ObjectAPI.getTagsByObjects} returns a C{dict} of L{Tag.path}s that
        are associated with the given objects.
        """
        tag1 = createTag(self.user, self.user.namespace, u'tag1')
        tag2 = createTag(self.user, self.user.namespace, u'tag2')
        createTagPermission(tag1)
        createTagPermission(tag2)
        objectID = uuid4()
        createTagValue(self.user.id, tag1.id, objectID, u'value1')
        createTagValue(self.user.id, tag2.id, objectID, u'value2')

        tagPaths = self.objects.getTagsByObjects([objectID])
        expected = {objectID: [u'user/tag1', u'user/tag2']}
        tagPaths[objectID] = sorted(tagPaths[objectID])
        self.assertEqual(expected, tagPaths)
コード例 #31
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
    def testAboutValueWithoutAboutTagValue(self):
        """
        L{TagValueIntegrityChecker.check} logs an error if a given L{TagValue}
        for fluiddb/about doesn't have an associated L{AboutTagValue} row.
        """
        tag = self.system.tags[u'fluiddb/about']
        tagValue1 = createTagValue(self.superuser.id, tag.id, uuid4(),
                                   u'Test object 1')
        tagValue2 = createTagValue(self.superuser.id, tag.id, uuid4(),
                                   u'Test object 2')
        createAboutTagValue(tagValue2.objectID, u'Test object 2')

        self.checker.check([tagValue1, tagValue2])
        self.assertEqual('Integrity Error in object %s: '
                         "fluiddb/about TagValue doesn't have an associated "
                         'AboutTagValue.\n' % tagValue1.objectID,
                         self.log.getvalue())
コード例 #32
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
    def testTagDescriptionValueWithoutNamespace(self):
        """
        L{TagValueIntegrityChecker.check} logs an error if a given L{TagValue}
        for fluiddb/tags/description doesn't have an associated L{Tag} row.
        """
        tag = self.system.tags[u'fluiddb/tags/description']
        tagValue1 = createTagValue(self.superuser.id, tag.id, uuid4(),
                                   u'Lonely Description')
        tag = createTag(self.user, self.parent, u'tag')
        tagValue2 = createTagValue(self.superuser.id, tag.id, tag.objectID,
                                   u'Description')

        self.checker.check([tagValue1, tagValue2])
        self.assertEqual('Integrity Error in object %s: '
                         "fluiddb/tags/description TagValue doesn't have"
                         ' an associated Tag.\n' % tagValue1.objectID,
                         self.log.getvalue())
コード例 #33
0
    def testTagDescriptionValueWithoutNamespace(self):
        """
        L{TagValueIntegrityChecker.check} logs an error if a given L{TagValue}
        for fluiddb/tags/description doesn't have an associated L{Tag} row.
        """
        tag = self.system.tags[u'fluiddb/tags/description']
        tagValue1 = createTagValue(self.superuser.id, tag.id, uuid4(),
                                   u'Lonely Description')
        tag = createTag(self.user, self.parent, u'tag')
        tagValue2 = createTagValue(self.superuser.id, tag.id, tag.objectID,
                                   u'Description')

        self.checker.check([tagValue1, tagValue2])
        self.assertEqual(
            'Integrity Error in object %s: '
            "fluiddb/tags/description TagValue doesn't have"
            ' an associated Tag.\n' % tagValue1.objectID, self.log.getvalue())
コード例 #34
0
ファイル: test_index.py プロジェクト: fluidinfo/fluiddb
 def testBuildIndex(self):
     """
     L{buildIndex} creates documents for all tags values in the main store.
     """
     user = createUser(u'username', u'secret', u'User', u'*****@*****.**')
     namespace = createNamespace(user, u'username', None)
     tag = createTag(user, namespace, u'tag')
     objectID1 = uuid4()
     objectID2 = uuid4()
     createTagValue(user.id, tag.id, objectID1, 42)
     createTagValue(user.id, tag.id, objectID2, 65)
     with open(os.devnull, 'w') as stream:
         yield buildIndex(self.client.url, stream=stream)
     response = yield self.client.search('*:*')
     self.assertEqual(sorted([{u'fluiddb/id': str(objectID1)},
                              {u'fluiddb/id': str(objectID2)}]),
                      sorted(response.results.docs))
コード例 #35
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
    def testAboutTagValueWithoutValue(self):
        """
        L{AboutTagValueIntegrityChecker.check} logs an error if the given
        L{AboutTagValue} doesn't have an associated L{TagValue}.
        """
        object1 = uuid4()
        object2 = uuid4()
        aboutTagValue1 = createAboutTagValue(object1, u'Test object 1')
        aboutTagValue2 = createAboutTagValue(object2, u'Test object 2')
        createTagValue(self.superuser.id, self.aboutTag.id, object2,
                       u'Test object 2')

        self.checker.check([aboutTagValue1, aboutTagValue2])
        self.assertEqual('Integrity Error in object %s: '
                         "AboutTagValue doesn't have an associated TagValue.\n"
                         % object1,
                         self.log.getvalue())
コード例 #36
0
ファイル: test_index.py プロジェクト: fluidinfo/fluiddb
 def testUpdateIndex(self):
     """
     L{updateIndex} creates documents for all tag-values in the main store
     that have been modified since the given C{datetime}.
     """
     user = createUser(u'username', u'secret', u'User', u'*****@*****.**')
     namespace = createNamespace(user, u'username', None)
     tag = createTag(user, namespace, u'tag')
     objectID = uuid4()
     value = createTagValue(user.id, tag.id, uuid4(), 42)
     value.creationTime = datetime.utcnow() - timedelta(days=2)
     createTagValue(user.id, tag.id, objectID, 65)
     createdAfterTime = datetime.utcnow() - timedelta(days=1)
     with open(os.devnull, 'w') as stream:
         yield updateIndex(self.client.url, createdAfterTime, stream=stream)
     response = yield self.client.search('*:*')
     self.assertEqual([{u'fluiddb/id': str(objectID)}],
                      response.results.docs)
コード例 #37
0
ファイル: test_object.py プロジェクト: fluidinfo/fluiddb
 def testGetObjectWithAboutValueDoesNotExist(self):
     """
     L{FacadeObjectAPI.getObject} returns a L{TObjectInfo} with the
     L{Tag.path}s for which the L{User} has L{Operation.READ_TAG_VALUE},
     and the L{AboutTagValue.value} if it has one and C{showAbout} is
     C{True}.
     """
     objectID = uuid4()
     tag = createTag(self.user, self.user.namespace, u'foo')
     createTagPermission(tag)
     createTagValue(self.user.id, tag.id, objectID, u'bar')
     session = AuthenticatedSession(self.user.username, uuid4())
     self.store.commit()
     with login(self.user.username, uuid4(), self.transact) as session:
         objectInfo = yield self.facade.getObject(session, str(objectID),
                                                  showAbout=True)
         self.assertEqual([u'username/foo'], objectInfo.tagPaths)
         self.assertIdentical(None, objectInfo.about)
コード例 #38
0
ファイル: test_object.py プロジェクト: xanixon/fluiddb
 def testGetObjectWithAboutValueDoesNotExist(self):
     """
     L{FacadeObjectAPI.getObject} returns a L{TObjectInfo} with the
     L{Tag.path}s for which the L{User} has L{Operation.READ_TAG_VALUE},
     and the L{AboutTagValue.value} if it has one and C{showAbout} is
     C{True}.
     """
     objectID = uuid4()
     tag = createTag(self.user, self.user.namespace, u'foo')
     createTagPermission(tag)
     createTagValue(self.user.id, tag.id, objectID, u'bar')
     session = AuthenticatedSession(self.user.username, uuid4())
     self.store.commit()
     with login(self.user.username, uuid4(), self.transact) as session:
         objectInfo = yield self.facade.getObject(session,
                                                  str(objectID),
                                                  showAbout=True)
         self.assertEqual([u'username/foo'], objectInfo.tagPaths)
         self.assertIdentical(None, objectInfo.about)
コード例 #39
0
 def testDeleteRemovesTagValues(self):
     """
     L{TagValueAPI.delete} removes L{TagValue}s associated with the deleted
     L{Tag}s.
     """
     objectID = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag1 = createTag(self.user, namespace, u'tag1')
     tag2 = createTag(self.user, namespace, u'tag2')
     createTagPermission(tag1)
     createTagPermission(tag2)
     value = createTagValue(self.user.id, tag1.id, objectID, 42)
     createTagValue(self.user.id, tag2.id, objectID, 17)
     self.tagValues.delete([(objectID, u'name/tag2')])
     values = self.store.find(TagValue, TagValue.tagID == Tag.id,
                              Not(Tag.path.is_in(self.system.tags)))
     self.assertEqual([value], list(values))
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
コード例 #40
0
    def testAboutTagValueWithWrongValue(self):
        """
        L{AboutTagValueIntegrityChecker.check} logs an error if the given
        L{AboutTagValue} and its L{TagValue} dont match.
        """
        object1 = uuid4()
        object2 = uuid4()
        aboutTagValue1 = createAboutTagValue(object1, u'Test object 1')
        createTagValue(self.superuser.id, self.aboutTag.id, object1,
                       u'Wrong tag value')
        aboutTagValue2 = createAboutTagValue(object2, u'Test object 2')
        createTagValue(self.superuser.id, self.aboutTag.id, object2,
                       u'Test object 2')

        self.checker.check([aboutTagValue1, aboutTagValue2])
        self.assertEqual(
            'Integrity Error in object %s: '
            "AboutTagValue doesn't match its TagValue.\n" % object1,
            self.log.getvalue())
コード例 #41
0
ファイル: test_value.py プロジェクト: fluidinfo/fluiddb
 def testDeleteRemovesTagValues(self):
     """
     L{TagValueAPI.delete} removes L{TagValue}s associated with the deleted
     L{Tag}s.
     """
     objectID = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag1 = createTag(self.user, namespace, u'tag1')
     tag2 = createTag(self.user, namespace, u'tag2')
     createTagPermission(tag1)
     createTagPermission(tag2)
     value = createTagValue(self.user.id, tag1.id, objectID, 42)
     createTagValue(self.user.id, tag2.id, objectID, 17)
     self.tagValues.delete([(objectID, u'name/tag2')])
     values = self.store.find(TagValue, TagValue.tagID == Tag.id,
                              Not(Tag.path.is_in(self.system.tags)))
     self.assertEqual([value], list(values))
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
コード例 #42
0
ファイル: test_value.py プロジェクト: fluidinfo/fluiddb
 def testDeleteOnlyConsidersSpecifiedObjectIDs(self):
     """
     L{TagValueAPI.delete} only removes the values for the specified object
     IDs.
     """
     objectID1 = uuid4()
     objectID2 = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     createTagValue(self.user.id, tag.id, objectID1, 42)
     value = createTagValue(self.user.id, tag.id, objectID2, 17)
     self.tagValues.delete([(objectID1, u'name/tag')])
     values = self.store.find(TagValue, TagValue.tagID == Tag.id,
                              Not(Tag.path.is_in(self.system.tags)))
     self.assertEqual([value], list(values))
     self.assertIn(objectID1,
                   getDirtyObjects().values(DirtyObject.objectID))
コード例 #43
0
 def testDeleteOnlyConsidersSpecifiedObjectIDs(self):
     """
     L{TagValueAPI.delete} only removes the values for the specified object
     IDs.
     """
     objectID1 = uuid4()
     objectID2 = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     createTagValue(self.user.id, tag.id, objectID1, 42)
     value = createTagValue(self.user.id, tag.id, objectID2, 17)
     self.tagValues.delete([(objectID1, u'name/tag')])
     values = self.store.find(TagValue, TagValue.tagID == Tag.id,
                              Not(Tag.path.is_in(self.system.tags)))
     self.assertEqual([value], list(values))
     self.assertIn(objectID1,
                   getDirtyObjects().values(DirtyObject.objectID))
コード例 #44
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
    def testNamespacePathValueWithoutNamespace(self):
        """
        L{TagValueIntegrityChecker.check} logs an error if a given L{TagValue}
        for fluiddb/namespaces/path doesn't have an associated L{Namespace}
        row.
        """
        tag = self.system.tags[u'fluiddb/namespaces/path']
        tagValue1 = createTagValue(self.superuser.id, tag.id, uuid4(),
                                   u'missing/namespace')
        namespace = createNamespace(self.user, u'user/namesace',
                                    self.user.namespaceID)
        tagValue2 = createTagValue(self.superuser.id, tag.id,
                                   namespace.objectID, u'user/namespace')

        self.checker.check([tagValue1, tagValue2])
        self.assertEqual('Integrity Error in object %s: '
                         "fluiddb/namespaces/path TagValue doesn't have an "
                         'associated Namespace.\n' % tagValue1.objectID,
                         self.log.getvalue())
コード例 #45
0
ファイル: test_index.py プロジェクト: xanixon/fluiddb
 def testUpdateIndex(self):
     """
     L{updateIndex} creates documents for all tag-values in the main store
     that have been modified since the given C{datetime}.
     """
     user = createUser(u'username', u'secret', u'User', u'*****@*****.**')
     namespace = createNamespace(user, u'username', None)
     tag = createTag(user, namespace, u'tag')
     objectID = uuid4()
     value = createTagValue(user.id, tag.id, uuid4(), 42)
     value.creationTime = datetime.utcnow() - timedelta(days=2)
     createTagValue(user.id, tag.id, objectID, 65)
     createdAfterTime = datetime.utcnow() - timedelta(days=1)
     with open(os.devnull, 'w') as stream:
         yield updateIndex(self.client.url, createdAfterTime, stream=stream)
     response = yield self.client.search('*:*')
     self.assertEqual([{
         u'fluiddb/id': str(objectID)
     }], response.results.docs)
コード例 #46
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
    def testAboutTagValueWithWrongValue(self):
        """
        L{AboutTagValueIntegrityChecker.check} logs an error if the given
        L{AboutTagValue} and its L{TagValue} dont match.
        """
        object1 = uuid4()
        object2 = uuid4()
        aboutTagValue1 = createAboutTagValue(object1, u'Test object 1')
        createTagValue(self.superuser.id, self.aboutTag.id, object1,
                       u'Wrong tag value')
        aboutTagValue2 = createAboutTagValue(object2, u'Test object 2')
        createTagValue(self.superuser.id, self.aboutTag.id, object2,
                       u'Test object 2')

        self.checker.check([aboutTagValue1, aboutTagValue2])
        self.assertEqual('Integrity Error in object %s: '
                         "AboutTagValue doesn't match its TagValue.\n"
                         % object1,
                         self.log.getvalue())
コード例 #47
0
ファイル: test_value.py プロジェクト: xanixon/fluiddb
 def testCreateOpaqueValueWithSameContent(self):
     """
     L{createOpaqueValue} doesn't create duplicate L{OpaqueValue}s if the
     content is the same.
     """
     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 = createTagValue(user.id, tag.id, uuid4(), None)
     value2 = createTagValue(user.id, tag.id, uuid4(), None)
     self.store.commit()
     createOpaqueValue(value1.id, 'content')
     createOpaqueValue(value2.id, 'content')
     fileID = sha256('content').hexdigest()
     result = self.store.find(OpaqueValue, OpaqueValue.fileID == fileID)
     self.assertNotIdentical(None, result.one())
     result = self.store.find(OpaqueValueLink,
                              OpaqueValueLink.fileID == fileID)
     self.assertEqual(2, result.count())
コード例 #48
0
    def testNamespacePathValueWithoutNamespace(self):
        """
        L{TagValueIntegrityChecker.check} logs an error if a given L{TagValue}
        for fluiddb/namespaces/path doesn't have an associated L{Namespace}
        row.
        """
        tag = self.system.tags[u'fluiddb/namespaces/path']
        tagValue1 = createTagValue(self.superuser.id, tag.id, uuid4(),
                                   u'missing/namespace')
        namespace = createNamespace(self.user, u'user/namesace',
                                    self.user.namespaceID)
        tagValue2 = createTagValue(self.superuser.id, tag.id,
                                   namespace.objectID, u'user/namespace')

        self.checker.check([tagValue1, tagValue2])
        self.assertEqual(
            'Integrity Error in object %s: '
            "fluiddb/namespaces/path TagValue doesn't have an "
            'associated Namespace.\n' % tagValue1.objectID,
            self.log.getvalue())
コード例 #49
0
ファイル: test_index.py プロジェクト: xanixon/fluiddb
 def testBuildIndex(self):
     """
     L{buildIndex} creates documents for all tags values in the main store.
     """
     user = createUser(u'username', u'secret', u'User', u'*****@*****.**')
     namespace = createNamespace(user, u'username', None)
     tag = createTag(user, namespace, u'tag')
     objectID1 = uuid4()
     objectID2 = uuid4()
     createTagValue(user.id, tag.id, objectID1, 42)
     createTagValue(user.id, tag.id, objectID2, 65)
     with open(os.devnull, 'w') as stream:
         yield buildIndex(self.client.url, stream=stream)
     response = yield self.client.search('*:*')
     self.assertEqual(
         sorted([{
             u'fluiddb/id': str(objectID1)
         }, {
             u'fluiddb/id': str(objectID2)
         }]), sorted(response.results.docs))
コード例 #50
0
ファイル: test_value.py プロジェクト: xanixon/fluiddb
 def testCreateTagValue(self):
     """L{createTagValue} creates a new L{TagValue}."""
     objectID = uuid4()
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     tag = createTag(user, user.namespace, u'name')
     value = createTagValue(user.id, tag.id, objectID, 42)
     self.assertIdentical(user, value.creator)
     self.assertEqual(tag, value.tag)
     self.assertEqual(objectID, value.objectID)
     self.assertEqual(42, value.value)
コード例 #51
0
ファイル: test_value.py プロジェクト: xanixon/fluiddb
 def testCreateTagValueAddsToDatabase(self):
     """
     L{createTagValue} automatically adds the new L{TagValue} to the
     database.
     """
     objectID = uuid4()
     user = createUser(u'username', u'password', u'User',
                       u'*****@*****.**')
     user.namespaceID = createNamespace(user, user.username, None).id
     tag = createTag(user, user.namespace, u'name')
     value = createTagValue(user.id, tag.id, objectID, 42)
     self.assertIdentical(value, self.store.find(TagValue).one())
コード例 #52
0
ファイル: test_value.py プロジェクト: fluidinfo/fluiddb
 def testDeleteRemovesTagValuesWhenPassedAGenerator(self):
     """
     L{TagValueAPI.delete} removes L{TagValue}s associated with the
     deleted L{Tag}s when it is passed a generator (as opposed to a
     C{list}).
     """
     objectID = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag1 = createTag(self.user, namespace, u'tag1')
     tag2 = createTag(self.user, namespace, u'tag2')
     createTagPermission(tag1)
     createTagPermission(tag2)
     value = createTagValue(self.user.id, tag1.id, objectID, 42)
     createTagValue(self.user.id, tag2.id, objectID, 17)
     values = ((objectID, name) for name in [u'name/tag2'])
     self.tagValues.delete(values)
     values = self.store.find(TagValue, TagValue.tagID == Tag.id,
                              Not(Tag.path.is_in(self.system.tags)))
     self.assertEqual([value], list(values))
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
コード例 #53
0
ファイル: test_object.py プロジェクト: fluidinfo/fluiddb
    def testGetObjectWithAboutValue(self):
        """
        L{FacadeObjectAPI.getObject} returns a L{TObjectInfo} with the
        L{Tag.path}s for which the L{User} has L{Operation.READ_TAG_VALUE},
        and the L{AboutTagValue.value} if it has one and C{showAbout} is
        C{True}.
        """
        objectID = uuid4()
        SecureTagAPI(self.user).create([(u'username/foo', u'A description')])
        values = {objectID: {u'username/foo': u'bar'}}
        SecureTagValueAPI(self.user).set(values)
        aboutTag = self.system.tags[u'fluiddb/about']
        createAboutTagValue(objectID, u'bar')
        createTagValue(self.user.id, aboutTag.id, objectID, u'about value')
        self.store.commit()

        with login(self.user.username, uuid4(), self.transact) as session:
            objectInfo = yield self.facade.getObject(session, str(objectID),
                                                     showAbout=True)
            self.assertEqual([u'fluiddb/about', u'username/foo'],
                             sorted(objectInfo.tagPaths))
            self.assertEqual('about value', objectInfo.about)
コード例 #54
0
ファイル: test_index.py プロジェクト: fluidinfo/fluiddb
    def testBatchIndexTouchesTheGivenNumberOfObjectsPerInterval(self):
        """
        C{batchIndex} touches only the max number of objects permited on each
        interval acording to the interval parameter.
        """
        createTagValue(self.userID, self.tagID, uuid4(), 10)
        createTagValue(self.userID, self.tagID, uuid4(), 20)
        createTagValue(self.userID, self.tagID, uuid4(), 30)
        createTagValue(self.userID, self.tagID, uuid4(), 40)
        createTagValue(self.userID, self.tagID, uuid4(), 50)
        self.createObjectsFile()

        self.expectedTouchedObjects = 1

        def fakeSleep(seconds):
            self.assertEqual(10 * 60, seconds)
            self.assertEqual(self.expectedTouchedObjects,
                             getDirtyObjects().count())
            self.expectedTouchedObjects += 1

        # index objects one every ten seconds
        batchIndex(self.objectsFilename, 10, 1, sleepFunction=fakeSleep)
コード例 #55
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
    def testEmailValueWithoutUser(self):
        """
        L{TagValueIntegrityChecker.check} logs an error if a given L{TagValue}
        for fluiddb/users/email doesn't have an associated L{User} row.
        """
        tag = self.system.tags[u'fluiddb/users/email']
        tagValue1 = createTagValue(self.superuser.id, tag.id, uuid4(),
                                   u'*****@*****.**')
        tagValue2 = getTagValues([(self.superuser.objectID, tag.id)]).one()

        self.checker.check([tagValue1, tagValue2])
        self.assertEqual('Integrity Error in object %s: '
                         "fluiddb/users/email TagValue doesn't have "
                         'an associated User.\n' % tagValue1.objectID,
                         self.log.getvalue())
コード例 #56
0
    def makeValue(self, user, tag, objectID, value, delay):
        """
        Helper function used to create a tag value with a given delay in its
        L{TagValue.creationTime}.

        @param user: The L{User} creator of the value.
        @param tag: The L{Tag} for the value.
        @param objectID: The object ID for the value.
        @param value: The value for the tag value.
        @param delay: The delay in seconds for the L{TagValue.creationTime}
            field.
        @return: The {TagValue.creationTime} field of the value.
        """
        value = createTagValue(user.id, tag.id, objectID, value)
        value.creationTime = datetime.now() - timedelta(days=delay)
        return value.creationTime
コード例 #57
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
    def createTestUser(self, username):
        """
        Create a test L{User} using low level functions to avoid integrity
        checks made by high level ones.

        @param username: The username of the new L{User}.
        @return: A L{User} instance.
        """
        user = User(username, 'hash', u'Name', u'*****@*****.**', Role.USER)
        namespace = Namespace(user, username, username)
        self.store.add(user)
        self.store.add(namespace)
        user.namespaceID = namespace.id
        createTagValue(user.id, self.usernameTag.id, user.objectID, username)
        createTagValue(user.id, self.nameTag.id, user.objectID, u'Name')
        createTagValue(user.id, self.emailTag.id, user.objectID,
                       u'*****@*****.**')
        createTagValue(user.id, self.aboutTag.id, user.objectID,
                       u'@%s' % username)
        return user
コード例 #58
0
ファイル: test_value.py プロジェクト: fluidinfo/fluiddb
 def testGetFilteredByObjectIDsAndPath(self):
     """
     When both object IDs and tag paths are provided, L{TagValueAPI.get}
     returns only those L{Tag} values that meet both criteria.
     """
     objectID1 = uuid4()
     objectID2 = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag1 = createTag(self.user, namespace, u'tag1')
     tag2 = createTag(self.user, namespace, u'tag2')
     createTagPermission(tag1)
     createTagPermission(tag2)
     createTagValue(self.user.id, tag1.id, objectID1, 42)
     createTagValue(self.user.id, tag1.id, objectID2, 67)
     createTagValue(self.user.id, tag2.id, objectID1, 17)
     createTagValue(self.user.id, tag2.id, objectID2, 13)
     result = self.tagValues.get(objectIDs=[objectID1],
                                 paths=[u'name/tag1'])
     self.assertEqual(42, result[objectID1][u'name/tag1'].value)
コード例 #59
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
    def testMissingPermissions(self):
        """
        L{NamespaceIntegrityChecker.check} logs an error if the given
        L{Namespace} doesn't have the required L{NamespacePermission} entries.
        """
        test = createNamespace(self.user.id, u'user/test', self.parent.id)
        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': "
                         'Permissions row is missing.\n',
                         self.log.getvalue())
コード例 #60
0
ファイル: test_checker.py プロジェクト: fluidinfo/fluiddb
    def testMissingPermissions(self):
        """
        L{TagIntegrityChecker.check} logs an error if the given L{Tag} doesn't
        have the required L{TagPermission}.
        """
        test = createTag(self.user, self.parent, u'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 attribute %s' % test.path)

        self.checker.check([test])
        self.assertEqual("Integrity Error in tag u'user/test': "
                         'Permissions row is missing.\n',
                         self.log.getvalue())