2022-05-18 16:18:47 +00:00
|
|
|
"""Test Api Blueprint."""
|
|
|
|
import json
|
2022-05-18 21:07:35 +00:00
|
|
|
from typing import Union
|
2022-05-18 16:18:47 +00:00
|
|
|
|
2022-05-18 21:07:35 +00:00
|
|
|
from flask.testing import FlaskClient
|
2022-05-18 16:18:47 +00:00
|
|
|
from flask_bpmn.models.db import db
|
2022-05-18 21:07:35 +00:00
|
|
|
|
2022-06-01 15:17:25 +00:00
|
|
|
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
2022-05-18 16:18:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_user_can_be_created_and_deleted(client: FlaskClient) -> None:
|
2022-05-31 18:10:00 +00:00
|
|
|
"""Test_user_can_be_created_and_deleted."""
|
2022-05-23 20:36:23 +00:00
|
|
|
process_instance = ProcessInstanceModel.query.filter().first()
|
|
|
|
if process_instance is not None:
|
|
|
|
db.session.delete(process_instance)
|
2022-05-18 16:18:47 +00:00
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
last_response = None
|
|
|
|
tasks = [
|
|
|
|
{"task_identifier": "1", "answer": {"Product Name": "G", "Quantity": "2"}},
|
|
|
|
{"task_identifier": "1", "answer": {"Sleeve Type": "Short"}},
|
|
|
|
{"task_identifier": "1", "answer": {"Continue shopping?": "N"}},
|
|
|
|
{"task_identifier": "1", "answer": {"Shipping Method": "Overnight"}},
|
|
|
|
{"task_identifier": "1", "answer": {"Shipping Address": "Somewhere"}},
|
|
|
|
{"task_identifier": "1", "answer": {"Place Order": "Y"}},
|
|
|
|
{"task_identifier": "1", "answer": {"Card Number": "MY_CARD"}},
|
|
|
|
{"task_identifier": "2", "answer": {"Was the customer charged?": "Y"}},
|
|
|
|
{"task_identifier": "1", "answer": {"Was the product available?": "Y"}},
|
|
|
|
{"task_identifier": "1", "answer": {"Was the order shipped?": "Y"}},
|
|
|
|
]
|
|
|
|
for task in tasks:
|
2022-05-20 22:11:32 +00:00
|
|
|
run_task(client, task, last_response)
|
2022-05-18 16:18:47 +00:00
|
|
|
|
2022-05-23 20:36:23 +00:00
|
|
|
process_instance = ProcessInstanceModel.query.filter().first()
|
|
|
|
if process_instance is not None:
|
|
|
|
db.session.delete(process_instance)
|
2022-05-18 16:18:47 +00:00
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
2022-05-18 21:07:35 +00:00
|
|
|
def run_task(
|
|
|
|
client: FlaskClient, request_body: dict, last_response: Union[None, str]
|
2022-05-20 22:11:32 +00:00
|
|
|
) -> None:
|
2022-05-18 16:18:47 +00:00
|
|
|
"""Run_task."""
|
2022-05-18 21:07:35 +00:00
|
|
|
response = client.post(
|
|
|
|
"/run_process",
|
|
|
|
content_type="application/json",
|
|
|
|
data=json.dumps(request_body),
|
|
|
|
)
|
2022-05-18 16:18:47 +00:00
|
|
|
assert response.status_code == 200
|