Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Olga Bulat <obulat@gmail.com>
  • Loading branch information
obulat committed Nov 21, 2023
1 parent f4d623c commit 09a1fc4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/test/unit/controllers/elasticsearch/test_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def excluded_providers_cache():
cache_key = "filtered_providers"
excluded_provider = "excluded_provider"
cache_value = [{"provider_identifier": excluded_provider}]
cache_value = [excluded_provider]
cache.set(cache_key, cache_value, timeout=1)

yield excluded_provider
Expand Down
28 changes: 28 additions & 0 deletions api/test/unit/controllers/test_search_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
from unittest import mock
from uuid import uuid4

from django.core.cache import cache

import pook
import pytest
from django_redis import get_redis_connection
from elasticsearch_dsl import Search
from elasticsearch_dsl.query import Terms

from api.controllers import search_controller
from api.controllers.elasticsearch import helpers as es_helpers
from api.controllers.search_controller import FILTERED_PROVIDERS_CACHE_KEY
from api.utils import tallies
from api.utils.dead_link_mask import get_query_hash, save_query_mask
from api.utils.search_context import SearchContext
Expand All @@ -26,6 +30,19 @@
pytestmark = pytest.mark.django_db


@pytest.fixture()
def cache_setter():
keys = []

def _cache_setter(key, value):
keys.append(key)
cache.set(key, value, timeout=1)

yield _cache_setter
for key in keys:
cache.delete(key)


@pytest.mark.parametrize(
"total_hits, real_result_count, page_size, page, expected",
[
Expand Down Expand Up @@ -807,3 +824,14 @@ def _delete_all_results_but_first(_, __, results, ___):
filter_dead=True,
)
assert "Nesting threshold breached" in caplog.text


def test_get_excluded_providers_query_returns_None_when_no_provider_is_excluded():
assert search_controller.get_excluded_providers_query() is None


def test_get_excluded_providers_query_returns_when_cache_is_set(cache_setter):
cache_setter(FILTERED_PROVIDERS_CACHE_KEY, ["provider1", "provider2"])
assert search_controller.get_excluded_providers_query() == Terms(
provider=["provider1", "provider2"]
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
def excluded_providers_cache():
cache_key = "filtered_providers"
excluded_provider = "excluded_provider"
cache_value = [{"provider_identifier": excluded_provider}]
cache_value = [excluded_provider]
cache.set(cache_key, cache_value, timeout=1)

yield excluded_provider
Expand Down

0 comments on commit 09a1fc4

Please sign in to comment.