Exemplo n.º 1
0
def test_request_cdn_cache_invalidation_configured(
        settings, mocked_get_cloudfront_client):
    """When explicitly enabling a MDN_CLOUDFRONT_DISTRIBUTIONS we should
    expect its 'transform' function to be called.
    """

    settings.MDN_CLOUDFRONT_DISTRIBUTIONS = {
        'mything': {
            'id': 'XYZABC123',
            'transform_function': ('kuma.api.tests.test_tasks.transformer')
        },
        'unconfigured': {
            'id': None,
            'transform_function': 'wont.be.used'
        }
    }

    pairs = [('sv-SE', 'Learn/stuff')]
    request_cdn_cache_invalidation(pairs)
    assert transform_calls_made == [['sv-SE', 'Learn/stuff']]

    # When used, we need to reset it because it's a module global mutable
    # specific to this test module.
    del transform_calls_made[:]

    mocked_get_cloudfront_client().create_invalidation.assert_called_with(
        DistributionId='XYZABC123',
        InvalidationBatch={
            'Paths': {
                'Items': ['/sv-SE/Learn/stuff/'],
                'Quantity': 1
            },
            'CallerReference': mock.ANY
        })
Exemplo n.º 2
0
def test_request_cdn_cache_invalidation_configured(
        settings, mocked_get_cloudfront_client):
    """When explicitly enabling a MDN_CLOUDFRONT_DISTRIBUTIONS we should
    expect its 'transform' function to be called.
    """

    settings.MDN_CLOUDFRONT_DISTRIBUTIONS = {
        "mything": {
            "id": "XYZABC123",
            "transform_function": ("kuma.api.tests.test_tasks.transformer"),
        },
        "unconfigured": {
            "id": None,
            "transform_function": "wont.be.used"
        },
    }

    pairs = [("sv-SE", "Learn/stuff")]
    request_cdn_cache_invalidation(pairs)
    assert transform_calls_made == [["sv-SE", "Learn/stuff"]]

    # When used, we need to reset it because it's a module global mutable
    # specific to this test module.
    del transform_calls_made[:]

    mocked_get_cloudfront_client().create_invalidation.assert_called_with(
        DistributionId="XYZABC123",
        InvalidationBatch={
            "Paths": {
                "Items": ["/sv-SE/Learn/stuff/"],
                "Quantity": 1
            },
            "CallerReference": mock.ANY,
        },
    )
Exemplo n.º 3
0
def test_request_cdn_cache_invalidation_not_configured(
        settings, mocked_get_cloudfront_client):
    """When the settings.MDN_CLOUDFRONT_DISTRIBUTIONS isn't set, no
    calls should be make to the boto3 CloudFront client.
    """
    # By default, for all testing, the MDN_CLOUDFRONT_DISTRIBUTIONS
    # should be set to an empty dict. Just sanity-check that.
    assert not settings.MDN_CLOUDFRONT_DISTRIBUTIONS

    pairs = [('sv-SE', 'Learn/stuff')]
    request_cdn_cache_invalidation(pairs)

    mocked_get_cloudfront_client().assert_not_called()