def setUp(self): super(DataImportHandlerTest, self).setUp() createSystemData() UserAPI().create([(u'user', u'secret', u'User', u'*****@*****.**')]) self.user = getUser(u'user') self.objects = ObjectAPI(self.user) self.values = TagValueAPI(self.user) self.index = ObjectIndex(self.client)
def setUp(self): super(FluidinfoGlobalTrendingHashtagTest, self).setUp() createSystemData() UserAPI().create([ (u'username', u'password', u'User', u'*****@*****.**'), (u'fluidinfo.com', u'secret', u'Fluidinfo', u'*****@*****.**')]) self.user = getUser(u'username') self.comments = CommentAPI(self.user) objectAPI = ObjectAPI(self.user) self.fluidinfObjectID = objectAPI.create(u'fluidinfo.com') self.tag = u'fluidinfo.com/trending-hashtags'
def setUp(self): super(FluidinfoGlobalTrendingHashtagTest, self).setUp() createSystemData() UserAPI().create([ (u'username', u'password', u'User', u'*****@*****.**'), (u'fluidinfo.com', u'secret', u'Fluidinfo', u'*****@*****.**') ]) self.user = getUser(u'username') self.comments = CommentAPI(self.user) objectAPI = ObjectAPI(self.user) self.fluidinfObjectID = objectAPI.create(u'fluidinfo.com') self.tag = u'fluidinfo.com/trending-hashtags'
def setVersionTag(version): """Updates the fluiddb/version tag. @param version: The new version string. """ user = getUser(u'fluiddb') objectID = ObjectAPI(user).create(u'fluidinfo') releaseDate = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') values = { objectID: { u'fluiddb/api-version': { 'mime-type': 'text/plain', 'contents': version }, u'fluiddb/release-date': { 'mime-type': 'text/plain', 'contents': releaseDate + '\n' } } } TagValueAPI(user).set(values) PermissionAPI(user).set([ (u'fluiddb/api-version', Operation.READ_TAG_VALUE, Policy.OPEN, []), (u'fluiddb/release-date', Operation.READ_TAG_VALUE, Policy.OPEN, []) ]) try: transaction.commit() except: transaction.abort() raise
def testRenderRecentUsersActivity(self): """ L{RecentUsersActivityResource.deferred_render_GET} renders a response with recent activity data by the users returned by the given query. """ objectID = ObjectAPI(self.user).create(u'object1') self.store.commit() TagValueAPI(self.user).set({objectID: {u'username/tag1': u'A'}}) runDataImportHandler(self.client.url) request = FakeRequest( args={'query': ['fluiddb/users/username = "******"']}) with login(u'username', self.user.objectID, self.transact) as session: resource = RecentUsersActivityResource(self.facade, session) body = yield resource.deferred_render_GET(request) body = json.loads(body) expected = [{ u'about': u'object1', u'id': str(objectID), u'tag': u'username/tag1', u'username': u'username', u'value': u'A' }] # Clean up timestamps. for item in body: del item['updated-at'] self.assertEqual(expected, body) self.assertEqual(http.OK, request.code)
def testRenderRecentUserActivity(self): """ L{RecentUserActivityResource.deferred_render_GET} renders a response with recent activity data for the given user. """ objectID = ObjectAPI(self.user).create(u'object1') TagValueAPI(self.user).set({objectID: {u'username/tag1': u'A'}}) self.store.commit() TagValueAPI(self.user).set({objectID: {u'username/tag2': u'B'}}) self.store.commit() request = FakeRequest() with login(u'username', self.user.objectID, self.transact) as session: resource = RecentUserActivityResource(self.facade, session, u'username') body = yield resource.deferred_render_GET(request) body = json.loads(body) expected = [{ u'username': u'username', u'about': u'object1', u'id': str(objectID), u'tag': u'username/tag2', u'value': u'B' }, { u'username': u'username', u'about': u'object1', u'id': str(objectID), u'tag': u'username/tag1', u'value': u'A' }] # Clean up timestamps. for item in body: del item['updated-at'] self.assertEqual(expected, body) self.assertEqual(http.OK, request.code)
def getObjectAPI(self, user): """Get an L{ObjectAPI} instance for the specified user. @param user: The L{User} to configure the L{ObjectAPI} instance. @return: An L{ObjectAPI} instance. """ return ObjectAPI(user)
class CachingObjectAPI(object): """The public API to cached object-related functionality. @param user: The L{User} to perform operations on behalf of. """ def __init__(self, user): self._api = ObjectAPI(user, factory=CachingAPIFactory()) self._cache = ObjectCache() self._user = user def create(self, value=None): """See L{ObjectAPI.create}.""" return self._api.create(value) def get(self, values): """Get object IDs matching C{fluiddb/about} tag values. Values will be fetched from the cache if they are available, otherwise they will be fetched directly from the data base. See L{ObjectAPI.get} for more details. """ cached = self._cache.get(values) if cached.uncachedValues: result = self._api.get(cached.uncachedValues) if result: self._cache.save(result) cached.results.update(result) return cached.results def getTagsByObjects(self, objectIDs): """See L{ObjectAPI.getTagsByObjects}.""" return self._api.getTagsByObjects(objectIDs) def getTagsForObjects(self, objectIDs): """See L{ObjectAPI.getTagsForObjects}.""" return self._api.getTagsForObjects(objectIDs) def search(self, queries, implicitCreate=True): """See L{ObjectAPI.search}.""" return self._api.search(queries, implicitCreate)
def testGetRecentAboutActivity(self): """ L{FacadeRecentActivityMixin.getRecentAboutActivity} returns a C{dict} with information about the recent tag values on the given object. """ tagValues = TagValueAPI(self.user) objectID1 = ObjectAPI(self.user).create(u'object1') objectID2 = uuid4() # Use commit() frequently to have different timestamps on each value. self.store.commit() tagValues.set({objectID1: {u'user/tag1': u'A'}}) self.store.commit() tagValues.set({objectID1: {u'user/tag2': u'B'}}) self.store.commit() tagValues.set({objectID2: {u'user/tag1': u'C'}}) self.store.commit() tagValues.set({objectID2: {u'user/tag2': u'D'}}) self.store.commit() tagValues.set({uuid4(): {u'user/tag1': u'E'}}) self.store.commit() tagValues.set({uuid4(): {u'user/tag2': u'F'}}) self.store.commit() expected = [ {'tag': u'user/tag2', 'id': str(objectID1), 'about': u'object1', 'value': u'B', 'username': u'username'}, {'tag': u'user/tag1', 'id': str(objectID1), 'about': u'object1', 'value': u'A', 'username': u'username'}, {'tag': u'fluiddb/about', 'id': str(objectID1), 'about': u'object1', 'value': u'object1', 'username': u'fluiddb'}] with login(self.user.username, uuid4(), self.transact) as session: result = yield self.facade.getRecentAboutActivity( session, 'object1') # Remove the creation times from the result. for item in result: del item['updated-at'] self.assertEqual(expected, result)
def extractTrendingHashtags(store, limit=10, duration=None): """Extract information about trending hashtags and store it in FluidDB. @param store: The storm store to query and to save our result to. @param limit: Optionally, the number of objects to retrieve. @param duration: Optionally, the recent time period to look at when determining which hashtags are trending. Default is 28 days. The storm query below results in SQL like: SELECT COUNT(DISTINCT comments.object_id) AS count, about_tag_values.value, array_agg(ROW(comments.username, comments.creation_time)) FROM about_tag_values, comment_object_link, comments WHERE about_tag_values.value LIKE '#%' AND about_tag_values.object_id = comment_object_link.object_id AND comments.object_id = comment_object_link.comment_id AND comments.creation_time >= '2012-11-09 07:42:40'::TIMESTAMP AND CHAR_LENGTH(about_tag_values.value) >= 2 GROUP BY about_tag_values.value ORDER BY count DESC LIMIT 10 """ duration = timedelta(days=28) if duration is None else duration startTime = datetime.utcnow() - duration count = Alias(Count(Comment.objectID, distinct=True)) result = store.find( (count, AboutTagValue.value, Func('array_agg', Row(Comment.username, Comment.creationTime))), Like(AboutTagValue.value, u'#%'), AboutTagValue.objectID == CommentObjectLink.objectID, Comment.objectID == CommentObjectLink.commentID, Comment.creationTime >= startTime, Func('CHAR_LENGTH', AboutTagValue.value) >= 2) result.group_by(AboutTagValue.value) result.order_by(Desc(count)) result.config(limit=limit) data = [{ 'count': count, 'usernames': _sortUsernames(usernames), 'value': hashtag } for count, hashtag, usernames in result] user = getUser(u'fluidinfo.com') tagValues = TagValueAPI(user) objectID = ObjectAPI(user).create(u'fluidinfo.com') tagValues.set( {objectID: { u'fluidinfo.com/trending-hashtags': json.dumps(data) }}) store.commit()
def testRenderRecentObjectActivityWithNoQuery(self): """ L{RecentUsersActivityResource.deferred_render_GET} raises L{MissingArgument} if the C{query} argument is not given. """ objectID = ObjectAPI(self.user).create(u'object1') self.store.commit() TagValueAPI(self.user).set({objectID: {u'username/tag1': u'A'}}) runDataImportHandler(self.client.url) request = FakeRequest() with login(u'username', self.user.objectID, self.transact) as session: resource = RecentUsersActivityResource(self.facade, session) deferred = resource.deferred_render_GET(request) yield self.assertFailure(deferred, MissingArgument)
def testGetForUsersReturnsOnlyAllowedTags(self): """ L{SecureRecentActivityAPI.getForUser} returns all the tags for the superuser. """ tagValues = TagValueAPI(self.user) objectID1 = ObjectAPI(self.user).create(u'object1') objectID2 = uuid4() # Use commit() frequently to have different timestamps on each value. self.store.commit() tagValues.set({objectID1: {u'user/tag1': u'A'}}) self.store.commit() tagValues.set({objectID1: {u'user/tag2': u'B'}}) self.store.commit() UserAPI().create([(u'user2', u'secret', u'User', u'*****@*****.**')]) tagValues = TagValueAPI(getUser(u'user2')) tagValues.set({objectID1: {u'user2/tag1': u'C'}}) self.store.commit() tagValues.set({objectID2: {u'user2/tag2': u'D'}}) self.store.commit() UserAPI().create([(u'user3', u'secret', u'User', u'*****@*****.**')]) tagValues = TagValueAPI(getUser(u'user3')) tagValues.set({objectID1: {u'user3/tag1': u'C'}}) self.store.commit() tagValues.set({objectID2: {u'user3/tag2': u'D'}}) self.store.commit() self.permissions.set([ (u'user/tag2', Operation.READ_TAG_VALUE, Policy.OPEN, [u'user']), (u'user2/tag2', Operation.READ_TAG_VALUE, Policy.CLOSED, []) ]) expected = [(u'user2/tag2', objectID2, None, u'D', u'user2'), (u'user2/tag1', objectID1, u'object1', u'C', u'user2'), (u'user/tag2', objectID1, u'object1', u'B', u'user'), (u'user/tag1', objectID1, u'object1', u'A', u'user')] result = self.recentActivity.getForUsers([u'user', u'user2']) # Remove the creation times from the result, with the order is enough. result = [(path, objectID, about, value, username) for path, objectID, about, value, username, time in result] self.assertEqual(expected, result)
def testGetForObjectsReturnsOnlyAllowedTags(self): """ L{SecureRecentActivityAPI.getForObjects} will return all the tags for which the user has C{Operation.READ_TAG_VALUE} permissions, but not those for which the user doesn't have. """ tagValues = TagValueAPI(self.user) objectID1 = ObjectAPI(self.user).create(u'object1') objectID2 = uuid4() # Use commit() frequently to have different timestamps on each value. self.store.commit() tagValues.set({objectID1: {u'user/tag1': u'A'}}) self.store.commit() tagValues.set({objectID1: {u'user/tag2': u'B'}}) self.store.commit() tagValues.set({objectID2: {u'user/tag1': u'C'}}) self.store.commit() tagValues.set({objectID2: {u'user/tag2': u'D'}}) self.store.commit() tagValues.set({uuid4(): {u'user/tag1': u'E'}}) self.store.commit() tagValues.set({uuid4(): {u'user/tag2': u'F'}}) self.store.commit() self.permissions.set([(u'user/tag2', Operation.READ_TAG_VALUE, Policy.OPEN, [u'anon'])]) expected = [(u'user/tag1', objectID2, None, u'C', u'user'), (u'user/tag1', objectID1, u'object1', u'A', u'user'), (u'fluiddb/about', objectID1, u'object1', u'object1', u'fluiddb')] result = self.recentActivity.getForObjects([objectID1, objectID2]) # Remove the creation times from the result, with the order is enough. result = [(path, objectID, about, value, username) for path, objectID, about, value, username, time in result] self.assertEqual(expected, result)
def testGetRecentUserActivityForQueryWithObjectsNotUsers(self): """ L{FacadeRecentActivityMixin.getRecentUserActivityForQuery} returns an empty result if the objects returned by the query are not users. """ tagValues = TagValueAPI(self.user) objectID1 = ObjectAPI(self.user).create(u'object1') # Use commit() frequently to have different timestamps on each value. self.store.commit() tagValues.set({objectID1: {u'user/following': u'A'}}) self.store.commit() runDataImportHandler(self.client.url) with login(self.user.username, uuid4(), self.transact) as session: result = yield self.facade.getRecentUserActivityForQuery( session, u'has user/following') # Remove the creation times from the result. for item in result: del item['updated-at'] self.assertEqual([], result)
def testGetRecentActivityForQuery(self): """ L{FacadeRecentActivityMixin.getRecentActivityForQuery} returns a C{dict} with information about the recent tag values on the objects returned by the given query. """ tagValues = TagValueAPI(self.user) objectID1 = ObjectAPI(self.user).create(u'object1') # Use commit() frequently to have different timestamps on each value. self.store.commit() tagValues.set({objectID1: {u'user/following': u'A'}}) self.store.commit() runDataImportHandler(self.client.url) expected = [{'about': u'object1', 'id': str(objectID1), 'tag': u'user/following', 'username': u'username', 'value': u'A'}, {'about': u'object1', 'id': str(objectID1), 'tag': u'fluiddb/about', 'username': u'fluiddb', 'value': u'object1'}] with login(self.user.username, uuid4(), self.transact) as session: result = yield self.facade.getRecentActivityForQuery( session, u'has user/following') # Remove the creation times from the result. for item in result: del item['updated-at'] self.assertEqual(expected, result)
class DataImportHandlerTest(FluidinfoTestCase): resources = [('client', IndexResource()), ('config', ConfigResource()), ('store', DatabaseResource())] def setUp(self): super(DataImportHandlerTest, self).setUp() createSystemData() UserAPI().create([(u'user', u'secret', u'User', u'*****@*****.**')]) self.user = getUser(u'user') self.objects = ObjectAPI(self.user) self.values = TagValueAPI(self.user) self.index = ObjectIndex(self.client) @inlineCallbacks def assertQuery(self, objectIDs, query): """Asserts if a query to fluidinfo returns the expected results. @param objectIDs: A sequence with the expected object IDs for the query. @param query: The fluidinfo query to check. """ query = parseQuery(query) results = yield self.index.search(query) self.assertEqual(set(objectIDs), results) @inlineCallbacks def testImportObjectWithStringValue(self): """The Data Import Handler correctly imports C{string} values.""" objectID = self.objects.create() self.values.set({objectID: {u'user/tag': u'string'}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag = "string"') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithStringValueInvalidXML(self): """ The Data Import Handler correctly imports C{string} values, including those that contain invalid XML characters. """ objectID = self.objects.create() self.values.set({objectID: {u'user/tag': u'foo \uFFFE'}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag = "foo \uFFFE"') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithEmptyStringValue(self): """The Data Import Handler correctly imports empty C{string} values.""" objectID = self.objects.create() self.values.set({objectID: {u'user/tag': u''}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag = ""') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithQuotesValue(self): """ The Data Import Handler correctly imports C{string} values with single quotes. """ objectID = self.objects.create() self.values.set({objectID: {u'user/tag': u'hello\'world'}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag = "hello\'world"') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithDoubleQuotesValue(self): """ The Data Import Handler correctly imports C{string} values with double quotes. """ objectID = self.objects.create() self.values.set({objectID: {u'user/tag': u'hello\"world'}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag = "hello\\\"world"') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithCommaAndParens(self): """ The Data Import Handler correctly imports C{string} values with comma and parens. """ objectID = self.objects.create() self.values.set({objectID: {u'user/tag': u'),'}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag = "),"') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithStringValueWithSpecialCharacters(self): """ The Data Import Handler correctly imports C{string} values with special unicode characters. """ objectID = self.objects.create() self.values.set({objectID: {u'user/tag': u'\xe1\xe9\xed\xf3'}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag = "\xe1\xe9\xed\xf3"') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithListValue(self): """The Data Import Handler correctly imports C{list} values.""" objectID = self.objects.create() self.values.set({objectID: {u'user/tag': [u'one', u'two', u'three']}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag contains "one" ' u'and user/tag contains "two" ' u'and user/tag contains "three"') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithListValueWithSpecialCharacters(self): """ The Data Import Handler correctly imports C{list} values with special unicode characters. """ objectID = self.objects.create() self.values.set({objectID: {u'user/tag': [u'one', u'\xe1\xe9']}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag contains "\xe1\xe9"') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithListValueWithEmptyString(self): """ The Data Import Handler correctly imports C{list} values with an empty string in them. """ objectID = self.objects.create() self.values.set({objectID: {u'user/tag': [u'']}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag contains ""') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithIntValue(self): """The Data Import Handler correctly imports C{int} values.""" objectID = self.objects.create() self.values.set({objectID: {u'user/tag': 5}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag = 5') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithIntSixDigitValue(self): """The Data Import Handler correctly imports C{int} values.""" objectID = self.objects.create() self.values.set({objectID: {u'user/tag': 123456}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag = 123456') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithFloatValue(self): """The Data Import Handler correctly imports C{float} values.""" objectID = self.objects.create() self.values.set({objectID: {u'user/tag': 5.5}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag = 5.5') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithBoolValue(self): """The Data Import Handler correctly imports C{boolean} values.""" objectID = self.objects.create() self.values.set({objectID: {u'user/tag': False}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'user/tag = false') yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithNoneValue(self): """The Data Import Handler correctly imports C{null} values.""" objectID = self.objects.create() self.values.set({objectID: {u'user/tag': None}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithBinaryValue(self): """The Data Import Handler correctly imports C{binary} values.""" objectID = self.objects.create() self.values.set({objectID: { u'user/tag': { 'mime-type': 'text/plain', 'contents': 'file contents'}}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'has user/tag') @inlineCallbacks def testImportObjectWithBinaryValueDoesNotCreateOtherValues(self): """ The Data Import Handler does not import binary tag values as other Solr fields. This is a test for issue #1447. """ objectID = self.objects.create() self.values.set({objectID: { u'user/tag': { 'mime-type': 'text/plain', 'contents': 'file contents'}}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], u'has user/tag') yield self.assertQuery([], u'user/tag = 13') yield self.assertQuery([], u'user/tag = "size"') @inlineCallbacks def testImportObjectWithMultipleValues(self): """The Data Import Handler import documents with multiple values.""" objectID = self.objects.create() self.values.set({objectID: { u'user/tag1': u'string', u'user/tag2': 5, u'user/tag3': 5.5, u'user/tag4': True, u'user/tag5': None, u'user/tag6': { 'mime-type': 'text/plain', 'contents': 'file contents'}}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID], 'user/tag1 = "string" and user/tag2 = 5 ' 'and user/tag3 = 5.5 and user/tag4 = true') yield self.assertQuery([objectID], 'has user/tag1 and has user/tag2 ' 'and has user/tag3 and has user/tag4 ' 'and has user/tag5 and has user/tag6') @inlineCallbacks def testImportMultipleObjects(self): """The Data Import Handler imports multiple objects.""" objectID1 = self.objects.create() objectID2 = self.objects.create() objectID3 = self.objects.create() objectID4 = self.objects.create() self.values.set({objectID1: {u'user/tag1': u'string'}, objectID2: {u'user/tag1': u'string'}, objectID3: {u'user/tag1': 5}, objectID4: {u'user/tag2': True}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID1, objectID2], 'user/tag1 = "string"') yield self.assertQuery([objectID1, objectID2, objectID3], 'has user/tag1') @inlineCallbacks def testImportDeletedObject(self): """The Data Import Handler removes all fields from deleted objects""" objectID1 = self.objects.create() objectID2 = self.objects.create() self.values.set({objectID1: {u'user/tag1': u'string'}, objectID2: {u'user/tag1': u'string'}}) self.values.delete([(objectID1, u'user/tag1')]) runDataImportHandler(self.client.url) yield self.assertQuery([objectID2], 'has user/tag1') yield self.assertQuery([objectID2], 'user/tag1 = "string"') @inlineCallbacks def testImportDeletedAndCreatedAgainObject(self): """ The Data Import Handler correctly imports values deleted and created again. """ objectID1 = self.objects.create() objectID2 = self.objects.create() self.values.set({objectID1: {u'user/tag1': u'string'}, objectID2: {u'user/tag1': u'string'}}) self.values.delete([(objectID1, u'user/tag1')]) self.values.set({objectID1: {u'user/tag1': u'string'}}) runDataImportHandler(self.client.url) yield self.assertQuery([objectID1, objectID2], 'has user/tag1') yield self.assertQuery([objectID1, objectID2], 'user/tag1 = "string"') @inlineCallbacks 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') @inlineCallbacks def testDeltaImportWithDeletedTag(self): """ L{TagValue}s deleted via delete cascade triggered by a L{Tag} deletion should be deleted in the index too. """ objectID = self.objects.create() self.values.set({objectID: {u'user/tag1': u'string', u'user/tag2': u'text'}}) time.sleep(1) runDataImportHandler(self.client.url) tags = TagAPI(self.user) tags.delete([u'user/tag1']) self.store.commit() values = self.values.get([objectID], [u'user/tag1']) self.assertNotIn(u'user/tag1', values[objectID]) runDataImportHandler(self.client.url, clean=False) yield self.assertQuery([], 'has user/tag1') yield self.assertQuery([], 'user/tag1 = "string"')
def __init__(self, user): self._api = ObjectAPI(user, factory=CachingAPIFactory()) self._cache = ObjectCache() self._user = user
def objects(self, user): """Get a new L{ObjectAPI} instance.""" from fluiddb.model.object import ObjectAPI return ObjectAPI(user)
store = setupStore('postgres:///fluidinfo', 'main') setConfig(setupConfig(None)) aboutTag = getTags(paths=[u'fluiddb/about']).one() superUser = getUsers(usernames=[u'fluiddb']).one() result = store.find(AboutTagValue, AboutTagValue.value.like(u'@%')) for aboutValue in result: if aboutValue.value == aboutValue.value.lower(): continue print 'Migrating mixed cased', aboutValue.value.encode('utf-8') newAbout = u'@%s' % aboutValue.value.lower() oldObjectID = aboutValue.objectID newObjectID = ObjectAPI(superUser).create(newAbout) result = store.find(TagValue, TagValue.objectID == oldObjectID, TagValue.tagID != aboutTag.id) for tagValue in result: existingValue = getTagValues([(newObjectID, tagValue.tagID)]).one() if existingValue is not None: error = ('ERROR: Cannot migrate value {path} on {about} ' 'because the value already exist.') print error.format(path=tagValue.tag.path, about=aboutValue.value.encode('utf-8')) else: tagValue.objectID = newObjectID store.commit()
def setUp(self): super(ObjectAPITest, self).setUp() self.system = createSystemData() UserAPI().create([(u'user', u'secret', u'User', u'*****@*****.**')]) self.user = getUser(u'user') self.objects = ObjectAPI(self.user)