Skip to content

Commit

Permalink
Add export functionality. Cleanup http requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kubantjan committed Mar 9, 2022
1 parent 2a59e9c commit 768fecb
Show file tree
Hide file tree
Showing 20 changed files with 608 additions and 207 deletions.
4 changes: 3 additions & 1 deletion local_testing_utilities/add-demo-user.http
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,6 @@ GET {{url}}/v1/user/{{demo_email}}/reset-password-token
Content-Type: application/json
Authorization: Bearer {{admin_auth_token}}

> {% client.log("Change password page has a format: http://localhost:4200/#/reset-password/" + response.body["token"]) %}
> {%
client.log("Change password page for " + client.global.get("demo_email") + " has a format: +" +
"txm.demo.mild.blue/#/reset-password/" + response.body["token"]) %}
62 changes: 62 additions & 0 deletions local_testing_utilities/add-new-ikem-user.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# test the api works

GET {{url}}/v1/service/version
Content-Type: application/json

> {%
client.global.set("new_user_email", "");
client.global.set("txm_event_name", "");
client.global.set("second_factor", "");
%}

###
POST {{url}}/v1/user/login
Content-Type: application/json

{
"email": "{{email}}",
"password": "{{password}}"
}

> {% client.global.set("auth_token", response.body["auth_token"]); %}

###

POST {{url}}/v1/user/otp
Content-Type: application/json
Authorization: Bearer {{auth_token}}

{
"otp": ""
}

> {% client.global.set("auth_token", response.body["auth_token"]); %}

###


POST {{url}}/v1/user/register
Content-Type: application/json
Authorization: Bearer {{auth_token}}

{
"email": {{new_user_email}},
"password": "supersecretpasswordthatwillbechangedanyway",
"role": "EDITOR",
"second_factor": {{second_factor}},
"allowed_countries": [
"BEL"
],
"require_second_factor": true
}

###

GET {{url}}/v1/user/{{new_user_email}}/reset-password-token
Content-Type: application/json
Authorization: Bearer {{auth_token}}

> {%
client.log("Change password page for " + client.global.get("new_user_email") + " has a format https://txmatching.ikem.cz/#/reset-password/" + response.body["token"]) %}

###
103 changes: 0 additions & 103 deletions local_testing_utilities/add-new-user.http

This file was deleted.

42 changes: 42 additions & 0 deletions local_testing_utilities/change-password.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# The workflow to change user password

GET {{url}}/v1/service/version
Content-Type: application/json

> {%
client.global.set("change_password_email", "demo@example.com");
client.global.set("new_password", "demo@example.com");
%}

### Registrer demo user

POST {{url}}/v1/user/login
Content-Type: application/json

{
"email": "{{email}}",
"password": "{{password}}"
}

> {% client.global.set("admin_auth_token", response.body["auth_token"]); %}

### Demo user is ready now, lets generate reset password link

GET {{url}}/v1/user/{{change_password_email}}/reset-password-token
Content-Type: application/json
Authorization: Bearer {{admin_auth_token}}

> {%
client.log("Change password page for " + client.global.get("change_password_email") + " has a format: " + client.global.get("url")+ "/#/reset-password/" + response.body["token"])
client.global.set("change_password_token", response.body["token"]);
%}

###

PUT {{url}}/v1/user/reset-password
Content-Type: application/json

{
"token": {{change_password_token}},
"password": "bag2r"
}
4 changes: 2 additions & 2 deletions local_testing_utilities/create-new-txm-event.http
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Content-Type: application/json
Authorization: Bearer {{auth_token}}

{
"otp": ""
"otp": "675785"
}

> {% client.global.set("auth_token", response.body["auth_token"]); %}
Expand All @@ -32,7 +32,7 @@ Authorization: Bearer {{auth_token}}


{
"name": "35-TXM-2021-10"
"name": "TEST-BEL-TXM-2022-01"
}

> {% client.global.set("txm_event_id", response.body["id"]); %}
Expand Down
46 changes: 46 additions & 0 deletions local_testing_utilities/export-patients.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
GET {{url}}/v1/service/version
Content-Type: application/json


###
POST {{url}}/v1/user/login
Content-Type: application/json

{
"email": "{{email}}",
"password": "{{password}}"
}

> {% client.global.set("auth_token", response.body["auth_token"]); %}

###


POST {{url}}/v1/txm-event/2/export
Content-Type: application/json
Authorization: Bearer {{auth_token}}


{
"country": "CZE",
"new_txm_event_name": "test2"
}


###
POST {{url}}/v1/user/login
Content-Type: application/json

{
"email": "{{service_username}}",
"password": "{{service_password}}"
}

> {% client.global.set("auth_token", response.body["auth_token"]); %}

###
PUT {{url}}/v1/public/patient-upload
Authorization: Bearer {{auth_token}}
Content-Type: application/json

< tmp.json
11 changes: 6 additions & 5 deletions local_testing_utilities/generate_patients.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
RecipientUploadDTO
from txmatching.database.services.patient_upload_service import \
replace_or_add_patients_from_one_country
from txmatching.patients.patient import DonorType
from txmatching.patients.patient import DonorType, TxmEvent
from txmatching.utils.blood_groups import BloodGroup
from txmatching.utils.country_enum import Country
from txmatching.utils.enums import HLA_GROUPS_PROPERTIES, HLAGroup, Sex
Expand Down Expand Up @@ -262,20 +262,21 @@ def generate_patients(txm_event_name: str = GENERATED_TXM_EVENT_NAME,
return patient_upload_objects


def store_generated_patients_from_folder(folder=LARGE_DATA_FOLDER):
def store_generated_patients_from_folder(folder=LARGE_DATA_FOLDER) -> TxmEvent:
patient_upload_objects = []
for filename in os.listdir(folder):
with open(f'{folder}{filename}', encoding='utf-8') as file_to_load:
patient_upload_dto = from_dict(data_class=PatientUploadDTOIn,
data=json.load(file_to_load), config=Config(cast=[Enum]))
patient_upload_objects.append(patient_upload_dto)
store_generated_patients(patient_upload_objects)
return store_generated_patients(patient_upload_objects)


def store_generated_patients(generated_patients: List[PatientUploadDTOIn]):
create_or_overwrite_txm_event(GENERATED_TXM_EVENT_NAME)
def store_generated_patients(generated_patients: List[PatientUploadDTOIn]) -> TxmEvent:
txm_event = create_or_overwrite_txm_event(GENERATED_TXM_EVENT_NAME)
for patient_upload_dto in generated_patients:
replace_or_add_patients_from_one_country(patient_upload_dto)
return txm_event


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 768fecb

Please sign in to comment.