From 5a8bf131c17e8a4effdcc524f1ef9409f2a7a00e Mon Sep 17 00:00:00 2001 From: "marcel.kocisek" Date: Thu, 14 Nov 2024 16:28:20 +0100 Subject: [PATCH] Introduce push_file utils method for tests to ge response objects --- server/mergin/tests/utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/server/mergin/tests/utils.py b/server/mergin/tests/utils.py index 8ba33953..ab52c574 100644 --- a/server/mergin/tests/utils.py +++ b/server/mergin/tests/utils.py @@ -4,6 +4,7 @@ import json import shutil +from typing import Tuple import pysqlite3 import uuid import math @@ -213,8 +214,7 @@ def file_info(project_dir, path, chunk_size=1024): } -def upload_file_to_project(project, filename, client): - """Add test file to project - start, upload and finish push process""" +def push_file(project, filename, client) -> Tuple: file = os.path.join(test_project_dir, filename) assert os.path.exists(file) changes = { @@ -231,6 +231,8 @@ def upload_file_to_project(project, filename, client): data=json.dumps(data, cls=DateTimeEncoder).encode("utf-8"), headers=json_headers, ) + if resp.status_code != 200: + return (resp, None) upload_id = resp.json["transaction"] changes = data["changes"] file_meta = changes["added"][0] @@ -241,7 +243,14 @@ def upload_file_to_project(project, filename, client): client.post( url, data=f_data, headers={"Content-Type": "application/octet-stream"} ) - assert client.post(f"/v1/project/push/finish/{upload_id}").status_code == 200 + return (resp, client.post(f"/v1/project/push/finish/{upload_id}")) + + +def upload_file_to_project(project, filename, client): + """Add test file to project - start, upload and finish push process""" + resp_push_start, resp_push_finish = push_file(project, filename, client) + assert resp_push_finish.status_code == 200 + assert resp_push_start.status_code == 200 def gpkgs_are_equal(file1, file2):