-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fix/tests using called_once_with #2363
Changes from 8 commits
0b4fa4f
bcb270a
d04db82
a7bae4e
9b98f8b
6e0242a
c355c3c
5b2a961
a24242d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ def match_json(request): | |
with notify_api.app_context(): | ||
response = freshdesk.Freshdesk(ContactRequest(**contact_request)).send_ticket() | ||
assert response == 201 | ||
assert email_freshdesk_ticket_mock.not_called() | ||
email_freshdesk_ticket_mock.assert_not_called() | ||
|
||
def test_send_ticket_go_live_request(self, email_freshdesk_ticket_mock, notify_api: Flask): | ||
def match_json(request): | ||
|
@@ -117,7 +117,7 @@ def match_json(request): | |
with notify_api.app_context(): | ||
response = freshdesk.Freshdesk(ContactRequest(**data)).send_ticket() | ||
assert response == 201 | ||
assert email_freshdesk_ticket_mock.not_called() | ||
email_freshdesk_ticket_mock.assert_not_called() | ||
|
||
def test_send_ticket_branding_request(self, email_freshdesk_ticket_mock, notify_api: Flask): | ||
def match_json(request): | ||
|
@@ -179,7 +179,7 @@ def match_json(request): | |
with notify_api.app_context(): | ||
response = freshdesk.Freshdesk(ContactRequest(**data)).send_ticket() | ||
assert response == 201 | ||
assert email_freshdesk_ticket_mock.not_called() | ||
email_freshdesk_ticket_mock.assert_not_called() | ||
|
||
def test_send_ticket_other_category(self, email_freshdesk_ticket_mock, notify_api: Flask): | ||
def match_json(request): | ||
|
@@ -227,7 +227,7 @@ def match_json(request): | |
with notify_api.app_context(): | ||
response = freshdesk.Freshdesk(ContactRequest(**data)).send_ticket() | ||
assert response == 201 | ||
assert email_freshdesk_ticket_mock.not_called() | ||
email_freshdesk_ticket_mock.assert_not_called() | ||
|
||
def test_send_ticket_other(self, email_freshdesk_ticket_mock, notify_api: Flask): | ||
def match_json(request): | ||
|
@@ -258,7 +258,7 @@ def match_json(request): | |
with notify_api.app_context(): | ||
response = freshdesk.Freshdesk(ContactRequest(email_address="[email protected]")).send_ticket() | ||
assert response == 201 | ||
assert email_freshdesk_ticket_mock.not_called() | ||
email_freshdesk_ticket_mock.assert_not_called() | ||
|
||
def test_send_ticket_user_profile(self, email_freshdesk_ticket_mock, notify_api: Flask): | ||
def match_json(request): | ||
|
@@ -294,7 +294,7 @@ def match_json(request): | |
) | ||
).send_ticket() | ||
assert response == 201 | ||
assert email_freshdesk_ticket_mock.not_called() | ||
email_freshdesk_ticket_mock.assert_not_called() | ||
|
||
def test_send_ticket_freshdesk_integration_disabled(self, mocker, email_freshdesk_ticket_mock, notify_api: Flask): | ||
mocked_post = mocker.patch("requests.post") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,28 +19,21 @@ def test_fetch_todays_requested_email_count(self, client, mocker, sample_service | |
|
||
assert actual_result == expected_result | ||
if redis_value is None: | ||
assert mocked_set.called_once_with( | ||
mocked_set.assert_called_once_with( | ||
cache_key, | ||
db_value, | ||
ex=7200, | ||
) | ||
else: | ||
mocked_set.assert_not_called() | ||
|
||
@pytest.mark.parametrize("redis_value, db_value, increment_by", [(None, 5, 5), ("3", 5, 3)]) | ||
def test_increment_todays_requested_email_count(self, mocker, sample_service, redis_value, db_value, increment_by): | ||
def test_increment_todays_requested_email_count(self, client, mocker, sample_service, redis_value, db_value, increment_by): | ||
cache_key = email_daily_count_cache_key(sample_service.id) | ||
mocker.patch("app.redis_store.get", lambda x: redis_value if x == cache_key else None) | ||
mocked_set = mocker.patch("app.redis_store.set") | ||
mocked_incrby = mocker.patch("app.redis_store.incrby") | ||
mocker.patch("app.email_limit_utils.fetch_todays_email_count", return_value=db_value) | ||
|
||
increment_todays_email_count(sample_service.id, increment_by) | ||
|
||
assert mocked_incrby.called_once_with(cache_key, increment_by) | ||
if redis_value is None: | ||
assert mocked_set.called_once_with( | ||
cache_key, | ||
db_value, | ||
) | ||
else: | ||
mocked_set.assert_not_called() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're mocking the code that involves the set ( |
||
with set_config(client.application, "REDIS_ENABLED", True): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't set |
||
increment_todays_email_count(sample_service.id, increment_by) | ||
mocked_incrby.assert_called_once_with(cache_key, increment_by) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,29 +21,22 @@ def test_fetch_todays_requested_sms_count(client, mocker, sample_service, redis_ | |
|
||
assert actual_result == expected_result | ||
if redis_value is None: | ||
assert mocked_set.called_once_with( | ||
mocked_set.assert_called_once_with( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indentation of the |
||
cache_key, | ||
db_value, | ||
ex=7200, | ||
) | ||
else: | ||
mocked_set.assert_not_called() | ||
|
||
|
||
@pytest.mark.parametrize("redis_value,db_value,increment_by", [(None, 5, 5), ("3", 5, 3)]) | ||
def test_increment_todays_requested_sms_count(mocker, sample_service, redis_value, db_value, increment_by): | ||
def test_increment_todays_requested_sms_count(mocker, client, sample_service, redis_value, db_value, increment_by): | ||
cache_key = sms_daily_count_cache_key(sample_service.id) | ||
mocker.patch("app.redis_store.get", lambda x: redis_value if x == cache_key else None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
mocked_set = mocker.patch("app.redis_store.set") | ||
mocked_incrby = mocker.patch("app.redis_store.incrby") | ||
mocker.patch("app.sms_fragment_utils.fetch_todays_requested_sms_count", return_value=db_value) | ||
|
||
increment_todays_requested_sms_count(sample_service.id, increment_by) | ||
|
||
assert mocked_incrby.called_once_with(cache_key, increment_by) | ||
if redis_value is None: | ||
assert mocked_set.called_once_with( | ||
cache_key, | ||
db_value, | ||
) | ||
else: | ||
mocked_set.assert_not_called() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above. |
||
with set_config(client.application, "REDIS_ENABLED", True): | ||
increment_todays_requested_sms_count(sample_service.id, increment_by) | ||
mocked_incrby.assert_called_once_with(cache_key, increment_by) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
mocked_set
variable is being used in the test but it is not defined. You should add back the linemocked_set = mocker.patch("app.redis_store.set")
to ensure the test works correctly.