Skip to content

Commit

Permalink
Move test data to temporary media root for every test
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanw committed Oct 31, 2022
1 parent 8ca5dd3 commit 9480560
Show file tree
Hide file tree
Showing 21 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion test_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
FILINGCABINET_MEDIA_PRIVATE_PREFIX = "docs-private"

MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "tests" / "testdata"
TEST_DATA_ROOT = BASE_DIR / "tests" / "testdata"
STATIC_ROOT = BASE_DIR / "static"

MIDDLEWARE = [
Expand Down
23 changes: 11 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ def long_timeout_page(browser):


@pytest.fixture()
def processed_document():
path = "docs-private/ef/39/5b/ef395b666014488aa551e431e653a1d9"
def processed_document(tmp_path, dummy_user, settings):
path = "{}/ef/39/5b/ef395b666014488aa551e431e653a1d9".format(
settings.FILINGCABINET_MEDIA_PUBLIC_PREFIX
)
shutil.copytree(
settings.TEST_DATA_ROOT / "example-doc",
tmp_path / path,
)
settings.MEDIA_ROOT = tmp_path

doc = DocumentFactory(
title="Test Document",
description="Description of Test Document",
uid=uuid.UUID("ef395b66-6014-488a-a551-e431e653a1d9"),
pdf_file=f"{path}/example.pdf",
file_size=260082,
user=dummy_user,
pending=False,
num_pages=4,
language="de",
Expand Down Expand Up @@ -98,13 +107,3 @@ def document_portal(processed_document, document_portal_factory):
processed_document.save()

yield portal


@pytest.fixture()
def tmp_media_path(settings, tmp_path):
shutil.copytree(
settings.MEDIA_ROOT / settings.FILINGCABINET_MEDIA_PRIVATE_PREFIX,
tmp_path / settings.FILINGCABINET_MEDIA_PRIVATE_PREFIX,
)
settings.MEDIA_ROOT = tmp_path
yield tmp_path
3 changes: 2 additions & 1 deletion tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@


@pytest.mark.django_db
def test_import_command(tmp_media_path, processed_document, document_collection):
@pytest.mark.slow
def test_import_command(processed_document, document_collection):
directory = PosixPath(processed_document.pdf_file.path).parent
metadata = {
"title": "Test title",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_zip_unpacking(dummy_user, document_collection_factory, settings, tmp_pa

@pytest.mark.django_db
@pytest.mark.slow
def test_processing_document(processed_document, tmp_media_path):
def test_processing_document(processed_document):
page = processed_document.pages.all()[0]
page.pending = True
page.save()
Expand Down
File renamed without changes.

0 comments on commit 9480560

Please sign in to comment.