def test_aboutTagIndexation(self): """ Create some objects in FluidDB with an about tag and then search in the Solr index to check if the the tags are indexed. """ aboutTags = [u'short', u'longer about description', u'ワンピース'] # First add the objects to FluidDB objectsByAbout = {} for about in aboutTags: obj = yield Object.create(self.fluiddb, about) objectsByAbout[about] = obj.uuid yield self.solr.commit() # Then search the objects in Solr for about in aboutTags: r = yield self.solr.search('path:%s AND value_fts:"%s"' % (self.aboutTag, about)) self.assertTrue(r.results.numFound > 0) # checks that at least one of the returning object ids is one # of the objects we just added self.assertTrue(any(obj['fluiddb/id'] in objectsByAbout.values() for obj in r.results.docs)) defer.returnValue(None)
def test_aboutTagsTermSearch(self): """ Adds some objects to fluidDB with about tags. Then search terms (words) in the about tags. """ aboutTags = [u'One Piece (ワンピース Wan Pīsu?) is a Japanese', u'manga series written and illustrated by Eiichiro Oda', u'that has been serialized in Weekly Shōnen Jump since', u'August 4, 1997. The individual chapters are being', u'published in tankōbon volumes by Shueisha'] # First add the objects to FluidDB objectsByAbout = {} for about in aboutTags: obj = yield Object.create(self.fluiddb, about) objectsByAbout[about] = obj.uuid yield self.solr.commit() # Then search the objects in Solr for about in aboutTags: term = random.choice(about.split()) r = yield self.solr.search('path:%s AND value_fts:"%s"' % (self.aboutTag, term)) self.assertTrue(r.results.numFound > 0) # checks that at least one of the returning object ids is one # of the objects we just added self.assertTrue(any(obj['fluiddb/id'] in objectsByAbout.values() for obj in r.results.docs)) defer.returnValue(None)
def test_AboutTagSearchTerms(self): """ Creates various objects with a phrase as about tag. Then query FluidDB using the "matches" operator on one of the words of the phrase. """ aboutTags = [u'Haruhi Suzumiya (涼宮ハルヒ) is the', u'general name for a series of light novels written', u'by Nagaru Tanigawa and illustrated by Noizi Ito', u'and subsequently adapted into other media. The story', u'follows the title character, Haruhi Suzumiya'] objectsByAbout = {} for about in aboutTags: obj = yield Object.create(self.fluiddb, about) objectsByAbout[about] = obj.uuid # Force Solr Commit yield self.solr.commit() for about in aboutTags: # chose any word of the phrase term = random.choice(about.split()) query = 'fluiddb/about matches "%s"' % term results = yield Object.query(self.fluiddb, query) results = [o.uuid for o in results] self.assertTrue(len(results) > 0) self.assertIn(objectsByAbout[about], results)
def objectByUid(self, uid, screenname=None, userNameCache=None): try: defer.returnValue(Object(self.uidToObjectId[uid])) except KeyError: results = yield Object.query( self.endpoint, '%s = %s' % (ftwitter.idTag.getPath(), uid)) nResults = len(results) if nResults: if nResults > 1: msg = ('User with Twitter id %d exists %d times ' 'in FluidDB! Ignoring.' % (uid, nResults)) log.err(msg) raise Exception(msg) else: o = results[0] self.add(o.uuid, uid, screenname) log.msg('Found FluidDB object for Twitter user %d.' % uid) else: about = '%s:uid:%d' % (TWITTER_USERNAME, uid) o = yield Object.create(self.endpoint, about) if screenname is None: assert userNameCache is not None screenname = yield userNameCache.screennameByUid(uid) log.msg('Made new object for Twitter user %r (uid %d).' % (screenname, uid)) # TODO: what happens if something goes wrong here? yield defer.gatherResults([ o.set(self.endpoint, ftwitter.idTag, int(uid)), o.set(self.endpoint, ftwitter.screennameTag, screenname), ]) log.msg('Set id/created tags on obj for Twitter user %r' % screenname) self.add(o.uuid, uid, screenname) defer.returnValue(o)
def test_aboutTagIndexation(self): """ Create some objects in FluidDB with an about tag and then search in the Solr index to check if the the tags are indexed. """ aboutTags = [u'short', u'longer about description', u'ワンピース'] # First add the objects to FluidDB objectsByAbout = {} for about in aboutTags: obj = yield Object.create(self.fluiddb, about) objectsByAbout[about] = obj.uuid yield self.solr.commit() # Then search the objects in Solr for about in aboutTags: r = yield self.solr.search('path:%s AND value_fts:"%s"' % (self.aboutTag, about)) self.assertTrue(r.results.numFound > 0) # checks that at least one of the returning object ids is one # of the objects we just added self.assertTrue( any(obj['fluiddb/id'] in objectsByAbout.values() for obj in r.results.docs)) defer.returnValue(None)
def testTagValueFromAbout(self): """ A GET on /about/xxx/namespace/tag where xxx is the fluiddb/about tag of an object and namespace/tag is the path of the tag we want to get its value. """ creds = _getCreds() endpoint = Endpoint(self._endpoint, creds=creds) about = 'testTagValueFromAbout' value = 'value' # First, we create an object and attach a tag to it. object = yield Object.create(endpoint, about) tag = Tag(u'fluiddb', u'testing', u'test1') yield object.set(endpoint, tag, value) try: URI = '{endpoint}/about/{value}/{tag}' URI = URI.format(endpoint=self._endpoint, value=about, tag='fluiddb/testing/test1') headers = Headers({'authorization': [creds.encode()]}) agent = Agent(reactor) response = yield agent.request('GET', URI, headers) self.assertEqual(response.code, http.OK) d = defer.Deferred() bodyGetter = ResponseGetter(d) response.deliverBody(bodyGetter) body = yield d self.assertEqual(json.loads(body), value) finally: yield object.delete(endpoint, tag)
def test_AboutTagSearchTerms(self): """ Creates various objects with a phrase as about tag. Then query FluidDB using the "matches" operator on one of the words of the phrase. """ aboutTags = [ u'Haruhi Suzumiya (涼宮ハルヒ) is the', u'general name for a series of light novels written', u'by Nagaru Tanigawa and illustrated by Noizi Ito', u'and subsequently adapted into other media. The story', u'follows the title character, Haruhi Suzumiya' ] objectsByAbout = {} for about in aboutTags: obj = yield Object.create(self.fluiddb, about) objectsByAbout[about] = obj.uuid # Force Solr Commit yield self.solr.commit() for about in aboutTags: # chose any word of the phrase term = random.choice(about.split()) query = 'fluiddb/about matches "%s"' % term results = yield Object.query(self.fluiddb, query) results = [o.uuid for o in results] self.assertTrue(len(results) > 0) self.assertIn(objectsByAbout[about], results)
def test_aboutTagSearch(self): """ Creates a simple object with an about tag and then tries to get the object using a query with the "matches" operator. """ aboutTag = 'description' obj = yield Object.create(self.fluiddb, aboutTag) # force Solr Commit yield self.solr.commit() query = 'fluiddb/about matches "%s"' % aboutTag results = yield Object.query(self.fluiddb, query) results = [o.uuid for o in results] self.assertTrue(len(results) > 0) self.assertIn(obj.uuid, results)
def test_AboutTagComplexSearchQuery(self): """ Creates a simple object with an about tag and then tries to get the object using a composed query (with more than one operator) involving the "matches" operator. """ aboutTag = 'my testing about tag' obj = yield Object.create(self.fluiddb, aboutTag) # force Solr Commit yield self.solr.commit() query = u'has fluiddb/about and fluiddb/about matches "%s"' % aboutTag results = yield Object.query(self.fluiddb, query) results = [o.uuid for o in results] self.assertTrue(len(results) > 0) self.assertIn(obj.uuid, results)
def test_aboutTagsTermSearch(self): """ Adds some objects to fluidDB with about tags. Then search terms (words) in the about tags. """ aboutTags = [ u'One Piece (ワンピース Wan Pīsu?) is a Japanese', u'manga series written and illustrated by Eiichiro Oda', u'that has been serialized in Weekly Shōnen Jump since', u'August 4, 1997. The individual chapters are being', u'published in tankōbon volumes by Shueisha' ] # First add the objects to FluidDB objectsByAbout = {} for about in aboutTags: obj = yield Object.create(self.fluiddb, about) objectsByAbout[about] = obj.uuid yield self.solr.commit() # Then search the objects in Solr for about in aboutTags: term = random.choice(about.split()) r = yield self.solr.search('path:%s AND value_fts:"%s"' % (self.aboutTag, term)) self.assertTrue(r.results.numFound > 0) # checks that at least one of the returning object ids is one # of the objects we just added self.assertTrue( any(obj['fluiddb/id'] in objectsByAbout.values() for obj in r.results.docs)) defer.returnValue(None)