Example #1
0
def test_macro_usage_2nd_es_exception(mock_sources, mock_page_count):
    """When follow-on ElasticSearch call raises, reraise exception."""
    mock_sources.return_value = {
        'A11yRoleQuicklinks': 'A11yRoleQuicklinks.ejs'
    }
    mock_page_count.side_effect = [
        {'a11yrolequicklinks': 200, 'othermacro': 50},
        TransportError("Can't reach ElasticSearch")
    ]

    with pytest.raises(TransportError):
        kumascript.macro_usage()
Example #2
0
def test_macro_usage_2nd_es_exception(mock_sources, mock_page_count):
    """When follow-on ElasticSearch call raises, reraise exception."""
    mock_sources.return_value = {
        'A11yRoleQuicklinks': 'A11yRoleQuicklinks.ejs'
    }
    mock_page_count.side_effect = [
        {'a11yrolequicklinks': 200, 'othermacro': 50},
        TransportError("Can't reach ElasticSearch")
    ]

    with pytest.raises(TransportError):
        kumascript.macro_usage()
Example #3
0
def macros(request):
    """Returns table of active macros and their page counts."""
    macros = macro_usage()
    total = sum(val['count'] for val in macros.values())
    context = {
        'macros': macros,
        'has_counts': total != 0
    }
    return render(request, 'dashboards/macros.html', context)
Example #4
0
File: views.py Project: tsl143/kuma
def macros(request):
    """Returns table of active macros and their page counts."""
    macros = macro_usage()
    total = sum(val['count'] for val in macros.values())
    context = {
        'macros': macros,
        'has_counts': total != 0
    }
    return render(request, 'dashboards/macros.html', context)
Example #5
0
def test_macro_usage_elasticsearch_exception(mock_sources, mock_page_count):
    """When ElasticSearch is unreachable, counts are 0."""
    mock_sources.return_value = {
        'A11yRoleQuicklinks': 'A11yRoleQuicklinks.ejs'
    }
    mock_page_count.side_effect = TransportError("Can't reach ElasticSearch")

    macros = kumascript.macro_usage()

    expected = {
        'A11yRoleQuicklinks': {
            'github_subpath': 'A11yRoleQuicklinks.ejs',
            'count': 0,
            'en_count': 0,
        }
    }
    assert macros == expected
Example #6
0
def test_macro_usage_elasticsearch_exception(mock_sources, mock_page_count):
    """When ElasticSearch is unreachable, counts are 0."""
    mock_sources.return_value = {
        'A11yRoleQuicklinks': 'A11yRoleQuicklinks.ejs'
    }
    mock_page_count.side_effect = TransportError("Can't reach ElasticSearch")

    macros = kumascript.macro_usage()

    expected = {
        'A11yRoleQuicklinks': {
            'github_subpath': 'A11yRoleQuicklinks.ejs',
            'count': 0,
            'en_count': 0,
        }
    }
    assert macros == expected
Example #7
0
def test_macro_usage(mock_sources, mock_page_count):
    mock_sources.return_value = {
        'A11yRoleQuicklinks': 'A11yRoleQuicklinks.ejs',
        'APIFeatureList': 'APIFeatureList.ejs',
    }
    all_page_count = {'a11yrolequicklinks': 200, 'othermacro': 50}
    en_page_count = {'a11yrolequicklinks': 101, 'othermacro': 42}
    mock_page_count.side_effect = [all_page_count, en_page_count]

    usage = kumascript.macro_usage()

    expected = {
        'A11yRoleQuicklinks': {
            'github_subpath': 'A11yRoleQuicklinks.ejs',
            'count': 200,
            'en_count': 101,
        },
        'APIFeatureList': {
            'github_subpath': 'APIFeatureList.ejs',
            'count': 0,
            'en_count': 0
        }
    }
    assert usage == expected
Example #8
0
def test_macro_usage(mock_sources, mock_page_count):
    mock_sources.return_value = {
        'A11yRoleQuicklinks': 'A11yRoleQuicklinks.ejs',
        'APIFeatureList': 'APIFeatureList.ejs',
    }
    all_page_count = {'a11yrolequicklinks': 200, 'othermacro': 50}
    en_page_count = {'a11yrolequicklinks': 101, 'othermacro': 42}
    mock_page_count.side_effect = [all_page_count, en_page_count]

    usage = kumascript.macro_usage()

    expected = {
        'A11yRoleQuicklinks': {
            'github_subpath': 'A11yRoleQuicklinks.ejs',
            'count': 200,
            'en_count': 101,
        },
        'APIFeatureList': {
            'github_subpath': 'APIFeatureList.ejs',
            'count': 0,
            'en_count': 0
        }
    }
    assert usage == expected
Example #9
0
def test_macro_usage_empty_kumascript(mock_sources, mock_page_count):
    """When KumaScript returns an empty response, macro usage is empty."""
    mock_sources.return_value = {}
    mock_page_count.side_effect = Exception('should not be called')
    macros = kumascript.macro_usage()
    assert macros == {}
Example #10
0
def test_macro_usage_empty_kumascript(mock_sources, mock_page_count):
    """When KumaScript returns an empty response, macro usage is empty."""
    mock_sources.return_value = {}
    mock_page_count.side_effect = Exception('should not be called')
    macros = kumascript.macro_usage()
    assert macros == {}
Example #11
0
def macros(request):
    """Returns table of active macros and their page counts."""
    macros = macro_usage()
    total = sum(val["count"] for val in macros.values())
    context = {"macros": macros, "has_counts": total != 0}
    return render(request, "dashboards/macros.html", context)