Example #1
0
 def test_function_calls_are_cached(self):
     test_func = Mock(side_effect=lambda s: "foo%s" % s, __name__="test_func")
     result = cached(test_func, "bar")
     self.assertEqual(result, "foobar")
     result2 = cached(test_func, "bar")
     self.assertEqual(result2, result)
     test_func.assert_called_once_with("bar")
Example #2
0
 def test_function_calls_are_cached(self):
     test_func = Mock(
         side_effect=lambda s: 'foo%s' % s,
         __name__='test_func'
     )
     result = cached(test_func, 'bar')
     self.assertEqual(result, 'foobar')
     result2 = cached(test_func, 'bar')
     self.assertEqual(result2, result)
     test_func.assert_called_once_with('bar')
Example #3
0
 def test_source_commit_id_used_in_cache_key(self):
     test_func = Mock(__name__='test_func', return_value='foo')
     cached(test_func)
     cached(test_func)
     self.assertEqual(test_func.call_count, 1)
     with override_settings(SOURCE_COMMIT_ID='def456'):
         cached(test_func)
         cached(test_func)
     self.assertEqual(test_func.call_count, 2)
Example #4
0
def make_all_england_email(bookmark, tag=None):
    msg = initialise_email(bookmark, "all-england-alerts")
    msg.subject = "Your monthly update on prescribing across NHS England"

    date = ImportLog.objects.latest_in_category("dashboard_data").current_at

    # This allows us to switch between calculating savings at the practice or
    # CCG level. We use CCG at present for performance reasons but we may want
    # to switch in future.
    entity_type = "CCG"
    ppu_savings = get_total_savings_for_org(str(date),
                                            "all_standard_practices", None)
    measure_savings = cached(all_england_measure_savings, entity_type, date)
    low_priority_savings = cached(all_england_low_priority_savings,
                                  entity_type, date)
    low_priority_total = cached(all_england_low_priority_total, entity_type,
                                date)
    ncso_spending = first_or_none(
        ncso_spending_for_entity(None, "all_england", num_months=1))

    unsubscribe_path = reverse("bookmarks",
                               kwargs={"key": bookmark.user.profile.key})
    unsubscribe_link = settings.GRAB_HOST + unsubscribe_path

    context = {
        "entity_type": entity_type,
        "ppu_savings": ppu_savings,
        "measure_savings": measure_savings,
        "low_priority_savings": low_priority_savings,
        "low_priority_total": low_priority_total,
        "ncso_spending": ncso_spending,
        "date": date,
        "unsubscribe_link": unsubscribe_link,
        "HOST": settings.GRAB_HOST,
    }

    finalise_email(msg, "bookmarks/email_for_all_england.html", context,
                   ["all_england", tag])

    return msg
def make_all_england_email(bookmark, tag=None):
    msg = initialise_email(bookmark, 'all-england-alerts')
    msg.subject = 'Your monthly update on prescribing across NHS England'

    date = ImportLog.objects.latest_in_category('ppu').current_at

    # This allows us to switch between calculating savings at the practice or
    # CCG level. We use CCG at present for performance reasons but we may want
    # to switch in future.
    entity_type = 'CCG'
    ppu_savings = cached(all_england_ppu_savings, entity_type, date)
    measure_savings = cached(all_england_measure_savings, entity_type, date)
    low_priority_savings = cached(all_england_low_priority_savings,
                                  entity_type, date)
    low_priority_total = cached(all_england_low_priority_total, entity_type,
                                date)
    ncso_spending = first_or_none(
        ncso_spending_for_entity(None, 'all_england', num_months=1))

    unsubscribe_path = reverse('bookmark-login',
                               kwargs={'key': bookmark.user.profile.key})
    unsubscribe_link = settings.GRAB_HOST + unsubscribe_path

    context = {
        'entity_type': entity_type,
        'ppu_savings': ppu_savings,
        'measure_savings': measure_savings,
        'low_priority_savings': low_priority_savings,
        'low_priority_total': low_priority_total,
        'ncso_spending': ncso_spending,
        'date': date,
        'unsubscribe_link': unsubscribe_link,
        'HOST': settings.GRAB_HOST,
    }

    finalise_email(msg, 'bookmarks/email_for_all_england.html', context,
                   ['all_england', tag])

    return msg
Example #6
0
 def test_no_caching_if_not_enabled(self):
     test_func = Mock(__name__='test_func', return_value='foo')
     with override_settings(ENABLE_CACHING=False):
         cached(test_func)
         cached(test_func)
     self.assertEqual(test_func.call_count, 2)