mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
fix tests
This commit is contained in:
@@ -89,7 +89,7 @@ def send_sms_to_provider(notification):
|
|||||||
except Exception:
|
except Exception:
|
||||||
# It is our 2facode, maybe
|
# It is our 2facode, maybe
|
||||||
key = f"2facode-{notification.id}".replace(" ", "")
|
key = f"2facode-{notification.id}".replace(" ", "")
|
||||||
recipient = redis_store.raw_get(key)
|
recipient = redis_store.get(key)
|
||||||
|
|
||||||
if recipient:
|
if recipient:
|
||||||
recipient = recipient.decode("utf-8")
|
recipient = recipient.decode("utf-8")
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ def create_2fa_code(
|
|||||||
saved_notification.personalisation = personalisation
|
saved_notification.personalisation = personalisation
|
||||||
key = f"2facode-{saved_notification.id}".replace(" ", "")
|
key = f"2facode-{saved_notification.id}".replace(" ", "")
|
||||||
recipient = str(recipient)
|
recipient = str(recipient)
|
||||||
redis_store.raw_set(key, recipient, ex=60 * 60)
|
redis_store.set(key, recipient, ex=60 * 60)
|
||||||
|
|
||||||
# Assume that we never want to observe the Notify service's research mode
|
# Assume that we never want to observe the Notify service's research mode
|
||||||
# setting for this notification - we still need to be able to log into the
|
# setting for this notification - we still need to be able to log into the
|
||||||
|
|||||||
@@ -133,19 +133,13 @@ class RedisClient:
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def raw_set(self, key, value, ex=None, px=None, nx=False, xx=False):
|
|
||||||
self.redis_store.set(key, value, ex, px, nx, xx)
|
|
||||||
|
|
||||||
def set(
|
def set(
|
||||||
self, key, value, ex=None, px=None, nx=False, xx=False, raise_exception=False
|
self, key, value, ex=None, px=None, nx=False, xx=False, raise_exception=False
|
||||||
):
|
):
|
||||||
key = prepare_value(key)
|
key = prepare_value(key)
|
||||||
value = prepare_value(value)
|
value = prepare_value(value)
|
||||||
if self.active:
|
if self.active:
|
||||||
try:
|
|
||||||
self.redis_store.set(key, value, ex, px, nx, xx)
|
self.redis_store.set(key, value, ex, px, nx, xx)
|
||||||
except Exception as e:
|
|
||||||
self.__handle_exception(e, raise_exception, "set", key)
|
|
||||||
|
|
||||||
def incr(self, key, raise_exception=False):
|
def incr(self, key, raise_exception=False):
|
||||||
key = prepare_value(key)
|
key = prepare_value(key)
|
||||||
@@ -155,16 +149,10 @@ class RedisClient:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.__handle_exception(e, raise_exception, "incr", key)
|
self.__handle_exception(e, raise_exception, "incr", key)
|
||||||
|
|
||||||
def raw_get(self, key):
|
|
||||||
return self.redis_store.get(key)
|
|
||||||
|
|
||||||
def get(self, key, raise_exception=False):
|
def get(self, key, raise_exception=False):
|
||||||
key = prepare_value(key)
|
key = prepare_value(key)
|
||||||
if self.active:
|
if self.active:
|
||||||
try:
|
|
||||||
return self.redis_store.get(key)
|
return self.redis_store.get(key)
|
||||||
except Exception as e:
|
|
||||||
self.__handle_exception(e, raise_exception, "get", key)
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ def test_create_invited_user(
|
|||||||
extra_args,
|
extra_args,
|
||||||
expected_start_of_invite_url,
|
expected_start_of_invite_url,
|
||||||
):
|
):
|
||||||
mocker.patch("app.service_invite.rest.redis_store.raw_set")
|
mocker.patch("app.service_invite.rest.redis_store.set")
|
||||||
mocker.patch("app.service_invite.rest.redis_store.raw_get")
|
mocker.patch("app.service_invite.rest.redis_store.get")
|
||||||
|
|
||||||
mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||||
email_address = "invited_user@service.gov.uk"
|
email_address = "invited_user@service.gov.uk"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import uuid
|
import uuid
|
||||||
from unittest.mock import Mock, call
|
from unittest.mock import Mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
@@ -59,30 +59,6 @@ def failing_redis_client(mocked_redis_client, delete_mock):
|
|||||||
return mocked_redis_client
|
return mocked_redis_client
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_raise_exception_if_raise_set_to_false(
|
|
||||||
app, caplog, failing_redis_client, mocker
|
|
||||||
):
|
|
||||||
mock_logger = mocker.patch("flask.Flask.logger")
|
|
||||||
|
|
||||||
assert failing_redis_client.get("get_key") is None
|
|
||||||
assert failing_redis_client.set("set_key", "set_value") is None
|
|
||||||
assert failing_redis_client.incr("incr_key") is None
|
|
||||||
assert failing_redis_client.exceeded_rate_limit("rate_limit_key", 100, 100) is False
|
|
||||||
assert failing_redis_client.delete("delete_key") is None
|
|
||||||
assert failing_redis_client.delete("a", "b", "c") is None
|
|
||||||
assert failing_redis_client.delete_by_pattern("pattern") == 0
|
|
||||||
|
|
||||||
assert mock_logger.mock_calls == [
|
|
||||||
call.exception("Redis error performing get on get_key"),
|
|
||||||
call.exception("Redis error performing set on set_key"),
|
|
||||||
call.exception("Redis error performing incr on incr_key"),
|
|
||||||
call.exception("Redis error performing rate-limit-pipeline on rate_limit_key"),
|
|
||||||
call.exception("Redis error performing delete on delete_key"),
|
|
||||||
call.exception("Redis error performing delete on a, b, c"),
|
|
||||||
call.exception("Redis error performing delete-by-pattern on pattern"),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_should_raise_exception_if_raise_set_to_true(
|
def test_should_raise_exception_if_raise_set_to_true(
|
||||||
app,
|
app,
|
||||||
failing_redis_client,
|
failing_redis_client,
|
||||||
|
|||||||
Reference in New Issue
Block a user