Exemplo n.º 1
0
    def testDeltaImport(self):
        """
        When using a C{clean=false} option, the Data Import Handler only
        imports values modified since the last run.
        """
        objectID1 = self.objects.create()
        objectID2 = self.objects.create()

        self.values.set({objectID1: {
            u'user/tag1': u'string',
            u'user/tag2': 5,
            u'user/tag3': 5.5}})

        getDirtyObjects().remove()

        self.values.set({objectID2: {
            u'user/tag1': u'string',
            u'user/tag2': 5,
            u'user/tag3': 5.5}})

        runDataImportHandler(self.client.url, clean=False)

        yield self.assertQuery(
            [objectID2], 'has user/tag1 and has user/tag2 and has user/tag3 '
                         'and user/tag1="string" and user/tag2=5 and '
                         'user/tag3=5.5')
Exemplo n.º 2
0
 def testDeleteUpdatesObjectsTagged(self):
     """
     L{TagAPI.delete} updates the objects previously tagged with the given
     paths.
     """
     objectID = uuid4()
     self.tags.create([(u'username/child', u'A description')])
     TagValueAPI(self.user).set({objectID: {u'username/child': 64}})
     getDirtyObjects([objectID]).remove()
     self.tags.delete([u'username/child'])
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
Exemplo n.º 3
0
 def testGetObjects(self):
     """
     L{getDirtyObjects} returns all L{DirtyObject}s in the database, by
     default.
     """
     object1 = createDirtyObject(uuid4())
     self.assertEqual(object1, getDirtyObjects().one())
Exemplo n.º 4
0
 def testGetObjects(self):
     """
     L{getDirtyObjects} returns all L{DirtyObject}s in the database, by
     default.
     """
     object1 = createDirtyObject(uuid4())
     self.assertEqual(object1, getDirtyObjects().one())
Exemplo n.º 5
0
 def testGetObjectsWithObjectIDs(self):
     """
     When L{DirtyObject.objectID}s are provided L{getDirtyObjects} returns
     matching L{DirtyObject}s.
     """
     objectID = uuid4()
     object1 = createDirtyObject(objectID)
     createDirtyObject(uuid4())
     result = getDirtyObjects(objectIDs=[objectID])
     self.assertIdentical(object1, result.one())
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
 def testGetObjectsWithObjectIDs(self):
     """
     When L{DirtyObject.objectID}s are provided L{getDirtyObjects} returns
     matching L{DirtyObject}s.
     """
     objectID = uuid4()
     object1 = createDirtyObject(objectID)
     createDirtyObject(uuid4())
     result = getDirtyObjects(objectIDs=[objectID])
     self.assertIdentical(object1, result.one())
Exemplo n.º 8
0
    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)
Exemplo n.º 9
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))
Exemplo n.º 10
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))
Exemplo n.º 11
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))
Exemplo n.º 12
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))
Exemplo n.º 13
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))
Exemplo n.º 14
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))
Exemplo n.º 15
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))
Exemplo n.º 16
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))
Exemplo n.º 17
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))
Exemplo n.º 18
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))
Exemplo n.º 19
0
 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())
Exemplo n.º 20
0
 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())
Exemplo n.º 21
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))
Exemplo n.º 22
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))
Exemplo n.º 23
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))
Exemplo n.º 24
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))
Exemplo n.º 25
0
 def testSetBinaryValue(self):
     """
     L{TagValueAPI.set} can store binary L{TagValue}s.  The contents
     included in the dict representing the value are written to a file and
     added to the L{FileStore}.
     """
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     objectID = uuid4()
     self.tagValues.set(
         {objectID: {u'name/tag': {'mime-type': 'text/plain',
                                   'contents': 'Hello, world!'}}})
     value = getTagValues([(objectID, tag.id)]).one()
     self.assertEqual(tag.id, value.tagID)
     self.assertEqual(objectID, value.objectID)
     self.assertEqual({'mime-type': 'text/plain',
                       'size': 13},
                      value.value)
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
Exemplo n.º 26
0
 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))
Exemplo n.º 27
0
 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))
Exemplo n.º 28
0
 def testSetBinaryValue(self):
     """
     L{TagValueAPI.set} can store binary L{TagValue}s.  The contents
     included in the dict representing the value are written to a file and
     added to the L{FileStore}.
     """
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     objectID = uuid4()
     self.tagValues.set({
         objectID: {
             u'name/tag': {
                 'mime-type': 'text/plain',
                 'contents': 'Hello, world!'
             }
         }
     })
     value = getTagValues([(objectID, tag.id)]).one()
     self.assertEqual(tag.id, value.tagID)
     self.assertEqual(objectID, value.objectID)
     self.assertEqual({'mime-type': 'text/plain', 'size': 13}, value.value)
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
Exemplo n.º 29
0
 def fakeSleep(seconds):
     self.assertEqual(10 * 60, seconds)
     self.assertEqual(self.expectedTouchedObjects,
                      getDirtyObjects().count())
     self.expectedTouchedObjects += 1
Exemplo n.º 30
0
 def fakeSleep(seconds):
     self.assertEqual(10 * 60, seconds)
     self.assertEqual(self.expectedTouchedObjects,
                      getDirtyObjects().count())
     self.expectedTouchedObjects += 1
Exemplo n.º 31
0
 def testTouchObjects(self):
     """L{touchObjects} adds the objects to the C{dirty_objects} table."""
     objectID = uuid4()
     touchObjects([objectID])
     self.assertNotIdentical(None, getDirtyObjects([objectID]).one())
Exemplo n.º 32
0
 def testTouchObjects(self):
     """L{touchObjects} adds the objects to the C{dirty_objects} table."""
     objectID = uuid4()
     touchObjects([objectID])
     self.assertNotIdentical(None, getDirtyObjects([objectID]).one())