Skip to content

Commit

Permalink
test(routes): add line to png to test detection
Browse files Browse the repository at this point in the history
* test(routes): add line to png to test detection

* add comment
  • Loading branch information
ElJocho authored Oct 19, 2023
1 parent bab711e commit b795d8b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/integration/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,28 @@ def sketch_map_pdf(uuid, tmp_path_factory) -> Path:
return fn


def draw_line_on_png(png):
"""Draw a single straight line in the middle of a png"""
width, height = png.width, png.height
line_start_x = int(width / 4)
line_end_x = int(width / 2)
middle_y = int(height / 2)
for x in range(line_start_x, line_end_x):
for y in range(middle_y - 4, middle_y):
png.set_pixel(x, y, (138, 29, 12))
return png


@pytest.fixture(scope="session")
def sketch_map_png(sketch_map_pdf, tmp_path_factory, uuid):
with open(sketch_map_pdf, "rb") as file:
sketch_map_pdf = file.read()
pdf = fitz.open(stream=sketch_map_pdf)
page = pdf.load_page(0)
png = page.get_pixmap()

png = draw_line_on_png(png) # mock sketches on map

path = tmp_path_factory.getbasetemp() / uuid / "sketch-map.png"
png.save(path, output="png")
return path
Expand Down Expand Up @@ -169,6 +184,7 @@ def test_api_download_uuid_vector_result(uuid_result_uploaded):

assert response.status_code == 200
json = geojson.loads(geojson.dumps(response.json()))
assert len(json["features"]) > 0
assert json.is_valid


Expand Down Expand Up @@ -221,11 +237,11 @@ def raster_result(uuid_result_uploaded, tmp_path_factory):
if not os.path.exists(tmp_path_factory.getbasetemp() / uuid_result_uploaded):
fn = (
tmp_path_factory.mktemp(uuid_result_uploaded, numbered=False)
/ "raster-results.tif"
/ "raster-results.zip"
)
else:
fn = (
tmp_path_factory.getbasetemp() / uuid_result_uploaded / "raster-results.tif"
tmp_path_factory.getbasetemp() / uuid_result_uploaded / "raster-results.zip"
)
with open(fn, "wb") as file:
file.write(response.content)
Expand Down

0 comments on commit b795d8b

Please sign in to comment.