def test_autocomplete(self): with app.test_request_context(): for term,url in [(c['label'],c['pid']) for c in my(CATEGORIES).list_categories()]: for i in range(len(term))[2:]: pfx = term[:i] for r in structs(self.app.get(url_for('taxonomy_autocomplete', term=pfx)).data): assert r.label[:i] == pfx assert r.pid == url
def random_annotation(self): p = gen_id(self.namespace) i = gen_id(self.namespace) b = [[123,234], [345,456]] # tuples do not survive JSON roundtripping t = gen_id(self.namespace) a = gen_id(self.namespace) ts = iso8601() return structs(timestamp=ts, pid=p, image=i, geometry=b, category=t, annotator=a)
def test_create_fetch(self): with app.test_request_context(): ann_in = self.random_annotation() self.app.post(url_for('create_annotations'), data=jsons([ann_in])) raw = self.app.get(url_for('fetch_annotation', pid=ann_in.pid)).data ann_out = structs(raw) assert ann_out.pid == ann_in.pid assert ann_out.image == ann_in.image assert ann_out.scope == ann_in.scope assert ann_out.category == ann_in.category assert ann_out.annotator == ann_in.annotator assert ann_out.timestamp == ann_in.timestamp assert ann_out.geometry == ann_in.geometry
def test_list_annotations(self): with app.test_request_context(): ns = [0,1,2,3,100] image_pids = [gen_id(self.namespace) for _ in range(len(ns))] for (n,image_pid) in zip(ns,image_pids): # create n annotations for this image pid for _ in range(n): ann = self.random_annotation() ann.image = image_pid self.app.post(url_for('create_annotations', pid=ann.pid), data=jsons([ann])) for (n,image_pid) in zip(ns,image_pids): ann_list = structs(self.app.get(url_for('list_annotations', image_pid=image_pid)).data) # FIXME don't just check the length of the result, check the contents assert len(ann_list) == n
def test_list_images(self): with app.test_request_context(): r = structs(self.app.get(url_for('list_images')).data) image_list = [i['image'] for i in my(ASSIGNMENT_STORE).list_assignments()[0]['images']] assert [i.image for i in r.images] == image_list