Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoacierno committed Jan 28, 2024
1 parent e5beff0 commit 1755801
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
9 changes: 8 additions & 1 deletion backend/grants/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
"approved_type": Grant.ApprovedType.ticket_only,
"travelling_from": "IT",
"expected_ticket_amount": 100,
"expected_accommodation_amount": 400,
"expected_travel_amount": 0,
},
{
"approved_type": Grant.ApprovedType.ticket_accommodation,
"travelling_from": "FR",
"expected_ticket_amount": 100,
"expected_accommodation_amount": 0,
"expected_travel_amount": 0,
},
Expand Down Expand Up @@ -108,7 +115,7 @@ def test_can_manually_change_amounts():
)

grant.status = Grant.Status.approved
grant.save()
grant.save(update_fields=["status"])

assert grant.ticket_amount == 100
assert grant.accommodation_amount == 0
Expand Down
57 changes: 56 additions & 1 deletion backend/grants/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import datetime
from unittest.mock import patch
from unittest.mock import patch, ANY
from conferences.tests.factories import DeadlineFactory
from django.test import override_settings

import pytest
from users.tests.factories import UserFactory
Expand All @@ -8,10 +10,12 @@

from grants.tests.factories import GrantFactory
from grants.tasks import (
send_grant_reply_waiting_list_update_email,
send_grant_voucher_email,
send_grant_reply_approved_email,
send_grant_reply_rejected_email,
send_grant_reply_waiting_list_email,
send_new_plain_chat,
)
from grants.models import Grant

Expand Down Expand Up @@ -236,3 +240,54 @@ def test_handle_grant_approved_ticket_only_reply_sent(
},
reply_to=["grants@pycon.it"],
)


def test_send_grant_reply_waiting_list_update_email(sent_emails):
grant = GrantFactory()
DeadlineFactory(
conference=grant.conference,
start=datetime(2023, 3, 1, 23, 59, tzinfo=timezone.utc),
type="custom",
name={
"en": "Update Grants in Waiting List",
"it": "Update Grants in Waiting List",
},
)

send_grant_reply_waiting_list_update_email(
grant_id=grant.id,
)

assert len(sent_emails) == 1
assert sent_emails[0]["template"] == EmailTemplate.GRANT_WAITING_LIST_UPDATE
assert sent_emails[0]["to"] == grant.user.email


@override_settings(PLAIN_API=None)
def test_send_new_plain_chat_when_disabled(mocker):
plain_mock = mocker.patch("grants.tasks.plain")
user = UserFactory()

send_new_plain_chat(
user_id=user.id,
message="Hello",
)

plain_mock.send_message.assert_not_called()


@override_settings(PLAIN_API="https://invalid/api")
def test_send_new_plain_chat(mocker):
plain_mock = mocker.patch("grants.tasks.plain")
user = UserFactory()

send_new_plain_chat(
user_id=user.id,
message="Hello",
)

plain_mock.send_message.assert_called_once_with(
user,
title=ANY,
message="Hello",
)

0 comments on commit 1755801

Please sign in to comment.