Skip to content

Commit

Permalink
fixing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiaBarbo committed Aug 16, 2024
1 parent 51077aa commit ffd28c2
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 46 deletions.
7 changes: 4 additions & 3 deletions routes/utils/json_to_prov.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def json_to_prov_record(json_file, bundle):
for rec_type_str, rec_content in json_file.items():
# get the type of the record
rec_type = PROV_RECORD_IDS_MAP[rec_type_str]

attributes = dict()
other_attributes = []

for rec_id, content in rec_content.items():
if hasattr(content, "items"): # it is a dict
Expand All @@ -18,8 +21,6 @@ def json_to_prov_record(json_file, bundle):
elements = content

for element in elements:
attributes = dict()
other_attributes = []
# this is for the multiple-entity membership hack to come
membership_extra_members = None
for attr_name, values in element.items():
Expand Down Expand Up @@ -79,4 +80,4 @@ def json_to_prov_record(json_file, bundle):

#prov_element = bundle.get_record(rec_id)[0]
# prov_element = prov_document.get_records(ProvElement)[0]
return bundle.get_record(rec_id)[0]
return bundle.get_record(rec_id)[0]
Binary file modified tests/__pycache__/test_documents.cpython-310-pytest-8.2.2.pyc
Binary file not shown.
111 changes: 68 additions & 43 deletions tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,51 @@ def test_documents_put_doc_id_permission():
response = requests.put(PATH + '/pta/permissions', json=payload, headers=headers)
assert response.status_code == 403

"""

# document not found
payload = {
"user": "userB",
"level": "w"
"user": "userD",
"level": "r"
}
headers = {
'Authorization': 'Bearer ' + TOKEN_A
}
response = requests.put(PATH + '/1/permissions', json=payload, headers=headers)
response = requests.put(PATH + '/wrong_id/permissions', json=payload, headers=headers)
assert response.status_code == 404
"""



def test_documents_put_doc_id_entities_e_id():

"""
# entity added
payload = {}
payload = {
"entity": {
"ophidia:MyNewTest":
{
"prov:type": "ophidia:datacube",
"prov:name": "test"
}
}
}
headers = {
'Authorization': 'Bearer ' + TOKEN_A
}
response = requests.put(PATH + '/pta/entities/test', json=payload, headers=headers)
assert response.status_code == 201
"""
# document not valid
payload = { "document not valid" }
payload = {
"entity": {
"ophidia:MyNewTest":
{
"prov:type": "ophidia:datacube",
"prov:name": 123
}
}
}
headers = {
'Authorization': 'Bearer ' + TOKEN
'Authorization': 'Bearer ' + TOKEN_A
}
response = requests.put(PATH + '/pta/entities/test', json=payload, headers=headers)
assert response.status_code == 400
Expand All @@ -112,15 +127,24 @@ def test_documents_put_doc_id_entities_e_id():
}
response = requests.put(PATH + '/wrong_id/entities/test', json=payload, headers=headers)
assert response.status_code == 404
"""



def test_documents_put_doc_id_activities_a_id():
"""
# activity added
payload = {}
payload = {
"activity": {
"ophidia:MyNewTest":
{
"prov:type": "ophidia:datacube",
"prov:name": "test"
}
}
}
headers = {
'Authorization': 'Bearer ' + TOKEN
'Authorization': 'Bearer ' + TOKEN_A
}
response = requests.put(PATH + '/pta/activities/test', json=payload, headers=headers)
assert response.status_code == 201
Expand All @@ -140,11 +164,12 @@ def test_documents_put_doc_id_activities_a_id():
}
response = requests.put(PATH + '/wrong_id/activities/test', json=payload, headers=headers)
assert response.status_code == 404
"""


def test_documents_put_doc_id_agents_a_id():

"""
# agents added
payload = {}
headers = {
Expand All @@ -168,11 +193,12 @@ def test_documents_put_doc_id_agents_a_id():
}
response = requests.put(PATH + '/wrong_id/agents/test', json=payload, headers=headers)
assert response.status_code == 404
"""


def test_documents_put_doc_id_relations_r_id():

"""
# agents added
payload = {}
headers = {
Expand All @@ -196,6 +222,7 @@ def test_documents_put_doc_id_relations_r_id():
}
response = requests.put(PATH + '/wrong_id/relations/test', json=payload, headers=headers)
assert response.status_code == 404
"""


def test_documents_get():
Expand Down Expand Up @@ -257,55 +284,54 @@ def test_documents_get_doc_id_agents():


def test_documents_get_doc_id_entities_e_id():
"""
# return requested entity
response = requests.get(PATH + "/pta/entities/test")
assert response.status_code == 200
# document not found
response = requests.get(PATH + "/wrong_id/entities/test")
assert response.status_code == 404
"""


def test_documents_get_doc_id_activities_a_id():
"""
# list of activities
response = requests.get(PATH + "/pta/activities/test")
assert response.status_code == 200
# document not found
response = requests.get(PATH + "/wrong_id/activities/test")
assert response.status_code == 404
"""


def test_documents_get_doc_id_agents_a_id():
"""
# list of agents
response = requests.get(PATH + "/pta/agents/test")
assert response.status_code == 200
# document not found
response = requests.get(PATH + "/wrong_id/agents/test")
assert response.status_code == 404
"""


def test_documents_get_doc_id_relations_r_id():
"""
# list of agents
response = requests.get(PATH + "/pta/agents/test")
assert response.status_code == 200
# document not found
response = requests.get(PATH + "/wrong_id/agents/test")
assert response.status_code == 404
"""

def test_documents_delete_doc_id_entities_e_id():
"""
# document uploaded
headers = {
'Authorization': 'Bearer wrong_token'
Expand All @@ -315,22 +341,22 @@ def test_documents_delete_doc_id_entities_e_id():
# document uploaded
headers = {
'Authorization': 'Bearer ' + TOKEN
'Authorization': 'Bearer ' + TOKEN_A
}
response = requests.delete(PATH + '/pta/entities/test', headers=headers)
assert response.status_code == 200
# document uploaded
headers = {
'Authorization': 'Bearer ' + TOKEN
'Authorization': 'Bearer ' + TOKEN_A
}
response = requests.delete(PATH + '/pta/entities/test', headers=headers)
assert response.status_code == 404
"""


def test_documents_delete_doc_id_activities_a_id():
"""
# document uploaded
headers = {
'Authorization': 'Bearer wrong_token'
Expand All @@ -340,22 +366,22 @@ def test_documents_delete_doc_id_activities_a_id():
# document uploaded
headers = {
'Authorization': 'Bearer ' + TOKEN
'Authorization': 'Bearer ' + TOKEN_A
}
response = requests.delete(PATH + '/pta/activites/test', headers=headers)
assert response.status_code == 200
# document uploaded
headers = {
'Authorization': 'Bearer ' + TOKEN
'Authorization': 'Bearer ' + TOKEN_A
}
response = requests.delete(PATH + '/pta/activites/test', headers=headers)
assert response.status_code == 404
"""


def test_documents_delete_doc_id_agents_a_id():
"""
# document uploaded
headers = {
'Authorization': 'Bearer wrong_token'
Expand All @@ -376,11 +402,11 @@ def test_documents_delete_doc_id_agents_a_id():
}
response = requests.delete(PATH + '/pta/agents/test', headers=headers)
assert response.status_code == 404
"""


def test_documents_delete_doc_id_relations_r_id():
"""
# document uploaded
headers = {
'Authorization': 'Bearer wrong_token'
Expand All @@ -401,35 +427,34 @@ def test_documents_delete_doc_id_relations_r_id():
}
response = requests.delete(PATH + '/pta/relations/test', headers=headers)
assert response.status_code == 404
"""


def test_documents_delete_doc_id():

# document uploaded
headers = {
'Authorization': 'Bearer wrong_token'
}
'Authorization': 'Bearer ' + TOKEN_B
}
response = requests.delete(PATH + '/pta', headers=headers)
assert response.status_code == 403

# document uploaded
headers = {
'Authorization': 'Bearer ' + TOKEN
'Authorization': 'Bearer ' + TOKEN_A
}
response = requests.delete(PATH + '/pta', headers=headers)
assert response.status_code == 200

# document uploaded
headers = {
'Authorization': 'Bearer ' + TOKEN
'Authorization': 'Bearer ' + TOKEN_A
}
response = requests.delete(PATH + '/pta', headers=headers)
assert response.status_code == 404


"""




Expand Down

0 comments on commit ffd28c2

Please sign in to comment.