Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Rename ContentProvider to ContentSource (#4402)
Olga Bulatb26624446572
diff --git a/api/api/admin/__init__.py b/api/api/admin/__init__.pyindex 11fbda698..77abef2df 100644--- a/api/api/admin/__init__.py+++ b/api/api/admin/__init__.py@@ -1,11 +1,10 @@-from django.conf import settingsfrom django.contrib import adminfrom api.admin.media_report import register as register_media_reportfrom api.admin.oauth import register as register_oauthfrom api.admin.site import openverse_adminfrom api.admin.user import register as register_user-from api.models.models import ContentProvider+from api.models.models import ContentSourceadmin.site = openverse_admin@@ -15,8 +14,8 @@ for register in [register_media_report, register_oauth, register_user]:register(admin.site)[email protected](ContentProvider)-class ProviderAdmin(admin.ModelAdmin):- list_display = ("provider_name", "provider_identifier", "media_type")- search_fields = ("provider_name", "provider_identifier")- ordering = ("media_type", "provider_name")[email protected](ContentSource)+class SourceAdmin(admin.ModelAdmin):+ list_display = ("source_name", "source_identifier", "media_type")+ search_fields = ("source_name", "source_identifier")+ ordering = ("media_type", "source_name")diff --git a/api/api/controllers/elasticsearch/related.py b/api/api/controllers/elasticsearch/related.pyindex ef7b2f4e4..7b6b1b914 100644--- a/api/api/controllers/elasticsearch/related.py+++ b/api/api/controllers/elasticsearch/related.py@@ -7,7 +7,7 @@ from elasticsearch_dsl.response import Hitfrom api.controllers.elasticsearch.helpers import get_es_response, get_query_slicefrom api.controllers.search_controller import (_post_process_results,- get_excluded_providers_query,+ get_excluded_sources_query,)@@ -55,8 +55,8 @@ def related_media(uuid: str, index: str, filter_dead: bool) -> list[Hit]:related_query["should"].append(Q("terms", tags__name__keyword=tags))# Exclude the dynamically disabled sources.- if excluded_providers_query := get_excluded_providers_query():- related_query["must_not"].append(excluded_providers_query)+ if excluded_sources_query := get_excluded_sources_query():+ related_query["must_not"].append(excluded_sources_query)# Exclude the current item and mature content.related_query["must_not"].extend([Q("term", mature=True), Q("term", identifier=uuid)]diff --git a/api/api/controllers/search_controller.py b/api/api/controllers/search_controller.pyindex c831375cd..f7098256e 100644--- a/api/api/controllers/search_controller.py+++ b/api/api/controllers/search_controller.py@@ -41,12 +41,8 @@ logger = structlog.get_logger(__name__)NESTING_THRESHOLD = config("POST_PROCESS_NESTING_THRESHOLD", cast=int, default=5)SOURCE_CACHE_TIMEOUT = 60 * 60 * 4 # 4 hoursFILTER_CACHE_TIMEOUT = 30-FILTERED_PROVIDERS_CACHE_KEY = "filtered_providers"-FILTERED_PROVIDERS_CACHE_VERSION = 2-THUMBNAIL = "thumbnail"-URL = "url"-PROVIDER = "provider"-QUERY_SPECIAL_CHARACTER_ERROR = "Unescaped special characters are not allowed."+FILTERED_SOURCES_CACHE_KEY = "filtered_sources"+FILTERED_SOURCES_CACHE_VERSION = 1DEFAULT_BOOST = 10000DEFAULT_SEARCH_FIELDS = ["title", "description", "tags.name"]DEFAULT_SQS_FLAGS = "AND|NOT|PHRASE|WHITESPACE"@@ -162,42 +158,43 @@ def _post_process_results(return results[:page_size]-def get_excluded_providers_query() -> Q | None:+def get_excluded_sources_query() -> Q | None:"""Hide data sources from the catalog dynamically.- To exclude a provider, set ``filter_content`` to ``True`` in the- ``ContentProvider`` model in Django admin.- The list of ``provider_identifier``s is cached in Redis with- `:FILTERED_PROVIDERS_CACHE_VERSION:FILTERED_PROVIDERS_CACHE_KEY` key.+ To exclude a source, set ``filter_content`` to ``True`` in the+ ``ContentSource`` model in Django admin.+ The list of ``source_identifier``s is cached in Redis with+ `:FILTERED_SOURCES_CACHE_VERSION:FILTERED_SOURCES_CACHE_KEY` key."""try:- filtered_providers = cache.get(- key=FILTERED_PROVIDERS_CACHE_KEY, version=FILTERED_PROVIDERS_CACHE_VERSION+ filtered_sources = cache.get(+ key=FILTERED_SOURCES_CACHE_KEY, version=FILTERED_SOURCES_CACHE_VERSION)+ logger.info(f"Filtered sources from cache: {filtered_sources}")except ConnectionError:- logger.warning("Redis connect failed, cannot get cached filtered providers.")- filtered_providers = None+ logger.warning("Redis connect failed, cannot get cached filtered sources.")+ filtered_sources = None- if not filtered_providers:- filtered_providers = list(- models.ContentProvider.objects.filter(filter_content=True).values_list(- "provider_identifier", flat=True+ if not filtered_sources:+ filtered_sources = list(+ models.ContentSource.objects.filter(filter_content=True).values_list(+ "source_identifier", flat=True))try:cache.set(- key=FILTERED_PROVIDERS_CACHE_KEY,- version=FILTERED_PROVIDERS_CACHE_VERSION,+ key=FILTERED_SOURCES_CACHE_KEY,+ version=FILTERED_SOURCES_CACHE_VERSION,timeout=FILTER_CACHE_TIMEOUT,- value=filtered_providers,+ value=filtered_sources,)except ConnectionError:- logger.warning("Redis connect failed, cannot cache filtered providers.")+ logger.warning("Redis connect failed, cannot cache filtered sources.")- if filtered_providers:- return Q("terms", provider=filtered_providers)+ if filtered_sources:+ return Q("terms", source=filtered_sources)return None@@ -285,8 +282,8 @@ def build_search_query(if not search_params.validated_data["include_sensitive_results"]:search_queries["must_not"].append(Q("term", mature=True))# Exclude dynamically disabled sources (see Redis cache)- if excluded_providers_query := get_excluded_providers_query():- search_queries["must_not"].append(excluded_providers_query)+ if excluded_sources_query := get_excluded_sources_query():+ search_queries["must_not"].append(excluded_sources_query)# Search either by generic multimatch or by "advanced search" with# individual field-level queries specified.@@ -395,8 +392,8 @@ def build_collection_query(if not include_sensitive_by_params:search_query["must_not"].append({"term": {"mature": True}})- if excluded_providers_query := get_excluded_providers_query():- search_query["must_not"].append(excluded_providers_query)+ if excluded_sources_query := get_excluded_sources_query():+ search_query["must_not"].append(excluded_sources_query)return Q("bool", **search_query)@@ -563,7 +560,7 @@ def get_sources(index):if isinstance(sources, list) or cache_fetch_failed:sources = Nonetry:- # Invalidate old provider format.+ # Invalidate old source format.cache.delete(key=source_cache_name)except ConnectionError:logger.warning("Redis connect failed, cannot invalidate cached sources.")diff --git a/api/api/docs/audio_docs.py b/api/api/docs/audio_docs.pyindex 00f3bf5c9..0bd3ab93d 100644--- a/api/api/docs/audio_docs.py+++ b/api/api/docs/audio_docs.py@@ -39,7 +39,7 @@ from api.serializers.audio_serializers import (AudioWaveformSerializer,)from api.serializers.media_serializers import MediaThumbnailRequestSerializer-from api.serializers.provider_serializers import ProviderSerializer+from api.serializers.source_serializers import SourceSerializerserializer = AudioSearchRequestSerializer(context={"media_type": "audio"})@@ -71,13 +71,13 @@ search = custom_extend_schema(stats = custom_extend_schema(desc=f"""- Get a list of all content providers and their respective number of+ Get a list of all content sources and their respective number ofaudio files in the Openverse catalog.- By using this endpoint, you can obtain info about content providers such- as {fields_to_md(ProviderSerializer.Meta.fields)}.""",+ By using this endpoint, you can obtain info about content sources such+ as {fields_to_md(SourceSerializer.Meta.fields)}.""",res={- 200: (ProviderSerializer(many=True), audio_stats_200_example),+ 200: (SourceSerializer(many=True), audio_stats_200_example),401: (AuthenticationFailed, None),},eg=[audio_stats_curl],diff --git a/api/api/docs/image_docs.py b/api/api/docs/image_docs.pyindex 24a484c0d..9d0837cbb 100644--- a/api/api/docs/image_docs.py+++ b/api/api/docs/image_docs.py@@ -41,7 +41,7 @@ from api.serializers.image_serializers import (OembedSerializer,)from api.serializers.media_serializers import MediaThumbnailRequestSerializer-from api.serializers.provider_serializers import ProviderSerializer+from api.serializers.source_serializers import SourceSerializerserializer = ImageSearchRequestSerializer(context={"media_type": "image"})@@ -74,13 +74,13 @@ search = custom_extend_schema(stats = custom_extend_schema(desc=f"""- Get a list of all content providers and their respective number of+ Get a list of all content sources and their respective number ofimages in the Openverse catalog.- By using this endpoint, you can obtain info about content providers such- as {fields_to_md(ProviderSerializer.Meta.fields)}.""",+ By using this endpoint, you can obtain info about content sources such+ as {fields_to_md(SourceSerializer.Meta.fields)}.""",res={- 200: (ProviderSerializer(many=True), image_stats_200_example),+ 200: (SourceSerializer(many=True), image_stats_200_example),401: (AuthenticationFailed, None),},eg=[image_stats_curl],diff --git a/api/api/migrations/0066_rename_contentprovider_to_contentsource.py b/api/api/migrations/0066_rename_contentprovider_to_contentsource.pynew file mode 100644index 000000000..14cff56b7--- /dev/null+++ b/api/api/migrations/0066_rename_contentprovider_to_contentsource.py@@ -0,0 +1,36 @@+# Generated by Django 4.2.11 on 2024-05-29 12:39++from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [+ ("api", "0065_throttledapplication_privileges"),+ ]++ operations = [+ migrations.RenameModel(old_name="ContentProvider", new_name="ContentSource"),+ migrations.AlterField(+ model_name="contentsource",+ name="provider_identifier",+ field=models.CharField(+ db_column="provider_identifier", max_length=50, unique=True+ ),+ ),+ migrations.RenameField(+ model_name="contentsource",+ old_name="provider_identifier",+ new_name="source_identifier",+ ),+ migrations.AlterField(+ model_name="contentsource",+ name="provider_name",+ field=models.CharField(db_column="provider_name", max_length=250),+ ),+ migrations.RenameField(+ model_name="contentsource",+ old_name="provider_name",+ new_name="source_name",+ ),+ ]diff --git a/api/api/models/__init__.py b/api/api/models/__init__.pyindex bb99e0809..3c629b7ac 100644--- a/api/api/models/__init__.py+++ b/api/api/models/__init__.py@@ -28,7 +28,7 @@ from api.models.media import (OTHER,PENDING,)-from api.models.models import ContentProvider, Tag+from api.models.models import ContentSource, Tagfrom api.models.moderation import UserPreferencesfrom api.models.oauth import (OAuth2Registration,diff --git a/api/api/models/models.py b/api/api/models/models.pyindex dc01ea31b..18e254936 100644--- a/api/api/models/models.py+++ b/api/api/models/models.py@@ -4,24 +4,26 @@ from api.constants.media_types import MEDIA_TYPE_CHOICESfrom api.models.base import OpenLedgerModel-class ContentProvider(models.Model):+class ContentSource(models.Model):"""- A content provider instance can only be mapped to a single media type.+ A content source instance can only be mapped to a single media type.- For providers providing multiple media types, use different identifiers while+ For sources with multiple media types, use different identifiers whilekeeping the same display name.For example,- Wikimedia for audio can have- ``provider_identifier`` as "wikimedia_audio" and- ``provider_name`` as "Wikimedia"+ ``source_identifier`` as "wikimedia_audio" and+ ``source_name`` as "Wikimedia"- Wikimedia for images can have- ``provider_identifier`` as "wikimedia_images" or "wikimedia" and- ``provider_name`` as "Wikimedia"+ ``source_identifier`` as "wikimedia_images" or "wikimedia" and+ ``source_name`` as "Wikimedia""""- provider_identifier = models.CharField(max_length=50, unique=True)- provider_name = models.CharField(max_length=250)+ source_identifier = models.CharField(+ max_length=50, unique=True, db_column="provider_identifier"+ )+ source_name = models.CharField(max_length=250, db_column="provider_name")created_on = models.DateTimeField(auto_now=False)domain_name = models.CharField(max_length=500)filter_content = models.BooleanField(diff --git a/api/api/serializers/provider_serializers.py b/api/api/serializers/source_serializers.pysimilarity index 77%rename from api/api/serializers/provider_serializers.pyrename to api/api/serializers/source_serializers.pyindex e10235dfc..26b4b017e 100644--- a/api/api/serializers/provider_serializers.py+++ b/api/api/serializers/source_serializers.py@@ -2,21 +2,21 @@ from rest_framework import serializersfrom drf_spectacular.utils import extend_schema_serializer-from api.models import ContentProvider+from api.models import ContentSource@extend_schema_serializer(many=True,deprecate_fields=["logo_url"],)-class ProviderSerializer(serializers.ModelSerializer):+class SourceSerializer(serializers.ModelSerializer):source_name = serializers.CharField(- source="provider_identifier",+ source="source_identifier",help_text="The source of the media, e.g. flickr",)display_name = serializers.CharField(- source="provider_name",- help_text="The name of content provider, e.g. Flickr",+ source="source_name",+ help_text="The name of content source, e.g. Flickr",)source_url = serializers.URLField(source="domain_name",@@ -34,7 +34,7 @@ class ProviderSerializer(serializers.ModelSerializer):return Noneclass Meta:- model = ContentProvider+ model = ContentSourcefields = ["source_name","display_name",@@ -45,4 +45,4 @@ class ProviderSerializer(serializers.ModelSerializer):def get_media_count(self, obj) -> int:source_counts = self.context.get("source_counts")- return source_counts.get(obj.provider_identifier)+ return source_counts.get(obj.source_identifier)diff --git a/api/api/views/media_views.py b/api/api/views/media_views.pyindex daf6688a8..f9eca0f38 100644--- a/api/api/views/media_views.py+++ b/api/api/views/media_views.py@@ -14,10 +14,10 @@ from asgiref.sync import sync_to_asyncfrom api.constants.media_types import MediaTypefrom api.controllers import search_controllerfrom api.controllers.elasticsearch.related import related_media-from api.models import ContentProvider+from api.models import ContentSourcefrom api.models.media import AbstractMediafrom api.serializers import media_serializers-from api.serializers.provider_serializers import ProviderSerializer+from api.serializers.source_serializers import SourceSerializerfrom api.utils import image_proxyfrom api.utils.pagination import StandardPaginationfrom api.utils.search_context import SearchContext@@ -73,18 +73,18 @@ class MediaViewSet(AsyncViewSetMixin, AsyncAPIView, ReadOnlyModelViewSet):def get_queryset(self):# The alternative to a sub-query would be using `extra` to do a join- # to the content provider table and filtering `filter_content`. However,- # that assumes that a content provider entry exists, which is not necessarily- # the case. We often don't add a content provider until after works from- # new providers are available in the API, and sometimes not even then.- # Search returns results with providers that do not have a ContentProvider+ # to the content source table and filtering `filter_content`. However,+ # that assumes that a content source entry exists, which is not necessarily+ # the case. We often don't add a content source until after works from+ # new source are available in the API, and sometimes not even then.+ # Search returns results with sources that do not have a ContentSource# table entry. Therefore, to maintain that assumption, a subquery is the only# workable approach, as Django's `extra` does not provide any facility for# handling null relations on the join.return self.model_class.objects.exclude(- provider__in=ContentProvider.objects.filter(- filter_content=True- ).values_list("provider_identifier")+ source__in=ContentSource.objects.filter(filter_content=True).values_list(+ "source_identifier"+ ))aget_object = sync_to_async(ReadOnlyModelViewSet.get_object)@@ -203,17 +203,17 @@ class MediaViewSet(AsyncViewSetMixin, AsyncAPIView, ReadOnlyModelViewSet):# Extra actions- @action(detail=False, serializer_class=ProviderSerializer, pagination_class=None)+ @action(detail=False, serializer_class=SourceSerializer, pagination_class=None)def stats(self, *_, **__):source_counts = search_controller.get_sources(self.default_index)context = self.get_serializer_context() | {"source_counts": source_counts,}- providers = ContentProvider.objects.filter(+ sources = ContentSource.objects.filter(media_type=self.default_index, filter_content=False)- serializer = self.get_serializer(providers, many=True, context=context)+ serializer = self.get_serializer(sources, many=True, context=context)return Response(serializer.data)@action(detail=True)diff --git a/api/latest_migrations/api b/api/latest_migrations/apiindex 81926666a..2f6c01764 100644--- a/api/latest_migrations/api+++ b/api/latest_migrations/api@@ -2,4 +2,4 @@# If you have a merge conflict in this file, it means you need to run:# manage.py makemigrations --merge# in order to resolve the conflict between migrations.-0065_throttledapplication_privileges+0066_contentsource_delete_contentproviderdiff --git a/api/test/factory/models/content_provider.py b/api/test/factory/models/content_provider.pydeleted file mode 100644index 04871aee5..000000000--- a/api/test/factory/models/content_provider.py+++ /dev/null@@ -1,8 +0,0 @@-from factory.django import DjangoModelFactory--from api.models import ContentProvider---class ContentProviderFactory(DjangoModelFactory):- class Meta:- model = ContentProviderdiff --git a/api/test/factory/models/content_source.py b/api/test/factory/models/content_source.pynew file mode 100644index 000000000..940b5d5fd--- /dev/null+++ b/api/test/factory/models/content_source.py@@ -0,0 +1,8 @@+from factory.django import DjangoModelFactory++from api.models import ContentSource+++class ContentSourceFactory(DjangoModelFactory):+ class Meta:+ model = ContentSourcediff --git a/api/test/unit/controllers/elasticsearch/test_related.py b/api/test/unit/controllers/elasticsearch/test_related.pyindex 23370f3dd..a894784d0 100644--- a/api/test/unit/controllers/elasticsearch/test_related.py+++ b/api/test/unit/controllers/elasticsearch/test_related.py@@ -5,8 +5,8 @@ import pytestfrom api.controllers.elasticsearch import relatedfrom api.controllers.search_controller import (- FILTERED_PROVIDERS_CACHE_KEY,- FILTERED_PROVIDERS_CACHE_VERSION,+ FILTERED_SOURCES_CACHE_KEY,+ FILTERED_SOURCES_CACHE_VERSION,)from test.factory.es_http import (MOCK_LIVE_RESULT_URL_PREFIX,@@ -20,22 +20,22 @@ pytestmark = pytest.mark.django_db@pytest.fixture-def excluded_providers_cache(django_cache, monkeypatch):+def excluded_sources_cache(django_cache, monkeypatch):cache = django_cachemonkeypatch.setattr("api.controllers.search_controller.cache", cache)- excluded_provider = "excluded_provider"- cache_value = [excluded_provider]+ excluded_source = "excluded_source"+ cache_value = [excluded_source]cache.set(- key=FILTERED_PROVIDERS_CACHE_KEY,- version=FILTERED_PROVIDERS_CACHE_VERSION,+ key=FILTERED_SOURCES_CACHE_KEY,+ version=FILTERED_SOURCES_CACHE_VERSION,value=cache_value,timeout=1,)- yield excluded_provider+ yield excluded_source- cache.delete(FILTERED_PROVIDERS_CACHE_KEY, version=FILTERED_PROVIDERS_CACHE_VERSION)+ cache.delete(FILTERED_SOURCES_CACHE_KEY, version=FILTERED_SOURCES_CACHE_VERSION)@mock.patch(@@ -47,7 +47,7 @@ def test_related_media(wrapped_related_results,image_media_type_config,settings,- excluded_providers_cache,+ excluded_sources_cache,):image = ImageFactory.create()@@ -83,7 +83,7 @@ def test_related_media("query": {"bool": {"must_not": [- {"terms": {"provider": [excluded_providers_cache]}},+ {"terms": {"source": [excluded_sources_cache]}},{"term": {"mature": True}},{"term": {"identifier": image.identifier}},],diff --git a/api/test/unit/controllers/test_search_controller.py b/api/test/unit/controllers/test_search_controller.pyindex c25107ade..6344e2144 100644--- a/api/test/unit/controllers/test_search_controller.py+++ b/api/test/unit/controllers/test_search_controller.py@@ -16,7 +16,10 @@ from structlog.testing import capture_logsfrom api.controllers import search_controllerfrom api.controllers.elasticsearch import helpers as es_helpers-from api.controllers.search_controller import FILTERED_PROVIDERS_CACHE_KEY+from api.controllers.search_controller import (+ FILTERED_SOURCES_CACHE_KEY,+ FILTERED_SOURCES_CACHE_VERSION,+)from api.utils import talliesfrom api.utils.dead_link_mask import get_query_hash, save_query_maskfrom api.utils.search_context import SearchContext@@ -25,7 +28,7 @@ from test.factory.es_http import (MOCK_LIVE_RESULT_URL_PREFIX,create_mock_es_http_image_search_response,)-from test.factory.models.content_provider import ContentProviderFactory+from test.factory.models.content_source import ContentSourceFactorypytestmark = pytest.mark.django_db@@ -838,39 +841,39 @@ def test_excessive_recursion_in_post_process(@cache_availability_params@pytest.mark.parametrize("excluded_count, result",- [(2, Terms(provider=["provider1", "provider2"])), (0, None)],+ [(2, Terms(source=["source1", "source2"])), (0, None)],)-def test_get_excluded_providers_query_returns_excluded(+def test_get_excluded_sources_query_returns_excluded(excluded_count, result, is_cache_reachable, cache_name, request):cache = request.getfixturevalue(cache_name)if is_cache_reachable:cache.set(- key=FILTERED_PROVIDERS_CACHE_KEY,- version=2,+ key=FILTERED_SOURCES_CACHE_KEY,+ version=FILTERED_SOURCES_CACHE_VERSION,timeout=30,- value=[f"provider{i + 1}" for i in range(excluded_count)],+ value=[f"source{i + 1}" for i in range(excluded_count)],)else:for i in range(excluded_count):- ContentProviderFactory.create(+ ContentSourceFactory.create(created_on=datetime.datetime.now(),- provider_identifier=f"provider{i + 1}",- provider_name=f"Provider {i + 1}",+ source_identifier=f"source{i + 1}",+ source_name=f"Source {i + 1}",filter_content=True,)with capture_logs() as cap_logs:- assert search_controller.get_excluded_providers_query() == result+ assert search_controller.get_excluded_sources_query() == resultif not is_cache_reachable:messages = [record["event"] for record in cap_logs]assert all(message in messagesfor message in [- "Redis connect failed, cannot get cached filtered providers.",- "Redis connect failed, cannot cache filtered providers.",+ "Redis connect failed, cannot get cached filtered sources.",+ "Redis connect failed, cannot cache filtered sources.",])@@ -880,9 +883,7 @@ def test_get_sources_returns_stats(is_cache_reachable, cache_name, request, caplcache = request.getfixturevalue(cache_name)if is_cache_reachable:- cache.set(- "sources-multimedia", value={"provider_1": "1000", "provider_2": "1000"}- )+ cache.set("sources-multimedia", value={"source_1": "1000", "source_2": "1000"})with capture_logs() as cap_logs, patch("api.controllers.search_controller.get_raw_es_response",@@ -890,16 +891,16 @@ def test_get_sources_returns_stats(is_cache_reachable, cache_name, request, capl"aggregations": {"unique_sources": {"buckets": [- {"key": "provider_1", "doc_count": 1000},- {"key": "provider_2", "doc_count": 1000},+ {"key": "source_1", "doc_count": 1000},+ {"key": "source_2", "doc_count": 1000},]}}},):assert search_controller.get_sources("multimedia") == {- "provider_1": 1000,- "provider_2": 1000,+ "source_1": 1000,+ "source_2": 1000,}if not is_cache_reachable:diff --git a/api/test/unit/controllers/test_search_controller_search_query.py b/api/test/unit/controllers/test_search_controller_search_query.pyindex 69f2de860..541443833 100644--- a/api/test/unit/controllers/test_search_controller_search_query.py+++ b/api/test/unit/controllers/test_search_controller_search_query.py@@ -5,8 +5,8 @@ from api.constants.parameters import COLLECTION, TAGfrom api.controllers import search_controllerfrom api.controllers.search_controller import (DEFAULT_SQS_FLAGS,- FILTERED_PROVIDERS_CACHE_KEY,- FILTERED_PROVIDERS_CACHE_VERSION,+ FILTERED_SOURCES_CACHE_KEY,+ FILTERED_SOURCES_CACHE_VERSION,)@@ -14,22 +14,22 @@ pytestmark = pytest.mark.django_db@pytest.fixture-def excluded_providers_cache(django_cache, monkeypatch):+def excluded_sources_cache(django_cache, monkeypatch):cache = django_cachemonkeypatch.setattr("api.controllers.search_controller.cache", cache)- excluded_provider = "excluded_provider"- cache_value = [excluded_provider]+ excluded_source = "excluded_source"+ cache_value = [excluded_source]cache.set(- key=FILTERED_PROVIDERS_CACHE_KEY,- version=FILTERED_PROVIDERS_CACHE_VERSION,+ key=FILTERED_SOURCES_CACHE_KEY,+ version=FILTERED_SOURCES_CACHE_VERSION,value=cache_value,timeout=1,)- yield excluded_provider+ yield excluded_source- cache.delete(FILTERED_PROVIDERS_CACHE_KEY, version=FILTERED_PROVIDERS_CACHE_VERSION)+ cache.delete(FILTERED_SOURCES_CACHE_KEY, version=FILTERED_SOURCES_CACHE_VERSION)def test_create_search_query_empty(media_type_config, anon_request):@@ -287,9 +287,9 @@ def test_create_search_query_q_search_license_license_type_creates_2_terms_filte}-def test_create_search_query_empty_with_dynamically_excluded_providers(+def test_create_search_query_empty_with_dynamically_excluded_sources(image_media_type_config,- excluded_providers_cache,+ excluded_sources_cache,anon_request,):serializer = image_media_type_config.search_request_serializer(@@ -307,7 +307,7 @@ def test_create_search_query_empty_with_dynamically_excluded_providers(assert actual_query_clauses == {"must_not": [{"term": {"mature": True}},- {"terms": {"provider": [excluded_providers_cache]}},+ {"terms": {"source": [excluded_sources_cache]}},],"must": [{"match_all": {}}],"should": [diff --git a/api/test/unit/views/test_media_views.py b/api/test/unit/views/test_media_views.pyindex 15c211cad..f55c807df 100644--- a/api/test/unit/views/test_media_views.py+++ b/api/test/unit/views/test_media_views.py@@ -5,7 +5,7 @@ from uuid import uuid4import pytestimport pytest_django.asserts-from api.models.models import ContentProvider+from api.models.models import ContentSource@pytest.mark.django_db@@ -51,14 +51,14 @@ def test_retrieve_query_count(api_client, media_type_config):"filter_content", (True, False), ids=lambda x: "filtered" if x else "not_filtered")@pytest.mark.django_db-def test_get_queryset_provider_filtering(api_client, media_type_config, filter_content):- test_provider = "test_provider_filtering_provider"- media = media_type_config.model_factory.create(provider=test_provider)+def test_get_queryset_source_filtering(api_client, media_type_config, filter_content):+ test_source = "test_source_filtering_source"+ media = media_type_config.model_factory.create(source=test_source)- ContentProvider.objects.create(+ ContentSource.objects.create(created_on=datetime.now(tz=timezone.utc),- provider_identifier=test_provider,- provider_name="Test Provider",+ source_identifier=test_source,+ source_name="Test Source",domain_name="https://example.com",filter_content=filter_content,)@@ -69,23 +69,20 @@ def test_get_queryset_provider_filtering(api_client, media_type_config, filter_c@pytest.mark.django_db-def test_get_queryset_does_not_exclude_works_without_contentprovider_entry(+def test_get_queryset_does_not_exclude_works_without_contentsource_entry(api_client, media_type_config):"""- Search only excludes works when a content provider entry exists AND that+ Search only excludes works when a content source entry exists AND thatentry has `filter_content=True`. Critically this means it will include works- from providers that do not have a content provider entry. To ensure the individual+ from sources that do not have a content source entry. To ensure the individualmedia views follow the same behaviour, this test retrieves a single media result- assigned to a provider that has no content provider entry.+ assigned to a source that has no content source entry."""- test_provider = f"test_provider_{uuid4()}"- media = media_type_config.model_factory.create(provider=test_provider)+ test_source = f"test_source_{uuid4()}"+ media = media_type_config.model_factory.create(source=test_source)- assert (- ContentProvider.objects.filter(provider_identifier=test_provider).exists()- is False- )+ assert ContentSource.objects.filter(source_identifier=test_source).exists() is Falseres = api_client.get(f"/v1/{media_type_config.url_prefix}/{media.identifier}/")