Example #1
0
def purge_cache_for_settings(sender, **kwargs):
    """
    We're using the nuclear option for caching. Every time any Setting changes
    we flush the entire cache
    """
    if issubclass(sender, BaseSetting):
        purge_all_from_cache()
Example #2
0
 def test_log__success(self, logger_mock, delete_mock):
     """
     If Cloudflare's API response OK on purge, info should be logged
     """
     # Mock a successful JSON response
     delete_mock.return_value.json.return_value = {'success': True}
     purge_all_from_cache()
     logger_mock.info.assert_called_once_with(
         'Purged from CloudFlare with data: %s',
         '{}'
     )
Example #3
0
    def test_log__invalid_url(self, logger_mock, delete_mock):
        # Mock a URL error response
        delete_mock.return_value.json.side_effect = ValueError
        delete_mock.return_value.raise_for_status.side_effect = InvalidURL(
            'something happened',
        )

        purge_all_from_cache()
        logger_mock.error.assert_called_once_with(
            'Couldn\'t purge from Cloudflare with data: %s. InvalidURL: %s',
            '{}',
            'something happened'
        )
Example #4
0
 def test_cache_purge_all(self, requests_delete):
     """
     Should fire an appropriate looking HTTP request to Cloudflare's
     purge API endpoint
     """
     purge_all_from_cache()
     requests_delete.assert_called_with(
         'https://api.cloudflare.com/client/v4/zones/CLOUDFLARE_FAKE_ZONE/purge_cache',
         json={},
         headers={
             'X-Auth-Email': 'CLOUDFLARE_FAKE_EMAIL',
             'Content-Type': 'application/json',
             'X-Auth-Key': 'CLOUDFLARE_FAKE_TOKEN'
         }
     )
Example #5
0
    def test_log__http_error(self, logger_mock, delete_mock):
        # Mock an HTTP error response
        response_500 = Mock()
        response_500.status_code = 500
        delete_mock.return_value.json.side_effect = ValueError
        delete_mock.return_value.raise_for_status.side_effect = HTTPError(
            'something happened',
            response=response_500
        )

        purge_all_from_cache()
        logger_mock.error.assert_called_once_with(
            'Couldn\'t purge from Cloudflare with data: %s. HTTPError: %d %s',
            '{}',
            500,
            'something happened'
        )
Example #6
0
 def test_log__http_ok__cf_error(self, logger_mock, delete_mock):
     """
     If Clouflare's API response returns a successful HTTP response, but
     without success in the json, an error should be logged
     """
     # Mock an error JSON response
     delete_mock.return_value.json.return_value = {
         'success': False,
         'errors': [{'message': 'Cloudflare doesn\'t like you 😡'}]
     }
     purge_all_from_cache()
     logger_mock.error.assert_called_once_with(
         'Couldn\'t purge from Cloudflare with data: %s. '
         'Cloudflare errors \'%s\'',
         '{}',
         'Cloudflare doesn\'t like you 😡'
     )
Example #7
0
def purge_cache(sender, **kwargs):
    """
    We're using the nuclear option for caching. Every time a Release changes
    we flush the entire cache
    """
    purge_all_from_cache()
Example #8
0
def purge_all(sender, **kwargs):
    purge_all_from_cache()