Skip to content

Commit

Permalink
test: separate conftest into unit and integration
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasschaub committed Oct 19, 2023
1 parent 0fd136b commit 9bd8d2d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 303 deletions.
268 changes: 0 additions & 268 deletions tests/conftest.py

This file was deleted.

25 changes: 21 additions & 4 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
from testcontainers.redis import RedisContainer
from werkzeug.datastructures import FileStorage

from sketch_map_tool import CELERY_CONFIG
from sketch_map_tool import CELERY_CONFIG, make_flask
from sketch_map_tool import celery_app as smt_celery_app
from sketch_map_tool import flask_app as smt_flask_app
from sketch_map_tool.database import client_celery as db_client_celery
from sketch_map_tool.database import client_flask as db_client_flask
from sketch_map_tool.models import Bbox, PaperFormat, Size
from sketch_map_tool.routes import (
about,
digitize,
digitize_results_post,
help,
index,
)
from tests import FIXTURE_DIR


Expand Down Expand Up @@ -76,12 +82,23 @@ def celery_worker(celery_worker):

@pytest.fixture()
def flask_app():
smt_flask_app.config.update(
app = make_flask()
app.config.update(
{
"TESTING": True,
}
)
yield smt_flask_app
# Register routes to be tested:
app.add_url_rule(
"/digitize/results",
view_func=digitize_results_post,
methods=["POST", "GET"],
)
app.add_url_rule("/digitize", view_func=digitize, methods=["GET"])
app.add_url_rule("/", view_func=index, methods=["GET"])
app.add_url_rule("/about", view_func=about, methods=["GET"])
app.add_url_rule("/help", view_func=help, methods=["GET"])
yield app


@pytest.fixture()
Expand Down
36 changes: 5 additions & 31 deletions tests/integration/test_upload.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,22 @@
import os
from copy import deepcopy
from unittest import mock

import pytest

from sketch_map_tool.exceptions import (
CustomFileNotFoundError,
UploadLimitsExceededError,
)
from sketch_map_tool.exceptions import UploadLimitsExceededError


@mock.patch.dict(os.environ, {"SMT-MAX-NR-SIM-UPLOADS": "2"})
def test_too_many_uploads(flask_client, sketch_map_markings_buffer_1):
def test_max_nr_sim_uploades(flask_client, sketch_map_buffer):
with pytest.raises(UploadLimitsExceededError):
flask_client.post(
"/digitize/results",
data=dict(
file=[
(sketch_map_markings_buffer_1, "file1.png"),
(sketch_map_markings_buffer_1, "file2.png"),
(sketch_map_markings_buffer_1, "file3.png"),
(sketch_map_buffer, "file1.png"),
(sketch_map_buffer, "file2.png"),
(sketch_map_buffer, "file3.png"),
],
),
follow_redirects=True,
)


@mock.patch.dict(os.environ, {"SMT-MAX-NR-SIM-UPLOADS": "2"})
def test_allowed_nr_of_uploads(flask_client, sketch_map_markings_buffer_1):
# Successful run requires that a sketch map
# has been generated on the instance beforehand
try:
flask_client.post(
"/digitize/results",
data=dict(
file=[
(sketch_map_markings_buffer_1, "file1.png"),
(deepcopy(sketch_map_markings_buffer_1), "file2.png"),
],
),
follow_redirects=True,
)
# if we do not have a previous successful run this error will appear;
# uuid of test image not in database, but the exception shows
# that the uploads have been accepted and processed -> relevant code works
except CustomFileNotFoundError:
pass

0 comments on commit 9bd8d2d

Please sign in to comment.