def test_delete(self): id_ = str(uuid.uuid4()) ann = Annotation(id=id_) ann.save() newann = Annotation.get(id_) newann.delete() noann = Annotation.get(id_) assert noann == None
def test_01_text(self): user = {"id": "Alice", "name": "Alice Wonderland"} ann = Annotation(text="Hello there", user=user) ann.ranges.append({}) ann.ranges.append({}) ann.save() ann = Annotation.get(ann.id) assert ann.text == "Hello there", "annotation text wasn't set" assert ann.user['id'] == "Alice", "annotation user wasn't set" assert ann.user['name'] == "Alice Wonderland", "annotation user wasn't set" assert len(ann.ranges) == 2, "ranges weren't added to annotation"
def test_search(self): uri1 = u'http://xyz.com' uri2 = u'urn:uuid:xxxxx' user = u'levin' user2 = u'anna' anno = Annotation(**dict( uri=uri1, text=uri1, user=user, )) anno2 = Annotation(**dict( uri=uri1, text=uri1 + uri1, user=user2, )) anno3 = Annotation(**dict( uri=uri2, text=uri2, user=user )) anno.save() anno2.save() anno3.save() annoid = anno.id anno2id = anno2.id anno3id = anno3.id # alldocs = [x.doc for x in Metadata.DB.view('_all_docs', include_docs=True)] # pprint.pprint(alldocs) res = list(Annotation.search()) assert len(res) == 3, res # ordering (most recent first) assert res[0].text == uri2, res[0] res = Annotation.count() assert res == 3, res res = list(Annotation.search(limit=1)) assert len(res) == 1, len(res) res = Annotation.count(limit=1) assert res == 3, res res = list(Annotation.search(uri=uri1)) assert len(res) == 2, [ x for x in res ] assert res[0].uri == uri1 assert res[0].id in [ annoid, anno2id ] res = list(Annotation.search(**{'user.id':user})) assert len(res) == 2, [ x for x in res ] assert res[0].user['id'] == user assert res[0].id in [ annoid, anno3id ] res = list(Annotation.search(**{'user.id':user, 'uri': uri2})) assert len(res) == 1, [ x for x in res ] assert res[0].user['id'] == user assert res[0].id == anno3id res = Annotation.count(**{'user.id':user, 'uri': uri2}) assert res == 1, res