def test_collection_profiles(self): w = self.create_user("user") coll = self.create_collection() xref = { "entity_id": "a1", "collection_id": coll.id, "match_id": "a2", "match_collection_id": coll.id, } for judgement in Judgement: decide_xref(xref, judgement=judgement, authz=w) result = list(collection_profiles(coll.id)) assert len(result) == 1, len(result) profile, items = result[0] assert profile.collection_id == coll.id, profile.collection_id assert len(items) == 2, len(items) assert [r == judgement for r in items] result = list(collection_profiles(coll.id, deleted=True)) assert len(result) == 1, len(result) profile, items = result[0] assert profile.collection_id == coll.id, profile.collection_id assert len(items) == len(Judgement), len(items) decide_xref(xref, judgement=Judgement.NEGATIVE, authz=w) result = list( collection_profiles(coll.id, judgements=[Judgement.POSITIVE])) assert len(result) == 1, len(result) profile, items = result[0] assert len(items) == 1 assert items[0].entity_id == "a1"
def decide(collection_id, xref_id): """ --- post: summary: Give feedback about the veracity of an xref match. description: > This lets a user decide if they think a given xref match is a true or false match, and what group of users (context) should be privy to this insight. parameters: - in: path name: collection_id required: true schema: type: integer - in: path name: xref_id required: true schema: type: string requestBody: content: application/json: schema: $ref: '#/components/schemas/XrefDecide' responses: '202': content: application/json: schema: properties: status: description: accepted type: string type: object description: Accepted tags: - Xref - Profiles - EntitySet """ data = parse_request("XrefDecide") xref = obj_or_404(get_xref(xref_id, collection_id=collection_id)) require(request.authz.can(collection_id, request.authz.WRITE)) entity = get_index_entity(xref.get("entity_id")) match = get_index_entity(xref.get("match_id")) if entity is None and match is None: # This will raise a InvalidData error if the two types are not compatible model.common_schema(entity.get("schema"), match.get("schema")) decide_xref(xref, judgement=data.get("decision"), authz=request.authz) return jsonify({"status": "ok"}, status=204)
def test_decide_xref(self): w = self.create_user("user") coll = self.create_collection() xref = { "entity_id": "a1", "collection_id": coll.id, "match_id": "a2", "match_collection_id": coll.id, } profile_t1 = decide_xref(xref, judgement=Judgement.POSITIVE, authz=w) assert profile_t1.collection_id == coll.id, profile_t1 assert len(profile_t1.items().all()) == 2, profile_t1 assert all( e.judgement == Judgement.POSITIVE and e.entity_id in ("a1", "a2") for e in profile_t1.items()) xref = { "entity_id": "a1", "collection_id": coll.id, "match_id": "b1", "match_collection_id": coll.id, } profile_t2 = decide_xref(xref, judgement=Judgement.NEGATIVE, authz=w) assert profile_t1.id == profile_t2.id, (profile_t1, profile_t2) assert len(profile_t2.items().all()) == 3, profile_t2 assert all(e.judgement == Judgement.POSITIVE if e.entity_id. startswith("a") else Judgement.NEGATIVE for e in profile_t2.items()) xref = { "entity_id": "b1", "collection_id": coll.id, "match_id": "b2", "match_collection_id": coll.id, } profile_t3 = decide_xref(xref, judgement=Judgement.NEGATIVE, authz=w) assert profile_t1.id != profile_t3.id != profile_t2.id xref = { "entity_id": "a1", "collection_id": coll.id, "match_id": "b1", "match_collection_id": coll.id, } profile_t4 = decide_xref(xref, judgement=Judgement.UNSURE, authz=w) assert profile_t4.id == profile_t2.id