Пример #1
0
 def test_get_newsletters(self):
     """
     get_newsletters passes the expected args to request() and returns
     the 'newsletters' part of what it returns
     """
     with patch('basket.base.request', autospec=True) as request_call:
         request_call.return_value = {'newsletters': 'FOO BAR'}
         result = get_newsletters()
     request_call.assert_called_with('get', 'newsletters')
     self.assertEqual('FOO BAR', result)
Пример #2
0
 def test_get_newsletters(self):
     """
     get_newsletters passes the expected args to request() and returns
     the 'newsletters' part of what it returns
     """
     with patch('basket.base.request', autospec=True) as request_call:
         request_call.return_value = {'newsletters': 'FOO BAR'}
         result = get_newsletters()
     request_call.assert_called_with('get', 'newsletters')
     self.assertEqual('FOO BAR', result)
Пример #3
0
    def handle(self, *args, **options):
        newsletters = basket.get_newsletters()
        if not newsletters:
            raise CommandError('No data from basket')

        count = Newsletter.objects.refresh(newsletters)
        if not options['quiet']:
            if count:
                print('Updated %d newsletters' % count)
            else:
                print('Nothing to update')
Пример #4
0
    def handle(self, *args, **options):
        newsletters = basket.get_newsletters()
        if not newsletters:
            raise CommandError('No data from basket')

        count = Newsletter.objects.refresh(newsletters)
        if not options['quiet']:
            if count:
                print('Updated %d newsletters' % count)
            else:
                print('Nothing to update')
Пример #5
0
    def handle(self, *args, **options):
        newsletters = basket.get_newsletters()
        if not newsletters:
            raise CommandError("No data from basket")

        count = Newsletter.objects.refresh(newsletters)
        if not options["quiet"]:
            if count:
                print(f"Updated {count} newsletters")
            else:
                print("Nothing to update")
Пример #6
0
def get_newsletters():
    """Return a dictionary with our information about newsletters.
    Keys are the internal keys we use to designate newsletters to basket.
    Values are dictionaries with the remaining newsletter information.

    If we cannot get through to basket, return a default set of newsletters
    from basket_data.json.
    """

    # Get the newsletter data from basket - it's a dictionary of dictionaries
    # Cache it for a little while (300 secs = 5 minutes)
    data = cache.get(NEWSLETTERS_CACHE_KEY)
    if data is None:
        try:
            data = basket.get_newsletters()
        except basket.BasketException:
            log.exception("Error getting newsletters from basket")
            return get_local_basket_newsletters_data()
        # Cache for an hour - newsletters very rarely change
        cache.set(NEWSLETTERS_CACHE_KEY, data, NEWSLETTERS_CACHE_TIMEOUT)
    return data