Skip to content

Commit

Permalink
fix: more tests and almost all static checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLaPiana committed Oct 13, 2023
1 parent 2b64527 commit a8a45a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
14 changes: 6 additions & 8 deletions src/fides/api/api/v1/endpoints/privacy_experience_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import uuid
from functools import lru_cache
from html import escape, unescape
from typing import Dict, List, Optional

Expand All @@ -13,8 +14,6 @@
HTTP_404_NOT_FOUND,
HTTP_422_UNPROCESSABLE_ENTITY,
)
from functools import lru_cache


from fides.api.api import deps
from fides.api.models.privacy_experience import (
Expand All @@ -24,7 +23,6 @@
)
from fides.api.models.privacy_notice import PrivacyNotice
from fides.api.models.privacy_request import ProvidedIdentity
from fides.api.schemas.privacy_experience import PrivacyExperienceResponse
from fides.api.util.api_router import APIRouter
from fides.api.util.consent_util import (
PRIVACY_EXPERIENCE_ESCAPE_FIELDS,
Expand Down Expand Up @@ -124,6 +122,7 @@ def _filter_experiences_by_region_or_country(
return db.query(PrivacyExperience).filter(False)


# TODO: readd the fides limiter
@router.get(
urls.PRIVACY_EXPERIENCE,
status_code=HTTP_200_OK,
Expand Down Expand Up @@ -164,7 +163,6 @@ async def privacy_experience_list(
:param response:
:return:
"""
global PRIVACY_EXPERIENCE_CACHE

# These are the parameters that get used to create the cache.
param_hash_list = [
Expand All @@ -184,13 +182,13 @@ async def privacy_experience_list(
if request.headers.get(BUST_CACHE_HEADER):
PRIVACY_EXPERIENCE_CACHE.clear()

if cache_hash in PRIVACY_EXPERIENCE_CACHE.keys():
if PRIVACY_EXPERIENCE_CACHE.get(cache_hash):
logger.debug("Cache HIT: {}", cache_hash)
response.headers[CACHE_HEADER] = "HIT"
return PRIVACY_EXPERIENCE_CACHE[cache_hash]
else:
logger.debug("Cache MISS: {}", cache_hash)
response.headers[CACHE_HEADER] = "MISS"

logger.debug("Cache MISS: {}", cache_hash)
response.headers[CACHE_HEADER] = "MISS"

fides_user_provided_identity: Optional[ProvidedIdentity] = None
if fides_user_device_id:
Expand Down
1 change: 0 additions & 1 deletion src/fides/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from starlette.background import BackgroundTask
from uvicorn import Config, Server


import fides
from fides.api.app_setup import (
check_redis,
Expand Down
1 change: 1 addition & 0 deletions src/fides/api/util/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def _custom_decoder(json_dict: Dict[str, Any]) -> Dict[str, Any]:
return json_dict


# pylint: disable=abstract-method
class FidesopsRedis(Redis):
"""
An extension to Redis' python bindings to support auto expiring data input. This class
Expand Down
12 changes: 7 additions & 5 deletions tests/ops/api/v1/endpoints/test_privacy_experience_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import annotations

from typing import Dict

import pytest
from starlette.status import HTTP_200_OK
from starlette.testclient import TestClient

from fides.api.api.v1.endpoints.privacy_experience_endpoints import (
_filter_experiences_by_region_or_country,
BUST_CACHE_HEADER,
CACHE_HEADER,
_filter_experiences_by_region_or_country,
)
from fides.api.models.privacy_experience import ComponentType, PrivacyExperience
from fides.api.models.privacy_notice import ConsentMechanism
Expand All @@ -19,6 +20,11 @@ def get_cache_bust_headers() -> Dict:
return {BUST_CACHE_HEADER: "true"}


@pytest.fixture(scope="function")
def url() -> str:
return V1_URL_PREFIX + PRIVACY_EXPERIENCE


class TestGetPrivacyExperiencesCaching:
def test_cache_header_hit(self, url, api_client):
"""Check that the header describing cache hits/misses is working."""
Expand All @@ -37,10 +43,6 @@ def test_bust_cache_header(self, url, api_client):


class TestGetPrivacyExperiences:
@pytest.fixture(scope="function")
def url(self) -> str:
return V1_URL_PREFIX + PRIVACY_EXPERIENCE

def test_get_privacy_experiences_unauthenticated(self, url, api_client):
"""This is a public endpoint"""
resp = api_client.get(url)
Expand Down

0 comments on commit a8a45a2

Please sign in to comment.