def test_update_review_data(self): self.make_reviewer(self.user) self.login() # create application applicant = self.create_user(username="******", email="*****@*****.**") application = create_application(user=applicant) application.save() # Create review record # Most fields are optional data = { 'application': application, 'status': STATUS_SUBMITTED, 'hotel_amount': Decimal('6.66'), 'registration_amount': Decimal('0.00'), 'travel_amount': Decimal('0.00'), } review = FinancialAidReviewData(**data) review.save() # Now, submit the form to change the status data['status'] = STATUS_REJECTED data['hotel_amount'] = Decimal('7.77') data['review_submit'] = 'review_submit' url = reverse('finaid_review_detail', kwargs={'pk': application.pk}) rsp = self.client.post(url, data, follow=False) self.assertEqual(302, rsp.status_code) new_review = FinancialAidReviewData.objects.get(pk=review.pk) self.assertEqual(STATUS_REJECTED, new_review.status) self.assertEqual(Decimal("7.77"), new_review.hotel_amount)
def test_email_submit(self, mock_send_mass_mail, mock_render): # Actually submit the thing # Create review record # Most fields are optional data = { 'application': self.application, 'status': STATUS_SUBMITTED, 'hotel_amount': Decimal('6.66'), 'registration_amount': Decimal('0.00'), 'travel_amount': Decimal('0.00'), } review = FinancialAidReviewData(**data) review.save() subject = 'TEST SUBJECT' template_text = 'THE TEMPLATE' FinancialAidEmailTemplate.objects.create( name='template', template="wrong template" ) template2 = FinancialAidEmailTemplate.objects.create( name='template', template=template_text, ) data = { 'template': template2.pk, 'subject': subject, } mock_render.return_value = template_text rsp = self.client.post(self.url, data) self.assertEqual(302, rsp.status_code, rsp.content) # we tried to send the right emails expected_msgs = [(subject, template_text, email_address(), [self.user.email])] mock_send_mass_mail.assert_called_with(expected_msgs) # the template was rendered with a good context context = mock_render.call_args[0][0] self.assertEqual(self.application, context['application']) self.assertEqual(review, context['review'])
def test_email_submit(self, mock_send_mass_mail, mock_render): # Actually submit the thing # Create review record # Most fields are optional data = { 'application': self.application, 'status': STATUS_SUBMITTED, 'hotel_amount': Decimal('6.66'), 'registration_amount': Decimal('0.00'), 'travel_amount': Decimal('0.00'), 'tutorial_amount': Decimal('0.00'), } review = FinancialAidReviewData(**data) review.save() subject = 'TEST SUBJECT' template_text = 'THE TEMPLATE' FinancialAidEmailTemplate.objects.create(name='template', template="wrong template") template2 = FinancialAidEmailTemplate.objects.create( name='template', template=template_text, ) data = { 'template': template2.pk, 'subject': subject, } mock_render.return_value = template_text rsp = self.client.post(self.url, data) self.assertEqual(302, rsp.status_code, rsp.content) # we tried to send the right emails expected_msgs = [(subject, template_text, email_address(), [self.user.email])] mock_send_mass_mail.assert_called_with(expected_msgs) # the template was rendered with a good context context = mock_render.call_args[0][0] self.assertEqual(self.application, context['application']) self.assertEqual(review, context['review'])
def test_email_submit(self, mock_send_mass_mail, mock_render): # Actually submit the thing # Create review record # Most fields are optional data = { 'application': self.application, 'status': STATUS_SUBMITTED, 'amount': Decimal('0.00'), } review = FinancialAidReviewData(**data) review.save() subject = 'TEST SUBJECT' template_text = 'THE TEMPLATE' FinancialAidEmailTemplate.objects.create( name='template', template="wrong template" ) template2 = FinancialAidEmailTemplate.objects.create( name='template', template=template_text, ) data = { 'template': template2.pk, 'subject': subject, 'confirm': True, } mock_render.side_effect = [template_text, subject] rsp = self.client.post(self.url, data) self.assertEqual(302, rsp.status_code, rsp.content) # we tried to send the right emails expected_msgs = [(subject, template_text, settings.FINANCIAL_AID_EMAIL, [self.user.email])] mock_send_mass_mail.assert_called_with(expected_msgs) # the template was rendered with a good context context = mock_render.call_args[0][0] self.assertEqual(self.application, context['application']) self.assertEqual(review, context['review'])