From 254e1b1ef9ed25e3d3bc4666e6075440daf4b5cb Mon Sep 17 00:00:00 2001 From: Vaibhav Mule <vaibhavmule135@gmail.com> Date: Tue, 17 Mar 2020 18:52:34 +0530 Subject: [PATCH] add tests for testing Reminder modal --- hypha/apply/funds/models/reminders.py | 4 ++-- hypha/apply/funds/tests/factories/models.py | 11 ++++++++++ hypha/apply/funds/tests/test_models.py | 23 +++++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/hypha/apply/funds/models/reminders.py b/hypha/apply/funds/models/reminders.py index d48eff662..919699d00 100644 --- a/hypha/apply/funds/models/reminders.py +++ b/hypha/apply/funds/models/reminders.py @@ -34,7 +34,7 @@ class Reminder(models.Model): ) medium = models.CharField( choices=MEDIUM_TYPES.items(), - default='email', + default=EMAIL, max_length=15, ) sent = models.BooleanField(default=False) @@ -55,4 +55,4 @@ class Reminder(models.Model): @property def action_message(self): - return self.ACTIONS[f'{self.action}-{self.medium}'] + return self.ACTION_MESSAGE[f'{self.action}-{self.medium}'] diff --git a/hypha/apply/funds/tests/factories/models.py b/hypha/apply/funds/tests/factories/models.py index 87f7647c8..b45246066 100644 --- a/hypha/apply/funds/tests/factories/models.py +++ b/hypha/apply/funds/tests/factories/models.py @@ -9,6 +9,7 @@ from hypha.apply.funds.models import ( AssignedReviewers, FundType, LabType, + Reminder, RequestForPartners, ReviewerRole, Round, @@ -57,6 +58,7 @@ __all__ = [ 'ReviewerRoleFactory', 'TodayRoundFactory', 'workflow_for_stages', + 'ReminderFactory', ] @@ -351,3 +353,12 @@ class ScreeningStatusFactory(factory.DjangoModelFactory): model = ScreeningStatus title = factory.Iterator(["Bad", "Good"]) + + +class ReminderFactory(factory.DjangoModelFactory): + class Meta: + model = Reminder + + submission = factory.SubFactory('hypha.apply.funds.tests.factories.ApplicationSubmissionFactory') + user = factory.SubFactory(StaffFactory) + time = factory.Sequence(lambda n: datetime.datetime.now() + datetime.timedelta(days=7 * n + 1)) diff --git a/hypha/apply/funds/tests/test_models.py b/hypha/apply/funds/tests/test_models.py index 9d903d7ff..6f13ca5c4 100644 --- a/hypha/apply/funds/tests/test_models.py +++ b/hypha/apply/funds/tests/test_models.py @@ -1,6 +1,6 @@ import itertools import os -from datetime import date, timedelta +from datetime import date, datetime, timedelta from django.conf import settings from django.contrib.auth import get_user_model @@ -11,7 +11,7 @@ from django.test import TestCase, override_settings from django.urls import reverse from hypha.apply.funds.blocks import EmailBlock, FullNameBlock -from hypha.apply.funds.models import ApplicationSubmission +from hypha.apply.funds.models import ApplicationSubmission, Reminder from hypha.apply.funds.workflow import Request from hypha.apply.review.options import MAYBE, NO from hypha.apply.review.tests.factories import ReviewFactory, ReviewOpinionFactory @@ -25,6 +25,7 @@ from .factories import ( FundTypeFactory, InvitedToProposalFactory, LabFactory, + ReminderFactory, RequestForPartnersFactory, RoundFactory, TodayRoundFactory, @@ -655,3 +656,21 @@ class TestForTableQueryset(TestCase): self.assertEqual(submission.review_count, 1) self.assertEqual(submission.review_submitted_count, 1) self.assertEqual(submission.review_recommendation, NO) + + +class TestReminderModel(TestCase): + def setUp(self): + self.submission = ApplicationSubmissionFactory() + + def test_can_save_reminder(self): + reminder = ReminderFactory(submission=self.submission, time=datetime.now()) + self.assertEqual(self.submission, reminder.submission) + self.assertFalse(reminder.sent) + + def test_check_default_action(self): + reminder = ReminderFactory(submission=self.submission, time=datetime.now()) + self.assertEqual(reminder.action, Reminder.REVIEW) + + def test_reminder_action_message(self): + reminder = ReminderFactory(submission=self.submission, time=datetime.now()) + self.assertEqual(reminder.action_message, Reminder.ACTION_MESSAGE[f'{reminder.action}-{reminder.medium}']) -- GitLab