Пример #1
0
 def test_match(self):
     _, headers = self.login(is_admin=True)
     data = {
         'schema': 'Person',
         'collection_id': self.col_id,
         'properties': {
             'name': "Osama bin Laden",
         }
     }
     res = self.client.post('/api/2/entities',
                            data=json.dumps(data),
                            headers=headers,
                            content_type='application/json')
     data = {
         'schema': 'Person',
         'properties': {
             'name': "Osama bin Laden",
         }
     }
     matches = self.client.post('/api/2/match',
                                data=json.dumps(data),
                                headers=headers,
                                content_type='application/json')
     assert matches.status_code == 200, (matches.status_code, matches.json)
     data = matches.json
     assert len(data['results']) == 1, data
     assert 'Laden' in get_caption(data['results'][0]), data
     assert b'Pooh' not in res.data, res.data
     validate(data['results'][0], 'Entity')
Пример #2
0
 def test_match(self):
     _, headers = self.login(is_admin=True)
     data = {
         "schema": "Person",
         "collection_id": self.col_id,
         "properties": {
             "name": "Osama bin Laden",
         },
     }
     res = self.client.post(
         "/api/2/entities",
         data=json.dumps(data),
         headers=headers,
         content_type=JSON,
     )
     data = {
         "schema": "Person",
         "properties": {
             "name": "Osama bin Laden",
         },
     }
     matches = self.client.post(
         "/api/2/match",
         data=json.dumps(data),
         headers=headers,
         content_type=JSON,
     )
     assert matches.status_code == 200, (matches.status_code, matches.json)
     data = matches.json
     assert len(data["results"]) == 1, data
     assert "Laden" in get_caption(data["results"][0]), data
     assert b"Pooh" not in res.data, res.data
     validate(data["results"][0], "Entity")
Пример #3
0
 def test_view(self):
     url = '/api/2/entities/%s' % self.id
     res = self.client.get(url)
     assert res.status_code == 403, res
     _, headers = self.login(is_admin=True)
     res = self.client.get(url, headers=headers)
     assert res.status_code == 200, res
     assert 'LegalEntity' in res.json['schema'], res.json
     assert 'Winnie' in get_caption(res.json), res.json
     validate(res.json, 'Entity')
Пример #4
0
 def test_view(self):
     url = "/api/2/entities/%s" % self.id
     res = self.client.get(url)
     assert res.status_code == 403, res
     _, headers = self.login(is_admin=True)
     res = self.client.get(url, headers=headers)
     assert res.status_code == 200, res
     assert "LegalEntity" in res.json["schema"], res.json
     assert "Winnie" in get_caption(res.json), res.json
     validate(res.json, "Entity")
Пример #5
0
    def test_update(self):
        _, headers = self.login(is_admin=True)
        url = '/api/2/entities/%s' % self.id
        res = self.client.get(url, headers=headers)
        assert res.status_code == 200, res

        data = res.json
        data['properties']['name'] = ['Winne the little Shit']
        res = self.client.post(url,
                               data=json.dumps(data),
                               headers=headers,
                               content_type='application/json')
        assert res.status_code == 200, res.json
        validate(res.json, 'Entity')
        assert 'little' in get_caption(res.json), res.json

        data['properties'].pop('name', None)
        res = self.client.post(url + '?validate=true',
                               data=json.dumps(data),
                               headers=headers,
                               content_type='application/json')
        assert res.status_code == 400, res.json
Пример #6
0
 def test_similar_entity(self):
     _, headers = self.login(is_admin=True)
     url = '/api/2/entities'
     data = {
         'schema': 'Person',
         'collection_id': self.col_id,
         'properties': {
             'name': "Osama bin Laden",
         }
     }
     res = self.client.post(url,
                            data=json.dumps(data),
                            headers=headers,
                            content_type='application/json')
     data = {
         'schema': 'Person',
         'collection_id': self.col_id,
         'properties': {
             'name': "Osama bin Laden",
         }
     }
     obj = self.client.post(url,
                            data=json.dumps(data),
                            headers=headers,
                            content_type='application/json')
     url = '/api/2/entities/%s/similar' % obj.json['id']
     similar = self.client.get(url, headers=headers)
     assert similar.status_code == 200, (similar.status_code, similar.json)
     text = similar.data.decode('utf-8')
     assert obj.json['id'] not in text, obj.id
     assert obj.json['id'] not in text, obj.id
     data = similar.json
     assert len(data['results']) == 1, data
     assert 'Laden' in get_caption(data['results'][0]), data
     assert b'Pooh' not in res.data, res.data
     validate(data['results'][0], 'Entity')
Пример #7
0
 def test_similar_entity(self):
     _, headers = self.login(is_admin=True)
     url = "/api/2/entities"
     data = {
         "schema": "Person",
         "collection_id": self.col_id,
         "properties": {
             "name": "Osama bin Laden"
         },
     }
     res = self.client.post(url,
                            data=json.dumps(data),
                            headers=headers,
                            content_type=JSON)
     data = {
         "schema": "Person",
         "collection_id": self.col_id,
         "properties": {
             "name": "Osama bin Laden"
         },
     }
     obj = self.client.post(url,
                            data=json.dumps(data),
                            headers=headers,
                            content_type=JSON)
     url = "/api/2/entities/%s/similar" % obj.json["id"]
     similar = self.client.get(url, headers=headers)
     assert similar.status_code == 200, (similar.status_code, similar.json)
     text = similar.data.decode("utf-8")
     assert obj.json["id"] not in text, obj.id
     assert obj.json["id"] not in text, obj.id
     data = similar.json
     assert len(data["results"]) == 1, data
     assert "Laden" in get_caption(data["results"][0]["entity"]), data
     assert b"Pooh" not in res.data, res.data
     validate(data["results"][0], "Entity")
Пример #8
0
    def test_update(self):
        _, headers = self.login(is_admin=True)
        url = "/api/2/entities/%s" % self.id
        res = self.client.get(url, headers=headers)
        assert res.status_code == 200, res

        data = res.json
        data["properties"]["name"] = ["Winne the little Shit"]
        res = self.client.post(url,
                               data=json.dumps(data),
                               headers=headers,
                               content_type=JSON)
        assert res.status_code == 200, res.json
        validate(res.json, "Entity")
        assert "little" in get_caption(res.json), res.json

        data["properties"].pop("name", None)
        res = self.client.post(
            url + "?validate=true",
            data=json.dumps(data),
            headers=headers,
            content_type=JSON,
        )
        assert res.status_code == 400, res.json
Пример #9
0
    def test_matches(self):
        xref.xref_collection(self.residents)
        url = "/api/2/collections/%s/xref" % self.residents.id
        # Not logged in
        res = self.client.get(url)
        assert res.status_code == 403, res

        self.grant_publish(self.residents)
        res = self.client.get(url)
        assert res.status_code == 200, res
        assert res.json["total"] == 1, res.json
        res0 = res.json["results"][0]
        assert "Leeta" in get_caption(res0["entity"])
        assert "Garak" not in get_caption(res0["entity"])
        assert "Tain" not in get_caption(res0["match"])
        assert "MPella" not in get_caption(res0["match"])

        # Logged in as outsider (restricted)
        _, headers = self.login("outsider")

        res = self.client.get(url, headers=headers)
        assert res.status_code == 200, res
        assert res.json["total"] == 1, res.json
        res0 = res.json["results"][0]
        assert "Leeta" in get_caption(res0["entity"])
        assert "Garak" not in get_caption(res0["entity"])
        assert "Tain" not in get_caption(res0["match"])
        assert "MPella" not in get_caption(res0["match"])

        # Logged in as creator (all access)
        _, headers = self.login("creator")

        res = self.client.get(url, headers=headers)
        assert res.status_code == 200, res
        assert res.json["total"] == 2, res.json
        res0 = res.json["results"][0]
        assert "Garak" in get_caption(res0["entity"])
        assert "Leeta" not in get_caption(res0["entity"])
        assert "Tain" not in get_caption(res0["match"])
        assert "MPella" not in get_caption(res0["match"])
        res1 = res.json["results"][1]
        assert "Leeta" in get_caption(res1["entity"])
        assert "Garak" not in get_caption(res1["entity"])
        assert "Tain" not in get_caption(res1["match"])
        assert "MPella" not in get_caption(res1["match"])
Пример #10
0
    def test_matches(self):
        xref.xref_collection(self.stage, self.residents)
        url = '/api/2/collections/%s/xref' % self.residents.id
        # Not logged in
        res = self.client.get(url)
        assert res.status_code == 403, res

        self.grant_publish(self.residents)
        res = self.client.get(url)
        assert res.status_code == 200, res
        assert res.json['total'] == 1, res.json
        res0 = res.json['results'][0]
        assert 'Leeta' in get_caption(res0['entity'])
        assert 'Garak' not in get_caption(res0['entity'])
        assert 'Tain' not in get_caption(res0['match'])
        assert 'MPella' not in get_caption(res0['match'])

        # Logged in as outsider (restricted)
        _, headers = self.login('outsider')

        res = self.client.get(url, headers=headers)
        assert res.status_code == 200, res
        assert res.json['total'] == 1, res.json
        res0 = res.json['results'][0]
        assert 'Leeta' in get_caption(res0['entity'])
        assert 'Garak' not in get_caption(res0['entity'])
        assert 'Tain' not in get_caption(res0['match'])
        assert 'MPella' not in get_caption(res0['match'])

        # Logged in as creator (all access)
        _, headers = self.login('creator')

        res = self.client.get(url, headers=headers)
        assert res.status_code == 200, res
        assert res.json['total'] == 2, res.json
        res0 = res.json['results'][0]
        assert 'Garak' in get_caption(res0['entity'])
        assert 'Leeta' not in get_caption(res0['entity'])
        assert 'Tain' not in get_caption(res0['match'])
        assert 'MPella' not in get_caption(res0['match'])
        res1 = res.json['results'][1]
        assert 'Leeta' in get_caption(res1['entity'])
        assert 'Garak' not in get_caption(res1['entity'])
        assert 'Tain' not in get_caption(res1['match'])
        assert 'MPella' not in get_caption(res1['match'])