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)
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']))
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'])))
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'])
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'])
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))
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))
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())
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())
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])))
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]))
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]))
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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)
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())
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())
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())
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))
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())
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)
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)
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))
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())
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))
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())
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)
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())
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())
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())
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))
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)
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())
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))
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)
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)
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())
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
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
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)
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())
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())