def test_search_by_exclude_username_ok(wa_audio): catcha = wa_audio c = deepcopy(catcha) for i in [1, 2, 3, 4, 5]: c['id'] = '{}{}'.format(catcha['id'], i) c['creator']['id'] = '{}-{}'.format(catcha['creator']['id'], i) c['creator']['name'] = '{}-{}'.format(catcha['creator']['name'], i) x = CRUD.create_anno(c) c = deepcopy(catcha) for i in [6, 7, 8, 9]: c['id'] = '{}{}'.format(catcha['id'], i) x = CRUD.create_anno(c) payload = make_jwt_payload(user=catcha['creator']['id']) other_username = '******'.format(catcha['creator']['name']) request = make_json_request( method='get', query_string='exclude_username={}&exclude_username={}'.format( other_username, catcha['creator']['name'])) request.catchjwt = payload response = search_api(request) resp = json.loads(response.content.decode('utf-8')) assert response.status_code == 200 assert resp['total'] == 4 assert len(resp['rows']) == 4 for a in resp['rows']: print('----- {} : {}'.format(a['id'], a['creator']['name'])) assert (a['creator']['name'] != catcha['creator']['name']) and ( a['creator']['name'] != other_username)
def test_search_by_userid_ok(wa_text): catcha = wa_text c = deepcopy(catcha) for i in [1, 2, 3, 4, 5]: c['id'] = '{}{}'.format(catcha['id'], i) c['creator']['id'] = '{}-{}'.format(catcha['creator']['id'], i) c['creator']['name'] = '{}-{}'.format(catcha['creator']['name'], i) x = CRUD.create_anno(c) c = deepcopy(catcha) for i in [6, 7, 8, 9]: c['id'] = '{}{}'.format(catcha['id'], i) x = CRUD.create_anno(c) payload = make_jwt_payload(user=catcha['creator']['id']) request = make_json_request( method='get', # to send a list of userids query_string='userid={}&userid=1234567890'.format( catcha['creator']['id'])) request.catchjwt = payload response = search_api(request) resp = json.loads(response.content.decode('utf-8')) assert response.status_code == 200 assert resp['total'] == 4 assert len(resp['rows']) == 4 for a in resp['rows']: assert a['creator']['id'] == catcha['creator']['id']
def test_search_by_context_id_ok(wa_text, wa_video, wa_image, wa_audio): for wa in [wa_text, wa_video, wa_image, wa_audio]: x = CRUD.create_anno(wa) wa = deepcopy(wa_audio) search_context_id = 'not_the_normal_context_id' wa['id'] = '12345678' wa['platform']['context_id'] = search_context_id x = CRUD.create_anno(wa) payload = make_jwt_payload() request = make_json_request( method='get', query_string='context_id={}&platform={}'.format( search_context_id, wa['platform']['platform_name'])) request.catchjwt = payload tudo = Anno._default_manager.all() for z in tudo: print('id({}), platform({}), context_id({}), collection_id({})'.format( z.anno_id, z.raw['platform'].get('platform_name', 'na'), z.raw['platform'].get('context_id', 'na'), z.raw['platform'].get('collection_id', 'na'))) response = search_api(request) resp = json.loads(response.content.decode('utf-8')) assert response.status_code == 200 assert resp['total'] == 1 assert resp['rows'][0]['target']['items'][0]['type'] == 'Audio' assert resp['rows'][0]['id'] == wa['id']
def test_search_by_target_source_ok(wa_audio, wa_image): catcha1 = wa_audio catcha2 = wa_image tsource = catcha1['target']['items'][0]['source'] ttype = catcha1['target']['items'][0]['type'] for i in [1, 2, 3, 4]: for catcha in [catcha1, catcha2]: c = deepcopy(catcha) c['id'] = '{}{}'.format(catcha['id'], i) x = CRUD.create_anno(c) payload = make_jwt_payload() request = make_json_request( method='get', query_string='target_source={}'.format(tsource)) request.catchjwt = payload response = search_api(request) resp = json.loads(response.content.decode('utf-8')) assert response.status_code == 200 assert resp['total'] == 4 for a in resp['rows']: assert Catcha.has_target_source(a, tsource, ttype) assert Catcha.has_target_source(a, tsource)
def test_search_by_tag_or_tag(wa_video): catcha = wa_video common_tag_value = 'testing_tag_even' common_tag = make_wa_tag(common_tag_value) for i in [1, 2, 3, 4, 5]: c = deepcopy(catcha) c['id'] = '{}{}'.format(catcha['id'], i) tag = make_wa_tag(tagname='testing_tag{}'.format(i)) c['body']['items'].append(tag) if i % 2 == 0: c['body']['items'].append(common_tag) x = CRUD.create_anno(c) payload = make_jwt_payload(user=catcha['creator']['id']) request = make_json_request( method='get', # to send a list of userids query_string='tag={}&tag={}'.format(common_tag_value, 'testing_tag3')) request.catchjwt = payload response = search_api(request) resp = json.loads(response.content.decode('utf-8')) assert response.status_code == 200 assert resp['total'] == 3 assert len(resp['rows']) == 3 for a in resp['rows']: if not Catcha.has_tag(a, 'testing_tag3'): assert Catcha.has_tag(a, common_tag_value) is True
def test_search_by_media_ok(wa_text, wa_video, wa_image, wa_audio): for wa in [wa_text, wa_video, wa_image, wa_audio]: x = CRUD.create_anno(wa) payload = make_jwt_payload() request = make_json_request(method='get', query_string='media=video') request.catchjwt = payload response = search_api(request) resp = json.loads(response.content.decode('utf-8')) assert response.status_code == 200 assert resp['total'] == 1 assert resp['rows'][0]['target']['items'][0]['type'] == 'Video' assert resp['rows'][0]['id'] == wa_video['id']
def test_search_by_body_text_ok(wa_list): for wa in wa_list: x = CRUD.create_anno(wa) wa = make_wa_object(age_in_hours=40) # counting that first item in body is the actual annotation wa['body']['items'][0]['value'] += ''' nao mais, musa, nao mais, que a lira tenho destemperada e a voz enrouquecida, e nao to canto, mas de ver que venho cantar a gente surda e endurecida.''' anno = CRUD.create_anno(wa) search_text = 'enrouquecida endurecida' payload = make_jwt_payload() request = make_json_request(method='get', query_string='text={}'.format(search_text)) request.catchjwt = payload response = search_api(request) resp = json.loads(response.content.decode('utf-8')) assert response.status_code == 200 assert resp['total'] == 1 assert resp['rows'][0]['id'] == anno.anno_id