Merge branch 'cullerton'
# Conflicts: # src/spiffworkflow_backend/routes/process_api_blueprint.py # tests/spiffworkflow_backend/integration/test_process_api.py
This commit is contained in:
commit
f12cc156c5
|
@ -63,7 +63,19 @@ def process_groups_list(page=1, per_page=100):
|
|||
"""Process_groups_list."""
|
||||
process_groups = ProcessModelService().get_process_groups()
|
||||
batch = ProcessModelService().get_batch(process_groups, page, per_page)
|
||||
return ProcessGroupSchema(many=True).dump(batch)
|
||||
pages = len(process_groups) // per_page
|
||||
remainder = len(process_groups) % per_page
|
||||
if remainder > 0:
|
||||
pages += 1
|
||||
response_json = {
|
||||
"results": ProcessGroupSchema(many=True).dump(batch),
|
||||
"pagination": {
|
||||
"count": len(batch),
|
||||
"total": len(process_groups),
|
||||
"pages": pages,
|
||||
},
|
||||
}
|
||||
return Response(json.dumps(response_json), status=200, mimetype="application/json")
|
||||
|
||||
|
||||
def process_group_show(process_group_id):
|
||||
|
@ -126,7 +138,24 @@ def process_model_show(process_group_id, process_model_id):
|
|||
|
||||
def process_model_list(process_group_id, page=1, per_page=100):
|
||||
"""Process model list!"""
|
||||
...
|
||||
process_models = ProcessModelService().get_process_models(process_group_id)
|
||||
batch = ProcessModelService().get_batch(
|
||||
process_models, page=page, per_page=per_page
|
||||
)
|
||||
pages = len(process_models) // per_page
|
||||
remainder = len(process_models) % per_page
|
||||
if remainder > 0:
|
||||
pages += 1
|
||||
response_json = {
|
||||
"results": ProcessModelInfoSchema(many=True).dump(batch),
|
||||
"pagination": {
|
||||
"count": len(batch),
|
||||
"total": len(process_models),
|
||||
"pages": pages,
|
||||
},
|
||||
}
|
||||
|
||||
return Response(json.dumps(response_json), status=200, mimetype="application/json")
|
||||
|
||||
|
||||
def get_file(process_model_id, file_name):
|
||||
|
|
|
@ -69,10 +69,10 @@ class ProcessModelService(FileSystemService):
|
|||
|
||||
def __remove_library_references(self, spec_id):
|
||||
"""__remove_library_references."""
|
||||
for spec in self.get_specs():
|
||||
if spec_id in spec.libraries:
|
||||
spec.libraries.remove(spec_id)
|
||||
self.update_spec(spec)
|
||||
for process_model in self.get_process_models():
|
||||
if spec_id in process_model.libraries:
|
||||
process_model.libraries.remove(spec_id)
|
||||
self.update_spec(process_model)
|
||||
|
||||
@property
|
||||
def master_spec(self):
|
||||
|
@ -112,9 +112,15 @@ class ProcessModelService(FileSystemService):
|
|||
)
|
||||
return self.__scan_spec(sd.path, sd.name, process_group)
|
||||
|
||||
def get_specs(self):
|
||||
"""Get_specs."""
|
||||
def get_process_models(self, process_group_id=None):
|
||||
"""Get process models."""
|
||||
if process_group_id is None:
|
||||
process_groups = self.get_process_groups()
|
||||
else:
|
||||
process_group = self.get_process_group(process_group_id)
|
||||
process_groups = [
|
||||
process_group,
|
||||
]
|
||||
process_models = []
|
||||
for process_group in process_groups:
|
||||
process_models.extend(process_group.process_models)
|
||||
|
|
|
@ -148,7 +148,75 @@ def test_process_model_update(
|
|||
def test_process_model_list(
|
||||
app: Flask, client: FlaskClient, with_bpmn_file_cleanup: None
|
||||
) -> None:
|
||||
...
|
||||
"""Test_process_model_list."""
|
||||
# create a group
|
||||
group_id = "test_group"
|
||||
user = find_or_create_user()
|
||||
create_process_group(client, user, group_id)
|
||||
|
||||
# add 5 models to the group
|
||||
for i in range(5):
|
||||
model_id = f"test_model_{i}"
|
||||
model_display_name = f"Test Model {i}"
|
||||
model_description = f"Test Model {i} Description"
|
||||
create_process_model(
|
||||
app, client, group_id, model_id, model_display_name, model_description
|
||||
)
|
||||
|
||||
# get all models
|
||||
response = client.get(
|
||||
f"/v1.0/process-groups/{group_id}/process-models",
|
||||
headers=logged_in_headers(user),
|
||||
)
|
||||
assert len(response.json["results"]) == 5
|
||||
assert response.json["pagination"]["count"] == 5
|
||||
assert response.json["pagination"]["total"] == 5
|
||||
assert response.json["pagination"]["pages"] == 1
|
||||
|
||||
# get first page, 1 per page
|
||||
response = client.get(
|
||||
f"/v1.0/process-groups/{group_id}/process-models?page=1&per_page=1",
|
||||
headers=logged_in_headers(user),
|
||||
)
|
||||
assert len(response.json["results"]) == 1
|
||||
assert response.json["results"][0]["id"] == "test_model_0"
|
||||
assert response.json["pagination"]["count"] == 1
|
||||
assert response.json["pagination"]["total"] == 5
|
||||
assert response.json["pagination"]["pages"] == 5
|
||||
|
||||
# get second page, 1 per page
|
||||
response = client.get(
|
||||
f"/v1.0/process-groups/{group_id}/process-models?page=2&per_page=1",
|
||||
headers=logged_in_headers(user),
|
||||
)
|
||||
assert len(response.json["results"]) == 1
|
||||
assert response.json["results"][0]["id"] == "test_model_1"
|
||||
assert response.json["pagination"]["count"] == 1
|
||||
assert response.json["pagination"]["total"] == 5
|
||||
assert response.json["pagination"]["pages"] == 5
|
||||
|
||||
# get first page, 3 per page
|
||||
response = client.get(
|
||||
f"/v1.0/process-groups/{group_id}/process-models?page=1&per_page=3",
|
||||
headers=logged_in_headers(user),
|
||||
)
|
||||
assert len(response.json["results"]) == 3
|
||||
assert response.json["results"][0]["id"] == "test_model_0"
|
||||
assert response.json["pagination"]["count"] == 3
|
||||
assert response.json["pagination"]["total"] == 5
|
||||
assert response.json["pagination"]["pages"] == 2
|
||||
|
||||
# get second page, 3 per page
|
||||
response = client.get(
|
||||
f"/v1.0/process-groups/{group_id}/process-models?page=2&per_page=3",
|
||||
headers=logged_in_headers(user),
|
||||
)
|
||||
# there should only be 2 left
|
||||
assert len(response.json["results"]) == 2
|
||||
assert response.json["results"][0]["id"] == "test_model_3"
|
||||
assert response.json["pagination"]["count"] == 2
|
||||
assert response.json["pagination"]["total"] == 5
|
||||
assert response.json["pagination"]["pages"] == 2
|
||||
|
||||
|
||||
def test_process_group_add(
|
||||
|
@ -237,7 +305,6 @@ def test_process_group_list(
|
|||
for i in range(5):
|
||||
group_id = f"test_process_group_{i}"
|
||||
group_display_name = f"Test Group {i}"
|
||||
|
||||
create_process_group(client, user, group_id, display_name=group_display_name)
|
||||
|
||||
# get all groups
|
||||
|
@ -245,33 +312,45 @@ def test_process_group_list(
|
|||
"/v1.0/process-groups",
|
||||
headers=logged_in_headers(user),
|
||||
)
|
||||
assert len(response.json) == 5
|
||||
assert len(response.json["results"]) == 5
|
||||
assert response.json["pagination"]["count"] == 5
|
||||
assert response.json["pagination"]["total"] == 5
|
||||
assert response.json["pagination"]["pages"] == 1
|
||||
|
||||
# get first page, one per page
|
||||
response = client.get(
|
||||
"/v1.0/process-groups?page=1&per_page=1",
|
||||
headers=logged_in_headers(user),
|
||||
)
|
||||
assert len(response.json) == 1
|
||||
assert response.json[0]["id"] == "test_process_group_0"
|
||||
assert len(response.json["results"]) == 1
|
||||
assert response.json["results"][0]["id"] == "test_process_group_0"
|
||||
assert response.json["pagination"]["count"] == 1
|
||||
assert response.json["pagination"]["total"] == 5
|
||||
assert response.json["pagination"]["pages"] == 5
|
||||
|
||||
# get second page, one per page
|
||||
response = client.get(
|
||||
"/v1.0/process-groups?page=2&per_page=1",
|
||||
headers=logged_in_headers(user),
|
||||
)
|
||||
assert len(response.json) == 1
|
||||
assert response.json[0]["id"] == "test_process_group_1"
|
||||
assert len(response.json["results"]) == 1
|
||||
assert response.json["results"][0]["id"] == "test_process_group_1"
|
||||
assert response.json["pagination"]["count"] == 1
|
||||
assert response.json["pagination"]["total"] == 5
|
||||
assert response.json["pagination"]["pages"] == 5
|
||||
|
||||
# get first page, 3 per page
|
||||
response = client.get(
|
||||
"/v1.0/process-groups?page=1&per_page=3",
|
||||
headers=logged_in_headers(user),
|
||||
)
|
||||
assert len(response.json) == 3
|
||||
assert response.json[0]["id"] == "test_process_group_0"
|
||||
assert response.json[1]["id"] == "test_process_group_1"
|
||||
assert response.json[2]["id"] == "test_process_group_2"
|
||||
assert len(response.json["results"]) == 3
|
||||
assert response.json["results"][0]["id"] == "test_process_group_0"
|
||||
assert response.json["results"][1]["id"] == "test_process_group_1"
|
||||
assert response.json["results"][2]["id"] == "test_process_group_2"
|
||||
assert response.json["pagination"]["count"] == 3
|
||||
assert response.json["pagination"]["total"] == 5
|
||||
assert response.json["pagination"]["pages"] == 2
|
||||
|
||||
# get second page, 3 per page
|
||||
response = client.get(
|
||||
|
@ -279,9 +358,12 @@ def test_process_group_list(
|
|||
headers=logged_in_headers(user),
|
||||
)
|
||||
# there should only be 2 left
|
||||
assert len(response.json) == 2
|
||||
assert response.json[0]["id"] == "test_process_group_3"
|
||||
assert response.json[1]["id"] == "test_process_group_4"
|
||||
assert len(response.json["results"]) == 2
|
||||
assert response.json["results"][0]["id"] == "test_process_group_3"
|
||||
assert response.json["results"][1]["id"] == "test_process_group_4"
|
||||
assert response.json["pagination"]["count"] == 2
|
||||
assert response.json["pagination"]["total"] == 5
|
||||
assert response.json["pagination"]["pages"] == 2
|
||||
|
||||
|
||||
def test_process_model_file_update_fails_if_no_file_given(
|
||||
|
@ -397,7 +479,7 @@ def test_get_process_groups_when_none(
|
|||
user = find_or_create_user()
|
||||
response = client.get("/v1.0/process-groups", headers=logged_in_headers(user))
|
||||
assert response.status_code == 200
|
||||
assert response.json == []
|
||||
assert response.json["results"] == []
|
||||
|
||||
|
||||
def test_get_process_groups_when_there_are_some(
|
||||
|
@ -408,7 +490,10 @@ def test_get_process_groups_when_there_are_some(
|
|||
load_test_spec(app, "hello_world")
|
||||
response = client.get("/v1.0/process-groups", headers=logged_in_headers(user))
|
||||
assert response.status_code == 200
|
||||
assert len(response.json) == 1
|
||||
assert len(response.json["results"]) == 1
|
||||
assert response.json["pagination"]["count"] == 1
|
||||
assert response.json["pagination"]["total"] == 1
|
||||
assert response.json["pagination"]["pages"] == 1
|
||||
|
||||
|
||||
def test_get_process_group_when_found(
|
||||
|
@ -464,7 +549,6 @@ def test_process_instance_create(
|
|||
app: Flask, client: FlaskClient, with_bpmn_file_cleanup: None
|
||||
) -> None:
|
||||
"""Test_process_instance_create."""
|
||||
print("test_process_instance_create: ")
|
||||
test_process_group_id = "runs_without_input"
|
||||
test_process_model_id = "sample"
|
||||
user = find_or_create_user()
|
||||
|
@ -594,8 +678,6 @@ def create_process_model(
|
|||
) -> TestResponse:
|
||||
"""Create_process_model."""
|
||||
process_model_service = ProcessModelService()
|
||||
assert 0 == len(process_model_service.get_specs())
|
||||
assert 0 == len(process_model_service.get_process_groups())
|
||||
|
||||
if process_group_id is None:
|
||||
process_group = ProcessGroup(
|
||||
|
@ -603,7 +685,7 @@ def create_process_model(
|
|||
)
|
||||
process_model_service.add_process_group(process_group)
|
||||
else:
|
||||
process_group = ProcessModelService.get_process_group(process_group_id)
|
||||
process_group = ProcessModelService().get_process_group(process_group_id)
|
||||
|
||||
if process_model_id is None:
|
||||
process_model_id = "make_cookies"
|
||||
|
|
Loading…
Reference in New Issue