def send_alert(bookmark, date):
    '''Send alert for bookmark for given date.'''

    try:
        msg = bookmark_utils.make_ncso_concession_email(bookmark, tag=date)
        msg = EmailMessage.objects.create_from_message(msg)
        msg.send()
        logger.info('Sent concession alert to %s about %s' % (msg.to, bookmark.id))
    except bookmark_utils.BadAlertImageError as e:
        logger.exception(e)
    def test_make_ncso_concessions_email_for_all_england(self, attach_image):
        bookmark = NCSOConcessionBookmark.objects.create(user=self.user, )

        msg = bookmark_utils.make_ncso_concession_email(bookmark)

        self.assertEqual(
            msg.subject,
            'Your update about NCSO Concessions for the NHS in England')
        self.assertIn('published for **July 2018**', msg.body)
        self.assertIn(u'cost the NHS in England an additional **\xa31,269**',
                      msg.body)

        html = msg.alternatives[0][0]
        self.assertInHTML('<b>July 2018</b>', html)
    def test_make_ncso_concessions_email_for_ccg(self, attach_image):
        bookmark = NCSOConcessionBookmark.objects.create(user=self.user,
                                                         pct=self.ccg)

        msg = bookmark_utils.make_ncso_concession_email(bookmark)

        self.assertEqual(msg.subject,
                         "Your update about Price Concessions for CCG 0")
        self.assertIn("published for **July 2018**", msg.body)
        additional_cost = round(
            ncso_spending_for_entity(self.ccg, "ccg", 1)[0]["additional_cost"])
        self.assertIn("**\xa3{:,}**".format(additional_cost), msg.body)

        html = msg.alternatives[0][0]
        self.assertInHTML("<b>July 2018</b>", html)
    def test_make_ncso_concessions_email_for_practice(self, attach_image):
        bookmark = NCSOConcessionBookmark.objects.create(
            user=self.user,
            practice=self.practice,
        )

        msg = bookmark_utils.make_ncso_concession_email(bookmark)

        self.assertEqual(msg.subject,
                         'Your update about NCSO Concessions for Practice 2')
        self.assertIn('published for **July 2018**', msg.body)
        self.assertIn('prescribed at Practice 2', msg.body)
        self.assertIn(u'an additional **\xa3206**', msg.body)

        html = msg.alternatives[0][0]
        self.assertInHTML('<b>July 2018</b>', html)
Example #5
0
    def test_make_ncso_concessions_email_for_practice(self, attach_image):
        bookmark = NCSOConcessionBookmark.objects.create(
            user=self.user, practice=self.practice)

        msg = bookmark_utils.make_ncso_concession_email(bookmark)

        self.assertEqual(msg.subject,
                         "Your update about NCSO Concessions for Practice 2")
        self.assertIn("published for **July 2018**", msg.body)
        self.assertIn("prescribed at Practice 2", msg.body)
        additional_cost = round(
            ncso_spending_for_entity(self.practice, "practice",
                                     1)[0]["additional_cost"])
        self.assertIn("an additional **\xa3{:,}**".format(additional_cost),
                      msg.body)

        html = msg.alternatives[0][0]
        self.assertInHTML("<b>July 2018</b>", html)
Example #6
0
    def test_make_ncso_concessions_email_for_all_england(self, attach_image):
        bookmark = NCSOConcessionBookmark.objects.create(user=self.user)

        msg = bookmark_utils.make_ncso_concession_email(bookmark)

        self.assertEqual(
            msg.subject,
            "Your update about NCSO Concessions for the NHS in England")
        self.assertIn("published for **July 2018**", msg.body)
        additional_cost = round(
            ncso_spending_for_entity(None, "all_england",
                                     1)[0]["additional_cost"])
        self.assertIn(
            "cost the NHS in England an additional **\xa3{:,}**".format(
                additional_cost),
            msg.body,
        )

        html = msg.alternatives[0][0]
        self.assertInHTML("<b>July 2018</b>", html)