Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Remove legacy provider DAG logic (#849)
Staci Cooper92771e3bd615
diff --git a/DAGs.md b/DAGs.mdindex 0c4b4051a..02b0db93e 100644--- a/DAGs.md+++ b/DAGs.md@@ -100,11 +100,11 @@ The following are DAGs grouped by their primary tag:| DAG ID | Schedule Interval || --- | --- |-| `europeana_reingestion_workflow` | `@weekly` |-| `flickr_reingestion_workflow` | `@weekly` |-| `metropolitan_museum_reingestion_workflow` | `@weekly` |-| `phylopic_reingestion_workflow` | `@weekly` |-| `wikimedia_reingestion_workflow` | `@weekly` |+| [`europeana_reingestion_workflow`](#europeana_reingestion_workflow) | `@weekly` |+| [`flickr_reingestion_workflow`](#flickr_reingestion_workflow) | `@weekly` |+| [`metropolitan_museum_reingestion_workflow`](#metropolitan_museum_reingestion_workflow) | `@weekly` |+| [`phylopic_reingestion_workflow`](#phylopic_reingestion_workflow) | `@weekly` |+| [`wikimedia_reingestion_workflow`](#wikimedia_reingestion_workflow) | `@weekly` |# DAG documentation@@ -114,15 +114,19 @@ The following is documentation associated with each DAG (where available):1. [`airflow_log_cleanup`](#airflow_log_cleanup)1. [`audio_data_refresh`](#audio_data_refresh)1. [`check_silenced_dags`](#check_silenced_dags)+ 1. [`europeana_reingestion_workflow`](#europeana_reingestion_workflow)1. [`europeana_workflow`](#europeana_workflow)+ 1. [`flickr_reingestion_workflow`](#flickr_reingestion_workflow)1. [`flickr_workflow`](#flickr_workflow)1. [`freesound_workflow`](#freesound_workflow)1. [`image_data_refresh`](#image_data_refresh)1. [`inaturalist_workflow`](#inaturalist_workflow)1. [`jamendo_workflow`](#jamendo_workflow)+ 1. [`metropolitan_museum_reingestion_workflow`](#metropolitan_museum_reingestion_workflow)1. [`metropolitan_museum_workflow`](#metropolitan_museum_workflow)1. [`oauth2_authorization`](#oauth2_authorization)1. [`oauth2_token_refresh`](#oauth2_token_refresh)+ 1. [`phylopic_reingestion_workflow`](#phylopic_reingestion_workflow)1. [`phylopic_workflow`](#phylopic_workflow)1. [`pr_review_reminders`](#pr_review_reminders)1. [`rawpixel_workflow`](#rawpixel_workflow)@@ -132,6 +136,7 @@ The following is documentation associated with each DAG (where available):1. [`smithsonian_workflow`](#smithsonian_workflow)1. [`stocksnap_workflow`](#stocksnap_workflow)1. [`wikimedia_commons_workflow`](#wikimedia_commons_workflow)+ 1. [`wikimedia_reingestion_workflow`](#wikimedia_reingestion_workflow)1. [`wordpress_workflow`](#wordpress_workflow)@@ -214,6 +219,19 @@ after the issue has been resolved.The DAG runs weekly.+## `europeana_reingestion_workflow`+++Content Provider: Europeana++ETL Process: Use the API to identify all CC licensed images.++Output: TSV file containing the images and the+ respective meta-data.++Notes: https://www.europeana.eu/api/v2/search.json++## `europeana_workflow`@@ -227,6 +245,20 @@ Output: TSV file containing the images and theNotes: https://www.europeana.eu/api/v2/search.json+## `flickr_reingestion_workflow`+++Content Provider: Flickr++ETL Process: Use the API to identify all CC licensed images.++Output: TSV file containing the images and the+ respective meta-data.++Notes: https://www.flickr.com/help/terms/api+ Rate limit: 3600 requests per hour.++## `flickr_workflow`@@ -335,6 +367,35 @@ Notes: https://api.jamendo.com/v3.0/tracks/channels: 1/2+## `metropolitan_museum_reingestion_workflow`+++Content Provider: Metropolitan Museum of Art++ETL Process: Use the API to identify all CC0 artworks.++Output: TSV file containing the image, their respective+ meta-data.++Notes: https://metmuseum.github.io/#search+ "Please limit requests to 80 requests per second." May need to+ bump up the delay (e.g. to 3 seconds), to avoid of blocking+ during local development testing.++ Some analysis to improve data quality was conducted using a+ separate csv file here: https://github.com/metmuseum/openaccess++ Get a list of object IDs:+ https://collectionapi.metmuseum.org/public/collection/v1/objects?metadataDate=2022-08-10+ Get a specific object:+ https://collectionapi.metmuseum.org/public/collection/v1/objects/1027+ The search functionality requires a specific query (term search)+ in addition to date and public domain. It seems like it won't+ connect with just date and license.+ https://collectionapi.metmuseum.org/public/collection/v1/search?isPublicDomain=true&metadataDate=2022-08-07+++## `metropolitan_museum_workflow`@@ -402,6 +463,20 @@ update the tokens stored in the Variable upon successful refresh.- Freesound+## `phylopic_reingestion_workflow`+++Content Provider: PhyloPic++ETL Process: Use the API to identify all CC licensed images.++Output: TSV file containing the image,+ their respective meta-data.++Notes: http://phylopic.org/api/+ No rate limit specified.++## `phylopic_workflow`@@ -526,6 +601,20 @@ Notes: https://stocksnap.io/api/load-photos/date/desc/1## `wikimedia_commons_workflow`+Content Provider: Wikimedia Commons++ETL Process: Use the API to identify all CC-licensed images.++Output: TSV file containing the image, the respective+ meta-data.++Notes: https://commons.wikimedia.org/wiki/API:Main_page+ No rate limit specified.+++## `wikimedia_reingestion_workflow`++Content Provider: Wikimedia CommonsETL Process: Use the API to identify all CC-licensed images.diff --git a/openverse_catalog/dags/providers/factory_utils.py b/openverse_catalog/dags/providers/factory_utils.pyindex 3fa36f408..469ee6d87 100644--- a/openverse_catalog/dags/providers/factory_utils.py+++ b/openverse_catalog/dags/providers/factory_utils.py@@ -1,48 +1,19 @@-import inspectimport loggingimport timefrom datetime import datetime-from types import FunctionType-from typing import Callable, Sequence+from typing import Sequence, Typefrom airflow.models import DagRun, TaskInstancefrom airflow.utils.dates import cron_presetsfrom common.constants import MediaType-from common.storage.media import MediaStore+from providers.provider_api_scripts.provider_data_ingester import ProviderDataIngesterlogger = logging.getLogger(__name__)-def _load_provider_script_stores(- ingestion_callable: Callable,- media_types: list[MediaType],- **kwargs,-) -> dict[str, MediaStore]:- """- Load the stores associated with a provided ingestion callable. This callable is- assumed to be a legacy provider script and NOT a provider data ingestion class.- """- # Stores exist at the module level, so in order to retrieve the output values we- # must first pull the stores from the module.- module = inspect.getmodule(ingestion_callable)- stores = {}- for media_type in media_types:- store = getattr(module, f"{media_type}_store", None)- if not store:- continue- stores[media_type] = store-- if len(stores) != len(media_types):- raise ValueError(- f"Expected stores in {module.__name__} were missing: "- f"{list(set(media_types) - set(stores))}"- )- return stores--def generate_tsv_filenames(- ingestion_callable: Callable,+ ingester_class: Type[ProviderDataIngester],media_types: list[MediaType],ti: TaskInstance,dag_run: DagRun,@@ -60,20 +31,14 @@ def generate_tsv_filenames(args = args or []logger.info("Pushing available store paths to XComs")- # TODO: This entire branch can be removed when all of the provider scripts have been- # TODO: refactored to subclass ProviderDataIngester.- if isinstance(ingestion_callable, FunctionType):- stores = _load_provider_script_stores(ingestion_callable, media_types)-- else:- # A ProviderDataIngester class was passed instead. First we initialize the- # class, which will initialize the media stores and DelayedRequester.- logger.info(- f"Initializing ProviderIngester {ingestion_callable.__name__} in"- f"order to generate store filenames."- )- ingester = ingestion_callable(dag_run.conf, *args)- stores = ingester.media_stores+ # Initialize the ProviderDataIngester class, which will initialize the+ # DelayedRequester and appropriate media stores.+ logger.info(+ f"Initializing ProviderIngester {ingester_class.__name__} in"+ f"order to generate store filenames."+ )+ ingester = ingester_class(dag_run.conf, *args)+ stores = ingester.media_stores# Push the media store output paths to XComs.for store in stores.values():@@ -84,7 +49,7 @@ def generate_tsv_filenames(def pull_media_wrapper(- ingestion_callable: Callable,+ ingester_class: Type[ProviderDataIngester],media_types: list[MediaType],tsv_filenames: list[str],ti: TaskInstance,@@ -107,23 +72,11 @@ def pull_media_wrapper()logger.info("Setting media stores to the appropriate output filenames")- # TODO: This entire branch can be removed when all of the provider scripts have been- # TODO: refactored to subclass ProviderDataIngester.- if isinstance(ingestion_callable, FunctionType):- # Stores exist at the module level, so in order to set the output values we- # must first pull the stores from the module.- stores = _load_provider_script_stores(ingestion_callable, media_types)- run_func = ingestion_callable- else:- # A ProviderDataIngester class was passed instead. First we initialize the- # class, which will initialize the media stores and DelayedRequester.- logger.info(f"Initializing ProviderIngester {ingestion_callable.__name__}")- ingester = ingestion_callable(dag_run.conf, *args)- stores = ingester.media_stores- run_func = ingester.ingest_records- # args have already been passed into the ingester, we don't need them passed- # in again to the ingest_records function, so we clear the list- args = []+ # Initialize the ProviderDataIngester class, which will initialize the+ # media stores and DelayedRequester.+ logger.info(f"Initializing ProviderIngester {ingester_class.__name__}")+ ingester = ingester_class(dag_run.conf, *args)+ stores = ingester.media_storesfor store, tsv_filename in zip(stores.values(), tsv_filenames):logger.info(@@ -134,10 +87,10 @@ def pull_media_wrapper(logger.info("Beginning ingestion")start_time = time.perf_counter()- # Not passing kwargs here because Airflow throws a bunch of stuff in there that- # none of our provider scripts are expecting.+ # Not passing args or kwargs here because Airflow throws a bunch of stuff in+ # there that none of our provider scripts are expecting.try:- data = run_func(*args)+ data = ingester.ingest_records()finally:end_time = time.perf_counter()# Report durationdiff --git a/openverse_catalog/dags/providers/provider_dag_factory.py b/openverse_catalog/dags/providers/provider_dag_factory.pyindex 78e7c61b5..8b852e83e 100644--- a/openverse_catalog/dags/providers/provider_dag_factory.py+++ b/openverse_catalog/dags/providers/provider_dag_factory.py@@ -124,7 +124,7 @@ def create_ingestion_workflow(identifier = f"{provider_name}_{{{{ ts_nodash }}}}_{day_shift}"ingestion_kwargs = {- "ingestion_callable": conf.ingestion_callable,+ "ingester_class": conf.ingester_class,"media_types": conf.media_types,}if conf.dated:diff --git a/openverse_catalog/dags/providers/provider_reingestion_workflows.py b/openverse_catalog/dags/providers/provider_reingestion_workflows.pyindex 96065de19..0c6fa8406 100644--- a/openverse_catalog/dags/providers/provider_reingestion_workflows.py+++ b/openverse_catalog/dags/providers/provider_reingestion_workflows.py@@ -47,14 +47,19 @@ class ProviderReingestionWorkflow(ProviderWorkflow):def __post_init__(self):if not self.dag_id:- self.dag_id = f"{self.provider_script}_reingestion_workflow"+ # Call super() first to initialize the provider_name+ super().__post_init__()+ # Override the dag_id+ self.dag_id = f"{self.provider_name}_reingestion_workflow"+ return++ super().__post_init__()PROVIDER_REINGESTION_WORKFLOWS = [ProviderReingestionWorkflow(# 60 total reingestion days- provider_script="europeana",- ingestion_callable=EuropeanaDataIngester,+ ingester_class=EuropeanaDataIngester,max_active_tasks=3,pull_timeout=timedelta(hours=12),daily_list_length=7,@@ -63,8 +68,7 @@ PROVIDER_REINGESTION_WORKFLOWS = [),ProviderReingestionWorkflow(# 128 total reingestion days- provider_script="flickr",- ingestion_callable=FlickrDataIngester,+ ingester_class=FlickrDataIngester,pull_timeout=timedelta(minutes=30),daily_list_length=7,weekly_list_length=12,@@ -75,8 +79,7 @@ PROVIDER_REINGESTION_WORKFLOWS = [),ProviderReingestionWorkflow(# 64 total reingestion days- provider_script="metropolitan_museum",- ingestion_callable=MetMuseumDataIngester,+ ingester_class=MetMuseumDataIngester,max_active_tasks=2,pull_timeout=timedelta(hours=12),daily_list_length=6,@@ -86,8 +89,7 @@ PROVIDER_REINGESTION_WORKFLOWS = [),ProviderReingestionWorkflow(# 64 total reingestion days- provider_script="phylopic",- ingestion_callable=PhylopicDataIngester,+ ingester_class=PhylopicDataIngester,max_active_tasks=2,pull_timeout=timedelta(hours=12),daily_list_length=6,@@ -98,10 +100,8 @@ PROVIDER_REINGESTION_WORKFLOWS = [ProviderReingestionWorkflow(# 64 total reingestion daysdag_id="wikimedia_reingestion_workflow",- provider_script="wikimedia_commons",- ingestion_callable=WikimediaCommonsDataIngester,+ ingester_class=WikimediaCommonsDataIngester,pull_timeout=timedelta(minutes=90),- media_types=("image", "audio"),max_active_tasks=2,daily_list_length=6,one_month_list_length=9,diff --git a/openverse_catalog/dags/providers/provider_workflows.py b/openverse_catalog/dags/providers/provider_workflows.pyindex 36af2e256..6887ff941 100644--- a/openverse_catalog/dags/providers/provider_workflows.py+++ b/openverse_catalog/dags/providers/provider_workflows.py@@ -1,4 +1,4 @@-import importlib+import inspectfrom dataclasses import dataclass, fieldfrom datetime import datetime, timedeltafrom typing import Dict, Optional, Sequence, Type@@ -32,22 +32,14 @@ class ProviderWorkflow:"""Required Arguments:- provider_script: string path for the provider_script file whose main- function is to be run. If the optional argument- `dated` is True, then the function must take a- single parameter (date) which will be a string of- the form 'YYYY-MM-DD'. Otherwise, the function- should take no arguments.+ ingester_class: ProviderDataIngester class whose `ingest_records` method is+ to be run.Optional Arguments:dag_id: string giving a unique id of the DAG to be created. Bydefault this will be set to the name of the provider_script,appended with 'workflow'.- ingestion_callable: ProviderDataIngester class whose `ingest_records` method is- to be run. Temporarily, may also be a `main` function for- providers that have not yet been refactored. TODO: Remove this- comment when refactors are completed.default_args: dictionary which is passed to the airflow.dag.DAG__init__ method and used to optionally override theDAG_DEFAULT_ARGS.@@ -71,7 +63,9 @@ class ProviderWorkflow:task may take.doc_md: string which should be used for the DAG's documentation markdownmedia_types: list describing the media type(s) that this provider handles- (e.g. `["audio"]`, `["image", "audio"]`, etc.)+ (e.g. `["audio"]`, `["image", "audio"]`, etc.) By default this+ will be set to the list of media_types supported in the+ ProviderDataIngester.create_preingestion_tasks: callable that returns an airflow task or task group toto run any necessary pre-ingestion tasks, such as loading bulkdata from S3@@ -81,10 +75,7 @@ class ProviderWorkflow:tags: list of any additional tags to apply to the generated DAG"""- provider_script: str- # TODO: update the ingestion_callable to only accept ProviderDataIngester classes- # when all provider scripts have been refactored.- ingestion_callable: Type[ProviderDataIngester] | callable = None+ ingester_class: Type[ProviderDataIngester]dag_id: str = ""default_args: Optional[Dict] = Nonestart_date: datetime = datetime(1970, 1, 1)@@ -95,22 +86,21 @@ class ProviderWorkflow:pull_timeout: timedelta = timedelta(hours=24)load_timeout: timedelta = timedelta(hours=1)doc_md: str = ""- media_types: Sequence[str] = ("image",)+ media_types: Sequence[str] = ()create_preingestion_tasks: Optional[callable] = Nonecreate_postingestion_tasks: Optional[callable] = Nonetags: list[str] = field(default_factory=list)def __post_init__(self):- if not self.dag_id:- self.dag_id = f"{self.provider_script}_workflow"+ # Get the module the ProviderDataIngester was defined in+ provider_script = inspect.getmodule(self.ingester_class)+ self.provider_name = provider_script.__name__.split(".")[-1]- provider_script = importlib.import_module(- f"providers.provider_api_scripts.{self.provider_script}"- )+ if not self.dag_id:+ self.dag_id = f"{self.provider_name}_workflow"- if not self.ingestion_callable:- self.ingestion_callable = provider_script.main- self.tags.append("legacy-ingestion")+ if not self.media_types:+ self.media_types = list(self.ingester_class.providers.keys())if not self.doc_md:self.doc_md = provider_script.__doc__@@ -118,45 +108,37 @@ class ProviderWorkflow:PROVIDER_WORKFLOWS = [ProviderWorkflow(- provider_script="brooklyn_museum",start_date=datetime(2020, 1, 1),- ingestion_callable=BrooklynMuseumDataIngester,+ ingester_class=BrooklynMuseumDataIngester,),ProviderWorkflow(- provider_script="cleveland_museum",- ingestion_callable=ClevelandDataIngester,+ ingester_class=ClevelandDataIngester,start_date=datetime(2020, 1, 15),pull_timeout=timedelta(hours=12),),ProviderWorkflow(- provider_script="europeana",- ingestion_callable=EuropeanaDataIngester,+ ingester_class=EuropeanaDataIngester,start_date=datetime(2022, 10, 27),schedule_string="@daily",dated=True,),ProviderWorkflow(- provider_script="finnish_museums",- ingestion_callable=FinnishMuseumsDataIngester,+ ingester_class=FinnishMuseumsDataIngester,start_date=datetime(2020, 9, 1),pull_timeout=timedelta(days=5),load_timeout=timedelta(days=5),),ProviderWorkflow(- provider_script="flickr",- ingestion_callable=FlickrDataIngester,+ ingester_class=FlickrDataIngester,start_date=datetime(2020, 11, 1),schedule_string="@daily",dated=True,),ProviderWorkflow(- provider_script="freesound",- ingestion_callable=FreesoundDataIngester,- media_types=("audio",),+ ingester_class=FreesoundDataIngester,),ProviderWorkflow(- provider_script="inaturalist",- ingestion_callable=INaturalistDataIngester,+ ingester_class=INaturalistDataIngester,create_preingestion_tasks=INaturalistDataIngester.create_preingestion_tasks,create_postingestion_tasks=INaturalistDataIngester.create_postingestion_tasks,schedule_string="@monthly",@@ -164,74 +146,60 @@ PROVIDER_WORKFLOWS = [load_timeout=timedelta(days=5),),ProviderWorkflow(- provider_script="jamendo",- ingestion_callable=JamendoDataIngester,- media_types=("audio",),+ ingester_class=JamendoDataIngester,),ProviderWorkflow(- provider_script="metropolitan_museum",- ingestion_callable=MetMuseumDataIngester,+ ingester_class=MetMuseumDataIngester,start_date=datetime(2016, 9, 1),schedule_string="@daily",dated=True,pull_timeout=timedelta(hours=12),),ProviderWorkflow(- provider_script="museum_victoria",- ingestion_callable=VictoriaDataIngester,+ ingester_class=VictoriaDataIngester,start_date=datetime(2020, 1, 1),),ProviderWorkflow(- provider_script="nypl",- ingestion_callable=NyplDataIngester,+ ingester_class=NyplDataIngester,start_date=datetime(2020, 1, 1),),ProviderWorkflow(- provider_script="phylopic",- ingestion_callable=PhylopicDataIngester,+ ingester_class=PhylopicDataIngester,start_date=datetime(2011, 2, 7),schedule_string="@daily",dated=True,pull_timeout=timedelta(hours=12),),ProviderWorkflow(- provider_script="rawpixel",- ingestion_callable=RawpixelDataIngester,+ ingester_class=RawpixelDataIngester,pull_timeout=timedelta(hours=12),),ProviderWorkflow(- provider_script="science_museum",- ingestion_callable=ScienceMuseumDataIngester,+ ingester_class=ScienceMuseumDataIngester,start_date=datetime(2020, 1, 1),),ProviderWorkflow(- provider_script="smithsonian",- ingestion_callable=SmithsonianDataIngester,+ ingester_class=SmithsonianDataIngester,start_date=datetime(2020, 1, 1),schedule_string="@weekly",load_timeout=timedelta(hours=4),),ProviderWorkflow(- provider_script="smk",- ingestion_callable=SmkDataIngester,+ ingester_class=SmkDataIngester,start_date=datetime(2020, 1, 1),),ProviderWorkflow(- provider_script="stocksnap",- ingestion_callable=StockSnapDataIngester,+ ingester_class=StockSnapDataIngester,),ProviderWorkflow(- provider_script="wikimedia_commons",- ingestion_callable=WikimediaCommonsDataIngester,+ ingester_class=WikimediaCommonsDataIngester,start_date=datetime(2020, 11, 1),schedule_string="@daily",dated=True,pull_timeout=timedelta(hours=12),- media_types=("image", "audio"),),ProviderWorkflow(- provider_script="wordpress",- ingestion_callable=WordPressDataIngester,+ ingester_class=WordPressDataIngester,pull_timeout=timedelta(hours=12),),]diff --git a/openverse_catalog/docs/adding_a_new_provider.md b/openverse_catalog/docs/adding_a_new_provider.mdindex 59d7f5f86..e2b4860a9 100644--- a/openverse_catalog/docs/adding_a_new_provider.md+++ b/openverse_catalog/docs/adding_a_new_provider.md@@ -71,9 +71,7 @@ Some APIs may not fit perfectly into the established `ProviderDataIngester` pattNow that you have an ingester class, you're ready to wire up a provider DAG in Airflow to automatically pull data and load it into our Catalog database. This is done by defining a `ProviderWorkflow` configuration dataclass and adding it to the `PROVIDER_WORKFLOWS` list in [`provider_workflows.py`](../dags/providers/provider_workflows.py). Our DAG factories will pick up the configuration and generate a complete new DAG in Airflow!At minimum, you'll need to provide the following in your configuration:-* `provider_script`: the name of the file where you defined your `ProviderDataIngester` class-* `ingestion_callable`: the `ProviderDataIngester` class itself-* `media_types`: the media types your provider handles+* `ingester_class`: the `ProviderDataIngester` class itselfExample:```python@@ -85,9 +83,7 @@ from providers.provider_api_scripts.foobar_museum import FoobarMuseumDataIngestePROVIDER_WORKFLOWS = [...ProviderWorkflow(- provider_script='foobar_museum',- ingestion_callable=FooBarMuseumDataIngester,- media_types=("image", "audio",)+ ingester_class=FooBarMuseumDataIngester,)]```diff --git a/tests/dags/providers/test_factory_utils.py b/tests/dags/providers/test_factory_utils.pyindex ff46a6214..1c3646636 100644--- a/tests/dags/providers/test_factory_utils.py+++ b/tests/dags/providers/test_factory_utils.py@@ -2,11 +2,9 @@ from datetime import datetimefrom unittest import mockimport pytest-import requestsfrom airflow.models import DagRun, TaskInstancefrom providers import factory_utils-from tests.dags.common.test_resources import fake_provider_modulefrom tests.dags.common.test_resources.fake_provider_data_ingester import (FakeDataIngester,)@@ -59,57 +57,6 @@ FakeDataIngesterClass.side_effect = _set_up_ingester@pytest.mark.parametrize("func, media_types, stores",[- # Happy path- (fake_provider_module.main, ["image"], [fake_provider_module.image_store]),- # Empty case, no media types provided- (fake_provider_module.main, [], []),- # Provided function doesn't have a store at the module level- pytest.param(- requests.get,- ["image"],- [None],- marks=pytest.mark.raises(- exception=ValueError, match="Expected stores in .*? were missing.*"- ),- ),- # Provided function doesn't have all specified stores- pytest.param(- fake_provider_module.main,- ["image", "other"],- [None, None],- marks=pytest.mark.raises(- exception=ValueError, match="Expected stores in .*? were missing.*"- ),- ),- ],-)-def test_load_provider_script(func, media_types, stores):- actual_stores = factory_utils._load_provider_script_stores(- func,- media_types,- )- assert actual_stores == dict(zip(media_types, stores))--- "func, media_types, stores",- [- ##################################################- # Function-based- ##################################################- # Happy path- (fake_provider_module.main, ["image"], [fake_provider_module.image_store]),- # Multiple types- (- fake_provider_module.main,- ["image", "audio"],- [fake_provider_module.image_store, fake_provider_module.audio_store],- ),- # Empty case, no media types provided- (fake_provider_module.main, [], []),- ##################################################- # Class-based- ################################################### Happy path(FakeDataIngesterClass, ["image", "audio"], list(fdi.media_stores.values())),# No media types provided, ingester class still supplies stores@@ -141,68 +88,14 @@ def test_generate_tsv_filenames(internal_func_mock.assert_not_called()- "func, media_types, tsv_filenames, stores",- [- ##################################################- # Function-based- ##################################################- # Happy path- (- fake_provider_module.main,- ["image"],- ["image_file_000.tsv"],- [fake_provider_module.image_store],- ),- # Multiple types- (- fake_provider_module.main,- ["image", "audio"],- ["image_file_000.tsv", "audio_file_111.tsv"],- [fake_provider_module.image_store, fake_provider_module.audio_store],- ),- # Empty case, no media types provided- (fake_provider_module.main, [], [], []),- # Fails if a mismatched # of items is provided- pytest.param(- fake_provider_module.main,- ["image", "other"],- ["file1.tsv"],- [fake_provider_module.image_store, fake_provider_module.audio_store],- marks=pytest.mark.raises(- exception=ValueError,- match="Provided media types and TSV filenames don't match.*",- ),- ),- pytest.param(- fake_provider_module.main,- ["image"],- ["file1.tsv", "file2.tsv"],- [fake_provider_module.image_store],- marks=pytest.mark.raises(- exception=ValueError,- match="Provided media types and TSV filenames don't match.*",- ),- ),- ##################################################- # Class-based- ##################################################- # Happy path- (- FakeDataIngesterClass,- ["image", "audio"],- ["image_file_000.tsv", "audio_file_111.tsv"],- list(fdi.media_stores.values()),- ),- ],-)-def test_pull_media_wrapper(- func, media_types, tsv_filenames, stores, ti_mock, dagrun_mock, internal_func_mock-):+def test_pull_media_wrapper(ti_mock, dagrun_mock, internal_func_mock):value = 42+ stores = list(fdi.media_stores.values())+ tsv_filenames = ["image_file_000.tsv", "audio_file_111.tsv"]+factory_utils.pull_media_wrapper(- func,- media_types,+ FakeDataIngesterClass,+ ["image", "audio"],tsv_filenames,ti_mock,dagrun_mock,@@ -220,8 +113,7 @@ def test_pull_media_wrapper(internal_func_mock.assert_called_once_with(value)[email protected]("func", [fake_provider_module.main, FakeDataIngesterClass])-def test_pull_media_wrapper_always_pushes_duration(func, ti_mock, dagrun_mock):+def test_pull_media_wrapper_always_pushes_duration(ti_mock, dagrun_mock):error_message = "Whoops!"def _raise_an_error(text):@@ -229,7 +121,7 @@ def test_pull_media_wrapper_always_pushes_duration(func, ti_mock, dagrun_mock):with pytest.raises(ValueError, match=error_message):factory_utils.pull_media_wrapper(- func,+ FakeDataIngesterClass,["image"],["file1.tsv"],ti_mock,diff --git a/tests/dags/providers/test_provider_dag_factory.py b/tests/dags/providers/test_provider_dag_factory.pyindex aa9c0620a..1292fc0b2 100644--- a/tests/dags/providers/test_provider_dag_factory.py+++ b/tests/dags/providers/test_provider_dag_factory.py@@ -11,6 +11,11 @@ from providers.provider_reingestion_workflows import ProviderReingestionWorkflowfrom providers.provider_workflows import ProviderWorkflowfrom tests.conftest import mark_extended+from tests.dags.providers.provider_api_scripts.resources.provider_data_ingester.mock_provider_data_ingester import (+ MockAudioOnlyProviderDataIngester,+ MockImageOnlyProviderDataIngester,+ MockProviderDataIngester,+)DAG_ID = "test_provider_dag_factory"@@ -29,7 +34,7 @@ def clean_db():_clean_dag_from_db()-def _generate_tsv_mock(ingestion_callable, media_types, ti, **kwargs):+def _generate_tsv_mock(ingester_class, media_types, ti, **kwargs):for media_type in media_types:ti.xcom_push(key=f"{media_type}_tsv", value=f"/tmp/{media_type}_does_not_exist.tsv"@@ -61,9 +66,7 @@ def test_skipped_pull_data_runs_successfully(side_effect, clean_db):pull_media_mock.side_effect = side_effectdag = provider_dag_factory.create_provider_api_workflow_dag(ProviderWorkflow(- provider_script="provider_data_ingester",- ingestion_callable=print,- dag_id=DAG_ID,+ ingester_class=MockProviderDataIngester,default_args={"retries": 0, "on_failure_callback": None},schedule_string="@once",)@@ -75,9 +78,7 @@ def test_skipped_pull_data_runs_successfully(side_effect, clean_db):def test_create_day_partitioned_ingestion_dag_with_single_layer_dependencies():dag = provider_dag_factory.create_day_partitioned_reingestion_dag(ProviderReingestionWorkflow(- dag_id="test_dag",- provider_script="provider_data_ingester",- ingestion_callable=print,+ ingester_class=MockImageOnlyProviderDataIngester,),[[1, 2]],)@@ -101,20 +102,18 @@ def test_create_day_partitioned_ingestion_dag_with_single_layer_dependencies():def test_create_day_partitioned_ingestion_dag_with_multi_layer_dependencies():dag = provider_dag_factory.create_day_partitioned_reingestion_dag(ProviderReingestionWorkflow(- dag_id="test_dag",- provider_script="provider_data_ingester",- ingestion_callable=print,+ ingester_class=MockAudioOnlyProviderDataIngester,),[[1, 2], [3, 4, 5]],)- today_id = "ingest_data.generate_image_filename"+ today_id = "ingest_data.generate_audio_filename"gather0_id = "gather_partition_0"- ingest1_id = "ingest_data_day_shift_1.generate_image_filename_day_shift_1"- ingest2_id = "ingest_data_day_shift_2.generate_image_filename_day_shift_2"+ ingest1_id = "ingest_data_day_shift_1.generate_audio_filename_day_shift_1"+ ingest2_id = "ingest_data_day_shift_2.generate_audio_filename_day_shift_2"gather1_id = "gather_partition_1"- ingest3_id = "ingest_data_day_shift_3.generate_image_filename_day_shift_3"- ingest4_id = "ingest_data_day_shift_4.generate_image_filename_day_shift_4"- ingest5_id = "ingest_data_day_shift_5.generate_image_filename_day_shift_5"+ ingest3_id = "ingest_data_day_shift_3.generate_audio_filename_day_shift_3"+ ingest4_id = "ingest_data_day_shift_4.generate_audio_filename_day_shift_4"+ ingest5_id = "ingest_data_day_shift_5.generate_audio_filename_day_shift_5"today_task = dag.get_task(today_id)assert today_task.upstream_task_ids == set()ingest1_task = dag.get_task(ingest1_id)