mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Added tests for setting and fetching from redis respecting the enabled flag.
This commit is contained in:
@@ -1,24 +1,24 @@
|
|||||||
import uuid
|
|
||||||
import os
|
import os
|
||||||
|
import uuid
|
||||||
|
|
||||||
from flask import request, url_for, g, jsonify
|
|
||||||
from flask import Flask, _request_ctx_stack
|
from flask import Flask, _request_ctx_stack
|
||||||
|
from flask import request, url_for, g, jsonify
|
||||||
from flask.ext.sqlalchemy import SQLAlchemy
|
from flask.ext.sqlalchemy import SQLAlchemy
|
||||||
from flask_marshmallow import Marshmallow
|
from flask_marshmallow import Marshmallow
|
||||||
from monotonic import monotonic
|
from monotonic import monotonic
|
||||||
from werkzeug.local import LocalProxy
|
|
||||||
from notifications_utils import logging
|
from notifications_utils import logging
|
||||||
|
from werkzeug.local import LocalProxy
|
||||||
|
|
||||||
from app.celery.celery import NotifyCelery
|
from app.celery.celery import NotifyCelery
|
||||||
from app.clients import Clients
|
from app.clients import Clients
|
||||||
from app.clients.sms.mmg import MMGClient
|
from app.clients.email.aws_ses import AwsSesClient
|
||||||
|
from app.clients.redis.redis_client import RedisClient
|
||||||
from app.clients.sms.firetext import FiretextClient
|
from app.clients.sms.firetext import FiretextClient
|
||||||
from app.clients.sms.loadtesting import LoadtestingClient
|
from app.clients.sms.loadtesting import LoadtestingClient
|
||||||
from app.clients.email.aws_ses import AwsSesClient
|
from app.clients.sms.mmg import MMGClient
|
||||||
from app.clients.statsd.statsd_client import StatsdClient
|
from app.clients.statsd.statsd_client import StatsdClient
|
||||||
from app.clients.redis.redis_client import RedisClient
|
|
||||||
from app.encryption import Encryption
|
from app.encryption import Encryption
|
||||||
|
|
||||||
|
|
||||||
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f"
|
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f"
|
||||||
DATE_FORMAT = "%Y-%m-%d"
|
DATE_FORMAT = "%Y-%m-%d"
|
||||||
|
|
||||||
|
|||||||
0
app/clients/redis/__init__.py
Normal file
0
app/clients/redis/__init__.py
Normal file
@@ -17,4 +17,4 @@ class RedisClient:
|
|||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
if self.active:
|
if self.active:
|
||||||
self.redis_store.get(key)
|
self.redis_store.get(key)
|
||||||
|
|||||||
44
tests/app/clients/test_redis_client.py
Normal file
44
tests/app/clients/test_redis_client.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import pytest
|
||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
|
from app.clients.redis.redis_client import RedisClient
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def enabled_redis_client(notify_api):
|
||||||
|
notify_api.config['REDIS_ENABLED'] = True
|
||||||
|
|
||||||
|
redis_client = RedisClient()
|
||||||
|
redis_client.init_app(notify_api)
|
||||||
|
redis_client.redis_store = Mock()
|
||||||
|
return redis_client
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def disabled_redis_client(notify_api):
|
||||||
|
notify_api.config['REDIS_ENABLED'] = False
|
||||||
|
|
||||||
|
redis_client = RedisClient()
|
||||||
|
redis_client.init_app(notify_api)
|
||||||
|
redis_client.redis_store = Mock()
|
||||||
|
return redis_client
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_not_call_set_if_not_enabled(disabled_redis_client):
|
||||||
|
disabled_redis_client.set('key', 'value')
|
||||||
|
disabled_redis_client.redis_store.set.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_call_set_if_enabled(enabled_redis_client):
|
||||||
|
enabled_redis_client.set('key', 'value')
|
||||||
|
enabled_redis_client.redis_store.set.assert_called_with('key', 'value')
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_not_call_get_if_not_enabled(disabled_redis_client):
|
||||||
|
disabled_redis_client.set('key', 'value')
|
||||||
|
disabled_redis_client.redis_store.get.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_call_get_if_enabled(enabled_redis_client):
|
||||||
|
enabled_redis_client.get('key')
|
||||||
|
enabled_redis_client.redis_store.get.assert_called_with('key')
|
||||||
Reference in New Issue
Block a user