Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documents-api-fix #1970

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deployment/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ services:
API_LOG_ROTATION_WHEN: ${API_LOG_ROTATION_WHEN:-d}
API_LOG_ROTATION_INTERVAL: ${API_LOG_ROTATION_INTERVAL:-1}
API_LOG_BACKUP_COUNT: ${API_LOG_BACKUP_COUNT:-7}
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}

stdin_open: true # -i
tty: true # -t
Expand Down
9 changes: 9 additions & 0 deletions forms-flow-documents/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ services:
API_LOG_ROTATION_WHEN: ${API_LOG_ROTATION_WHEN:-d}
API_LOG_ROTATION_INTERVAL: ${API_LOG_ROTATION_INTERVAL:-1}
API_LOG_BACKUP_COUNT: ${API_LOG_BACKUP_COUNT:-7}
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}
stdin_open: true # -i
tty: true # -t
networks:
- forms-flow-webapi-network
- redis

redis:
image: "redis:alpine"
ports:
- "6379:6379"
networks:
- forms-flow-webapi-network

networks:
forms-flow-webapi-network:
Expand Down
1 change: 1 addition & 0 deletions forms-flow-documents/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ typing_extensions==4.10.0
urllib3==2.2.1
wsproto==1.2.0
zstandard==0.22.0
setuptools==69.0.2
3 changes: 3 additions & 0 deletions forms-flow-documents/src/formsflow_documents/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class _Config: # pylint: disable=too-few-public-methods
str(os.getenv("MULTI_TENANCY_ENABLED", default="false")).lower() == "true"
)

# REDIS CONFIG
REDIS_URL = os.getenv("REDIS_URL", "redis://redis:6379/0")

# Configure LOG
CONFIGURE_LOGS = str(os.getenv("CONFIGURE_LOGS", default="true")).lower() == "true"

Expand Down
27 changes: 27 additions & 0 deletions forms-flow-documents/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Common setup and fixtures for the pytest suite used by this service."""
import pytest
from unittest.mock import patch
from formsflow_api_utils.utils import jwt as _jwt
from formsflow_api_utils.utils.startup import setup_jwt_manager

Expand Down Expand Up @@ -76,3 +77,29 @@ def docker_compose_files(pytestconfig):
return [
os.path.join(str(pytestconfig.rootdir), "tests/docker", "docker-compose.yml")
]


@pytest.fixture
def mock_redis_client():
"""Mock Redis client that will act as a simple key-value store."""

class MockRedis:
"""Mock redis class."""

def __init__(self):
self.store = {}

def set(self, key, value, ex=None):
self.store[key] = value

def get(self, key):
return self.store.get(key)

mock_redis = MockRedis()

# Patch the RedisManager.get_client to return the mock_redis
with patch(
"formsflow_api_utils.utils.caching.RedisManager.get_client",
return_value=mock_redis,
) as _mock: # noqa
yield mock_redis
2 changes: 1 addition & 1 deletion forms-flow-documents/tests/unit/api/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class TestFormResourceRenderPdf:
"""Test suite for the render endpoint."""

def test_render_template(self, app, client, jwt):
def test_render_template(self, app, client, jwt, mock_redis_client):
"""Assert that API /render when passed with token returns 200 status code."""
with app.app_context():
token = get_token(jwt)
Expand Down
4 changes: 2 additions & 2 deletions forms-flow-documents/tests/unit/services/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestPDFService:

template = get_test_template()

def test_get_render_data_without_template_and_template_variable(self, app):
def test_get_render_data_without_template_and_template_variable(self, app, mock_redis_client):
"""Test get_render_data method for the request without template and template variable."""
with app.app_context():
service = PDFService(form_id="1234", submission_id="1234567")
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_get_render_data_with_template_and_template_variable(self, app):
service.delete_template(template_name)
service.delete_template(template_var_name)

def test_get_render_data_with_template_and_without_template_variable(self, app):
def test_get_render_data_with_template_and_without_template_variable(self, app, mock_redis_client):
"""Test get_render_data method for the request with template and without template variable."""
with app.app_context():
service = PDFService(form_id="1234", submission_id="1234567")
Expand Down
Loading