Skip to content

Commit

Permalink
Introduce push_file utils method for tests to ge response objects
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelGeo committed Nov 14, 2024
1 parent 2b8c382 commit 5a8bf13
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions server/mergin/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json
import shutil
from typing import Tuple
import pysqlite3
import uuid
import math
Expand Down Expand Up @@ -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 = {
Expand All @@ -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]
Expand All @@ -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):
Expand Down

0 comments on commit 5a8bf13

Please sign in to comment.