Ejemplo n.º 1
0
 def test_entity_tags(self):
     _, headers = self.login(is_admin=True)
     url = '/api/2/entities'
     data = {
         'schema': 'Person',
         'collection_id': self.col_id,
         'properties': {
             'name': "Blaaaa blubb",
             'phone': '+491769817271'
         }
     }
     resa = self.client.post(url, data=json.dumps(data),
                             headers=headers,
                             content_type='application/json')
     data = {
         'schema': 'Person',
         'collection_id': self.col_id,
         'properties': {
             'name': "Nobody Man",
             'phone': '+491769817271'
         }
     }
     resa = self.client.post(url, data=json.dumps(data),
                             headers=headers,
                             content_type='application/json')
     url = '/api/2/entities/%s/tags' % resa.json['id']
     res = self.client.get(url, headers=headers)
     assert res.status_code == 200, (res.status_code, res.json)
     results = res.json['results']
     assert len(results) == 1, results
     assert results[0]['value'] == '+491769817271', results
     validate(res.json['results'][0], 'EntityTag')
Ejemplo n.º 2
0
 def test_create(self):
     data = {"query": "banana pumpkin"}
     jdata = json.dumps(data)
     res = self.client.post("/api/2/alerts",
                            data=jdata,
                            content_type="application/json")
     assert res.status_code == 403, res
     _, headers = self.login()
     res = self.client.post(
         "/api/2/alerts",
         data=jdata,
         headers=headers,
         content_type="application/json",
     )
     assert res.status_code == 200, res.json
     validate(res.json, "Alert")
     assert "banana pumpkin" in res.json["query"], res.json
     for wrong_data in [{"query": 2}, {"quarry": "stone"}]:
         wdata = json.dumps(wrong_data)
         res = self.client.post(
             "/api/2/alerts",
             data=wdata,
             headers=headers,
             content_type="application/json",
         )
         assert res.status_code == 400, res.json
Ejemplo n.º 3
0
    def test_entityset_items_query(self):
        url = "/api/2/entitysets"
        res = self.client.post(url, json=self.input_data, headers=self.headers)
        assert res.status_code == 200, res
        entityset_id = res.json["id"]

        url = "/api/2/entitysets/%s/items" % entityset_id
        res = self.client.get(url, headers=self.headers)
        assert res.status_code == 200, res
        validate(res.json, "EntitySetItemResponse")
        assert len(res.json["results"]) == 7, len(res.json["results"])

        fst = res.json["results"][0]
        fst["judgement"] = "negative"
        res = self.client.post(url, json=fst)
        assert res.status_code == 403, res
        res = self.client.post(url, json=fst, headers=self.headers)
        assert res.status_code == 200, res
        assert res.json["judgement"] == "negative", res

        res = self.client.get(url, headers=self.headers)
        assert len(res.json["results"]) == 7, len(res.json["results"])

        fst["judgement"] = "no_judgement"
        res = self.client.post(url, json=fst, headers=self.headers)
        assert res.status_code == 204, res

        res = self.client.get(url, headers=self.headers)
        assert len(res.json["results"]) == 6, len(res.json["results"])
Ejemplo n.º 4
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 data['results'][0]['name'], data
     assert b'Pooh' not in res.data, res.data
     validate(data['results'][0], 'Entity')
Ejemplo n.º 5
0
 def test_entity_tags(self):
     _, headers = self.login(is_admin=True)
     url = "/api/2/entities"
     data = {
         "schema": "Person",
         "collection_id": self.col_id,
         "properties": {
             "name": "Blaaaa blubb",
             "phone": ["+491769817271", "+491769817999"],
         },
     }
     resa = self.client.post(url,
                             data=json.dumps(data),
                             headers=headers,
                             content_type=JSON)
     data = {
         "schema": "Person",
         "collection_id": self.col_id,
         "properties": {
             "name": "Nobody Man",
             "phone": ["+491769817271", "+491769817777"],
         },
     }
     resa = self.client.post(url,
                             data=json.dumps(data),
                             headers=headers,
                             content_type=JSON)
     url = "/api/2/entities/%s/tags" % resa.json["id"]
     res = self.client.get(url, headers=headers)
     assert res.status_code == 200, (res.status_code, res.json)
     results = res.json["results"]
     assert len(results) == 1, results
     assert results[0]["value"] == "+491769817271", results
     validate(res.json["results"][0], "EntityTag")
Ejemplo n.º 6
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")
Ejemplo n.º 7
0
    def test_summary(self):
        xref_collection(self.stage, self.residents)
        res = self.client.get('/api/2/collections/%s/xref' % self.obsidian.id)
        assert res.status_code == 403, res

        # Not logged in
        resi_url = '/api/2/collections/%s/xref' % self.residents.id
        res = self.client.get(resi_url)
        assert res.status_code == 200, res
        assert res.json['total'] == 1, res.json
        coll0 = res.json['results'][0]['collection']
        assert 'Obsidian Order' not in coll0['label'], res.json
        assert 'Dabo Girls' in coll0['label'], res.json
        validate(coll0, 'XrefCollection')

        # Logged in as outsider (restricted access)
        _, headers = self.login(foreign_id='outsider')
        res = self.client.get(resi_url, headers=headers)
        assert res.status_code == 200, res
        assert res.json['total'] == 1, res.json
        coll0 = res.json['results'][0]['collection']
        assert 'Obsidian Order' not in coll0['label'], res.json
        assert 'Dabo Girls' in coll0['label'], res.json
        validate(coll0, 'XrefCollection')

        # Logged in as creator (all access)
        _, headers = self.login(foreign_id='creator')
        res = self.client.get(resi_url, headers=headers)
        assert res.status_code == 200, res
        assert res.json['total'] == 2, res.json
        labels = [m['collection']['label'] for m in res.json['results']]
        assert 'Obsidian Order' in labels, res.json
        assert 'Dabo Girls' in labels, res.json
Ejemplo n.º 8
0
 def test_index(self):
     res = self.client.get('/api/2/alerts')
     assert res.status_code == 403, res
     _, headers = self.login()
     res = self.client.get('/api/2/alerts', headers=headers)
     assert res.status_code == 200, res
     assert res.json.get('total') == 0, res.json
     validate(res.json, 'QueryResponse')
Ejemplo n.º 9
0
 def test_index(self):
     res = self.client.get("/api/2/alerts")
     assert res.status_code == 403, res
     _, headers = self.login()
     res = self.client.get("/api/2/alerts", headers=headers)
     assert res.status_code == 200, res
     assert res.json.get("total") == 0, res.json
     validate(res.json, "QueryResponse")
Ejemplo n.º 10
0
 def test_role_schema(self):
     data = {
         "name": "sunu",
         "is_muted": True,
         "password": "******",
         "current_password": "******",
         "locale": "en-us",
     }
     with self.assertRaises(BadRequest):
         validate(data, "RoleUpdate")
Ejemplo n.º 11
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")
Ejemplo n.º 12
0
 def test_entity_references(self):
     _, headers = self.login(is_admin=True)
     url = "/api/2/entities/%s/references" % self.book_id
     res = self.client.get(url)
     assert res.status_code == 403, res.status_code
     res = self.client.get(url, headers=headers)
     results = res.json["results"]
     assert len(results) == 1, results
     assert results[0]["count"] == 2, results
     validate(res.json["results"][0], "EntityReference")
Ejemplo n.º 13
0
 def test_entity_references(self):
     _, headers = self.login(is_admin=True)
     url = '/api/2/entities/%s/references' % self.book_id
     res = self.client.get(url)
     assert res.status_code == 403, res.status_code
     res = self.client.get(url, headers=headers)
     results = res.json['results']
     assert len(results) == 1, results
     assert results[0]['count'] == 1, results
     validate(res.json['results'][0], 'EntityReference')
Ejemplo n.º 14
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 res.json['name'], res.json
     validate(res.json, 'Entity')
Ejemplo n.º 15
0
 def test_create_with_query(self):
     data = {'query': 'putin'}
     jdata = json.dumps(data)
     _, headers = self.login()
     res = self.client.post('/api/2/alerts',
                            data=jdata,
                            headers=headers,
                            content_type='application/json')
     assert res.status_code == 200, res.json
     validate(res.json, 'Alert')
     assert res.json['query'] == 'putin', res.json
Ejemplo n.º 16
0
 def test_index(self):
     res = self.client.get("/api/2/status")
     assert res.status_code == 403, res
     _, headers = self.login()
     res = self.client.get("/api/2/status", headers=headers)
     assert res.status_code == 200, res
     assert res.json.get("total") == 0, res.json
     _, headers = self.login(is_admin=True)
     res = self.client.get("/api/2/status", headers=headers)
     assert res.status_code == 200, res
     assert res.json.get("total") == 0, res.json
     validate(res.json, "SystemStatusResponse")
Ejemplo n.º 17
0
 def test_index(self):
     res = self.client.get("/api/2/groups")
     assert res.status_code == 403, res
     _, headers = self.login(foreign_id="user_1")
     res = self.client.get("/api/2/groups", headers=headers)
     assert res.status_code == 200, res
     assert res.json["total"] == 2, res.json
     validate(res.json["results"][0], "Role")
     _, headers = self.login(foreign_id="other")
     res = self.client.get("/api/2/groups", headers=headers)
     assert res.status_code == 200, res
     assert res.json["total"] == 0, res.json
Ejemplo n.º 18
0
 def test_index(self):
     res = self.client.get('/api/2/groups')
     assert res.status_code == 403, res
     _, headers = self.login(foreign_id='user_1')
     res = self.client.get('/api/2/groups', headers=headers)
     assert res.status_code == 200, res
     assert res.json['total'] == 2, res.json
     validate(res.json['results'][0], 'Role')
     _, headers = self.login(foreign_id='other')
     res = self.client.get('/api/2/groups', headers=headers)
     assert res.status_code == 200, res
     assert res.json['total'] == 0, res.json
Ejemplo n.º 19
0
 def test_create_with_query(self):
     data = {"query": "putin"}
     jdata = json.dumps(data)
     _, headers = self.login()
     res = self.client.post(
         "/api/2/alerts",
         data=jdata,
         headers=headers,
         content_type="application/json",
     )
     assert res.status_code == 200, res.json
     validate(res.json, "Alert")
     assert res.json["query"] == "putin", res.json
Ejemplo n.º 20
0
 def test_exports_index(self):
     res = self.client.get("/api/2/exports")
     assert res.status_code == 403, res
     _, headers = self.login()
     res = self.client.get("/api/2/exports", headers=headers)
     assert res.status_code == 200, res
     assert res.json["total"] == 0, res.json
     res = self.client.get("/api/2/exports", headers=self.headers)
     assert res.status_code == 200, res
     validate(res.json, "QueryResponse")
     assert res.json["total"] == 2, res.json
     results = res.json["results"]
     validate(results[0], "Export")
Ejemplo n.º 21
0
    def test_view(self):
        data = {'query': 'putin'}
        jdata = json.dumps(data)
        _, headers = self.login()
        res = self.client.post('/api/2/alerts',
                               data=jdata,
                               headers=headers,
                               content_type='application/json')
        url = '/api/2/alerts/%s' % res.json['id']
        res2 = self.client.get(url, headers=headers)
        assert res2.json['id'] == res.json['id'], res2.json
        validate(res.json, 'Alert')

        res3 = self.client.get('/api/2/alerts/100000', headers=headers)
        assert res3.status_code == 404, res3
Ejemplo n.º 22
0
    def test_notifications(self):
        _, headers = self.login(foreign_id="admin")
        res = self.client.get("/api/2/notifications", headers=headers)
        assert res.status_code == 200, res
        assert res.json["total"] == 0, res.json

        assert self.rolex.type == Role.USER, self.rolex.type
        _, headers = self.login(foreign_id=self.rolex.foreign_id)
        res = self.client.get("/api/2/notifications", headers=headers)
        assert res.status_code == 200, res
        assert res.json["total"] == 2, res.json
        not0 = res.json["results"][0]
        validate(not0, "Notification")

        role = not0["params"]["role"]
        assert isinstance(role, dict), not0
        assert "actor" in not0["params"], not0["params"]
Ejemplo n.º 23
0
def _load_metadata():
    """Unpack the common, pre-defined metadata for all the uploaded files."""
    try:
        meta = json.loads(request.form.get("meta", "{}"))
    except Exception as ex:
        raise BadRequest(str(ex))

    validate(meta, "DocumentIngest")
    foreign_id = stringify(meta.get("foreign_id"))
    if not len(request.files) and foreign_id is None:
        raise BadRequest(
            response=jsonify(
                {"status": "error", "message": "Directories need to have a foreign_id"},
                status=400,
            )
        )
    return meta, foreign_id
Ejemplo n.º 24
0
    def test_view(self):
        data = {"query": "putin"}
        jdata = json.dumps(data)
        _, headers = self.login()
        res = self.client.post(
            "/api/2/alerts",
            data=jdata,
            headers=headers,
            content_type="application/json",
        )
        url = "/api/2/alerts/%s" % res.json["id"]
        res2 = self.client.get(url, headers=headers)
        assert res2.json["id"] == res.json["id"], res2.json
        validate(res.json, "Alert")

        res3 = self.client.get("/api/2/alerts/100000", headers=headers)
        assert res3.status_code == 404, res3
Ejemplo n.º 25
0
    def test_notifications(self):
        _, headers = self.login(foreign_id='admin')
        res = self.client.get('/api/2/notifications', headers=headers)
        assert res.status_code == 200, res
        assert res.json['total'] == 0, res.json

        assert self.rolex.type == Role.USER, self.rolex.type
        _, headers = self.login(foreign_id=self.rolex.foreign_id)
        res = self.client.get('/api/2/notifications', headers=headers)
        assert res.status_code == 200, res
        assert res.json['total'] == 2, res.json
        not0 = res.json['results'][0]
        validate(not0, 'Notification')

        role = not0['params']['role']
        assert isinstance(role, dict), not0
        assert 'actor' in not0['params'], not0['params']
Ejemplo n.º 26
0
def _load_metadata():
    """Unpack the common, pre-defined metadata for all the uploaded files."""
    try:
        meta = json.loads(request.form.get('meta', '{}'))
    except Exception as ex:
        raise BadRequest(str(ex))

    validate(meta, 'DocumentIngest')
    foreign_id = stringify(meta.get('foreign_id'))
    if not len(request.files) and foreign_id is None:
        raise BadRequest(response=jsonify(
            {
                'status': 'error',
                'message': 'Directories need to have a foreign_id'
            },
            status=400))
    return meta, foreign_id
Ejemplo n.º 27
0
    def test_querylog_logged_in(self):
        _, headers = self.login()
        res = self.client.get('/api/2/querylog', headers=headers)
        assert res.json['total'] == 0, res

        res = self.client.get('/api/2/search?q=foo', headers=headers)
        res = self.client.get('/api/2/querylog', headers=headers)
        assert res.json['total'] == 1, res

        res = self.client.get('/api/2/search?q=foo', headers=headers)
        res = self.client.get('/api/2/querylog', headers=headers)
        assert res.json['total'] == 1, res

        res = self.client.get('/api/2/search?q=bar', headers=headers)
        res = self.client.get('/api/2/querylog', headers=headers)
        assert res.json['total'] == 2, res
        validate(res.json['results'][0], 'QueryLog')
        validate(res.json['results'][1], 'QueryLog')
Ejemplo n.º 28
0
 def test_view(self):
     res = self.client.get("/api/2/collections/%s" % self.col.id)
     assert res.status_code == 403, res
     _, headers = self.login(is_admin=True)
     res = self.client.get("/api/2/collections/%s" % self.col.id, headers=headers)
     assert res.status_code == 200, res
     assert "test_coll" in res.json["foreign_id"], res.json
     assert "Winnie" not in res.json["label"], res.json
     assert validate(res.json, "Collection")
Ejemplo n.º 29
0
    def test_querylog_logged_in(self):
        _, headers = self.login()
        res = self.client.get("/api/2/querylog", headers=headers)
        assert res.json["total"] == 0, res

        res = self.client.get("/api/2/search?q=foo", headers=headers)
        res = self.client.get("/api/2/querylog", headers=headers)
        assert res.json["total"] == 1, res

        res = self.client.get("/api/2/search?q=foo", headers=headers)
        res = self.client.get("/api/2/querylog", headers=headers)
        assert res.json["total"] == 1, res

        res = self.client.get("/api/2/search?q=bar", headers=headers)
        res = self.client.get("/api/2/querylog", headers=headers)
        assert res.json["total"] == 2, res
        validate(res.json["results"][0], "QueryLog")
        validate(res.json["results"][1], "QueryLog")
Ejemplo n.º 30
0
 def test_create(self):
     _, headers = self.login(is_admin=True)
     url = '/api/2/entities'
     data = {
         'schema': 'RealEstate',
         'collection_id': self.col_id,
         'properties': {
             'name': "Our house",
             'summary': "In the middle of our street"
         }
     }
     res = self.client.post(url,
                            data=json.dumps(data),
                            headers=headers,
                            content_type='application/json')
     assert res.status_code == 200, res.json
     assert 'middle' in res.json['properties']['summary'][0], res.json
     validate(res.json, 'Entity')