Skip to content

Commit

Permalink
Move move fixtures for valid rows for docs with translations to conftest
Browse files Browse the repository at this point in the history
  • Loading branch information
katybaulch committed Sep 5, 2024
1 parent ab3271c commit d60aec2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .trunk/configs/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"capsys",
"dtypes",
"isin",
"pydantic"
"pydantic",
"getfixturevalue"
],
"flagWords": ["hte"],
"suggestionsTimeout": 5000
Expand Down
56 changes: 56 additions & 0 deletions tests/unit_tests/parsers/document/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pandas as pd
import pytest

from gcf_data_mapper.enums.document import (
RequiredDocumentColumns,
RequiredFamilyDocumentColumns,
TranslatedDocumentColumns,
)


@pytest.fixture
def mock_valid_doc_row_with_one_translation():
return pd.Series(
{
RequiredFamilyDocumentColumns.APPROVED_REF.value: "ref123",
RequiredFamilyDocumentColumns.PROJECTS_ID.value: "proj123",
RequiredDocumentColumns.ID.value: "doc123",
RequiredDocumentColumns.TYPE.value: "type123",
RequiredDocumentColumns.TITLE.value: "title123",
TranslatedDocumentColumns.SOURCE_URL.value: "link123",
TranslatedDocumentColumns.TRANSLATED_FILES.value: "http://example.com",
TranslatedDocumentColumns.TRANSLATED_TITLES.value: "title123",
}
)


@pytest.fixture
def mock_valid_doc_row_with_many_translations():
return pd.Series(
{
RequiredFamilyDocumentColumns.APPROVED_REF.value: "ref123",
RequiredFamilyDocumentColumns.PROJECTS_ID.value: "proj123",
RequiredDocumentColumns.ID.value: "doc123",
RequiredDocumentColumns.TYPE.value: "type123",
RequiredDocumentColumns.TITLE.value: "title123",
TranslatedDocumentColumns.SOURCE_URL.value: "link123,link456,link789",
TranslatedDocumentColumns.TRANSLATED_FILES.value: "http://example.com|http://example.org|http://example.co.uk",
TranslatedDocumentColumns.TRANSLATED_TITLES.value: "title123|title456|title789",
}
)


@pytest.fixture
def mock_valid_doc_row_with_two_translations():
return pd.Series(
{
RequiredFamilyDocumentColumns.APPROVED_REF.value: "ref123",
RequiredFamilyDocumentColumns.PROJECTS_ID.value: "proj123",
RequiredDocumentColumns.ID.value: "doc123",
RequiredDocumentColumns.TYPE.value: "type123",
RequiredDocumentColumns.TITLE.value: "title123",
TranslatedDocumentColumns.SOURCE_URL.value: "link123,link456",
TranslatedDocumentColumns.TRANSLATED_FILES.value: "http://example.com|http://example.org",
TranslatedDocumentColumns.TRANSLATED_TITLES.value: "title123|title456",
}
)
31 changes: 12 additions & 19 deletions tests/unit_tests/parsers/document/test_map_translated_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,23 @@

from gcf_data_mapper.enums.document import (
RequiredDocumentColumns,
RequiredFamilyDocumentColumns,
TranslatedDocumentColumns,
)
from gcf_data_mapper.parsers.document import map_translated_files


@pytest.fixture
def mock_row():
return pd.Series(
{
RequiredFamilyDocumentColumns.APPROVED_REF.value: "ref123",
RequiredFamilyDocumentColumns.PROJECTS_ID.value: "proj123",
RequiredDocumentColumns.ID.value: "doc123",
RequiredDocumentColumns.TYPE.value: "type123",
RequiredDocumentColumns.TITLE.value: "title123",
TranslatedDocumentColumns.SOURCE_URL.value: "link123",
TranslatedDocumentColumns.TRANSLATED_FILES.value: "http://example.com|http://example.org",
}
)


def test_translated_files_mapped_to_documents(mock_row):
result = map_translated_files(mock_row)
assert len(result) == 2
@pytest.mark.parametrize(
("valid_doc_row", "expected_objects"),
[
("mock_valid_doc_row_with_one_translation", 1),
("mock_valid_doc_row_with_two_translations", 2),
("mock_valid_doc_row_with_many_translations", 2),
],
)
def test_translated_files_mapped_to_documents(valid_doc_row, expected_objects, request):
result = map_translated_files(request.getfixturevalue(valid_doc_row))
assert result is not None
assert len(result) == expected_objects


def test_translated_files_not_mapped_with_invalid_urls():
Expand Down
29 changes: 10 additions & 19 deletions tests/unit_tests/parsers/document/test_process_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,20 @@
from gcf_data_mapper.enums.document import (
RequiredDocumentColumns,
RequiredFamilyDocumentColumns,
TranslatedDocumentColumns,
)
from gcf_data_mapper.parsers.document import process_row


@pytest.fixture
def mock_row():
return pd.Series(
{
RequiredFamilyDocumentColumns.APPROVED_REF.value: "ref123",
RequiredFamilyDocumentColumns.PROJECTS_ID.value: "proj123",
RequiredDocumentColumns.ID.value: "doc123",
RequiredDocumentColumns.TYPE.value: "type123",
RequiredDocumentColumns.TITLE.value: "title123",
TranslatedDocumentColumns.SOURCE_URL.value: "link123,link456",
TranslatedDocumentColumns.TRANSLATED_FILES.value: "url123|url456",
TranslatedDocumentColumns.TRANSLATED_TITLES.value: "title123|title456",
}
)


def test_process_row_success(mock_row):
result = process_row(mock_row, debug=False)
@pytest.mark.parametrize(
"valid_doc_row",
[
"mock_valid_doc_row_with_one_translation",
"mock_valid_doc_row_with_two_translations",
"mock_valid_doc_row_with_many_translations",
],
)
def test_process_row_success(valid_doc_row, request):
result = process_row(request.getfixturevalue(valid_doc_row), debug=False)
assert isinstance(result, list)


Expand Down

0 comments on commit d60aec2

Please sign in to comment.