Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jashan-lco committed Feb 21, 2025
1 parent fbd7055 commit eaba861
Showing 1 changed file with 16 additions and 48 deletions.
64 changes: 16 additions & 48 deletions observation_portal/sciapplications/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django_dramatiq.test import DramatiqTestCase
from django.utils import timezone
from django.core import mail
from django.urls import reverse

from observation_portal.accounts.test_utils import blend_user
from observation_portal.sciapplications.models import ScienceApplication, Call, TimeRequest, CoInvestigator, Instrument, ScienceApplicationReview, ReviewPanel
Expand Down Expand Up @@ -126,6 +127,9 @@ class TestReviewProcess(DramatiqTestCase):
def setUp(self):
super().setUp()

self.user = blend_user(user_params={"is_superuser": True})
self.client.force_login(self.user)

self.semester = mixer.blend(
Semester, start=timezone.now() + timedelta(days=1), end=timezone.now() + timedelta(days=365)
)
Expand All @@ -138,7 +142,7 @@ def setUp(self):
)
mixer.blend(Instrument, call=self.call)

def test_email_sent_to_panelists_on_create(self):
def test_sending_email_to_panelists_with_admin_action(self):
submitter = blend_user()

app = mixer.blend(
Expand All @@ -159,73 +163,37 @@ def test_email_sent_to_panelists_on_create(self):

panel.members.set([user1, user2, user3])

app_review = mixer.blend(
mixer.blend(
ScienceApplicationReview,
science_application=app,
review_panel=panel,
primary_reviewer=user1,
secondary_reviewer=user2,
)

resp = self.client.post(
reverse("admin:sciapplications_reviewpanel_changelist"),
{
"action": "send_review_requested_emails",
"_selected_action": [panel.pk],
},
follow=True,
)

self.assertEqual(app_review.status, ScienceApplicationReview.Status.AWAITING_REVIEWS)
self.assertEqual(resp.status_code, 200)

self.broker.join('default')
self.worker.join()

self.assertEqual(len(mail.outbox), 3)
expected_email_subject = f"Proposal Application Review Requested: {app_review.science_application.title}"
expected_email_subject = f"Proposal Application Review Requested: {panel.name}"
self.assertEqual(set([expected_email_subject]), set(x.subject for x in mail.outbox))
self.assertEqual(
set(u.email for u in panel.members.all()),
set(t for x in mail.outbox for t in x.to)
)


def test_email_not_sent_to_panelists_on_update(self):
submitter = blend_user()

app = mixer.blend(
ScienceApplication,
status=ScienceApplication.SUBMITTED,
submitter=submitter,
call=self.call
)

user1 = blend_user()
user2 = blend_user()
user3 = blend_user()

panel = mixer.blend(
ReviewPanel,
name="panel 1",
)

panel.members.set([user1, user2, user3])

app_review = mixer.blend(
ScienceApplicationReview,
science_application=app,
review_panel=panel,
primary_reviewer=user1,
secondary_reviewer=user2,
)

self.assertEqual(app_review.status, ScienceApplicationReview.Status.AWAITING_REVIEWS)

self.broker.join('default')
self.worker.join()

mail.outbox = []

app_review.technical_review = "test"
app_review.save()

self.broker.join('default')
self.worker.join()

self.assertEqual(len(mail.outbox), 0)

def test_application_is_accepted_on_review_accepted(self):
submitter = blend_user()

Expand Down

0 comments on commit eaba861

Please sign in to comment.