Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Retire legacy ingestion column fix (#287)
Madison Swain-Bowden669067d24f1d
diff --git a/openverse_catalog/dags/common/loader/paths.py b/openverse_catalog/dags/common/loader/paths.pyindex d9100f9dd..62b03b6f0 100644--- a/openverse_catalog/dags/common/loader/paths.py+++ b/openverse_catalog/dags/common/loader/paths.py@@ -5,7 +5,6 @@ from datetime import datetime, timedeltafrom typing import Optionalfrom airflow.models import TaskInstance-from common.loader.ingestion_column import _fix_ingestion_columnFAILURE_SUBDIRECTORY = "db_loader_failures"@@ -43,11 +42,7 @@ def stage_oldest_tsv_file(tsv_found = tsv_file_name is not Noneif tsv_found:tsv_version = _get_tsv_version(tsv_file_name)- should_fix_ingestion_type = False- if tsv_version == LEGACY_TSV_VERSION:- should_fix_ingestion_type = True- logger.info(f"Will move and fix ingestion type: {tsv_version}")- _move_file(tsv_file_name, staging_directory, should_fix_ingestion_type)+ _move_file(tsv_file_name, staging_directory)media_type = _extract_media_type(tsv_file_name)ti.xcom_push(key="media_type", value=media_type)ti.xcom_push(key="tsv_version", value=tsv_version)@@ -126,13 +121,11 @@ def _get_oldest_tsv_file(return oldest_file_name-def _move_file(file_path, new_directory, should_fix_ingestion_type=False):+def _move_file(file_path, new_directory):os.makedirs(new_directory, exist_ok=True)new_file_path = os.path.join(new_directory, os.path.basename(file_path))logger.info(f"Moving {file_path} to {new_file_path}")os.rename(file_path, new_file_path)- if should_fix_ingestion_type:- _fix_ingestion_column(new_file_path)def _get_full_tsv_paths(directory):diff --git a/openverse_catalog/dags/common/loader/ingestion_column.py b/openverse_catalog/dags/retired/common/ingestion_column.pysimilarity index 100%rename from openverse_catalog/dags/common/loader/ingestion_column.pyrename to openverse_catalog/dags/retired/common/ingestion_column.pydiff --git a/tests/dags/common/loader/test_ingestion_column.py b/tests/dags/common/loader/test_ingestion_column.pydeleted file mode 100644index 919a663b9..000000000--- a/tests/dags/common/loader/test_ingestion_column.py+++ /dev/null@@ -1,59 +0,0 @@-import logging-from pathlib import Path--from common.loader import ingestion_column as ic---logging.basicConfig(- format="%(asctime)s - %(name)s - %(levelname)s: %(message)s",- level=logging.DEBUG,-)-RESOURCES = Path(__file__).parent.resolve() / "test_resources"---def test_check_and_fix_file_adds_column_to_provider_api_tsv(tmpdir):- old_tsv_file_path = RESOURCES / "old_columns_papis.tsv"- new_tsv_file_path = RESOURCES / "new_columns_papis.tsv"- with open(old_tsv_file_path) as f:- old_tsv_data = f.read()- test_tsv = "test.tsv"- path = tmpdir.join(test_tsv)- backup_path = tmpdir.join(test_tsv + ".old")- path.write(old_tsv_data)- ic._fix_ingestion_column(path.strpath)- actual_tsv_data = path.read()- with open(new_tsv_file_path) as f:- expect_tsv_data = f.read()- assert expect_tsv_data == actual_tsv_data- assert backup_path.read() == old_tsv_data---def test_check_and_fix_file_adds_column_to_common_crawl_tsv(tmpdir):- old_tsv_file_path = RESOURCES / "old_columns_crawl.tsv"- new_tsv_file_path = RESOURCES / "new_columns_crawl.tsv"- with open(old_tsv_file_path) as f:- old_tsv_data = f.read()- test_tsv = "test.tsv"- path = tmpdir.join(test_tsv)- backup_path = tmpdir.join(test_tsv + ".old")- path.write(old_tsv_data)- ic._fix_ingestion_column(path.strpath)- actual_tsv_data = path.read()- with open(new_tsv_file_path) as f:- expect_tsv_data = f.read()- assert expect_tsv_data == actual_tsv_data- assert backup_path.read() == old_tsv_data---def test_check_and_fix_file_leaves_unchanged_when_enough_columns_tsv(tmpdir):- tsv_file_path = RESOURCES / "new_columns_papis.tsv"- with open(tsv_file_path) as f:- tsv_data = f.read()- test_tsv = "test.tsv"- path = tmpdir.join(test_tsv)- backup_path = tmpdir.join(test_tsv + ".old")- path.write(tsv_data)- ic._fix_ingestion_column(path.strpath)- actual_tsv_data = path.read()- assert tsv_data == actual_tsv_data- assert not backup_path.check()