예제 #1
0
def test__custom_sitemap__with_invalid_section():
    """Tests custom_sitemap view when invalid section is provided."""
    # Setup details to call view
    section = 'Wrong Section'
    sitemaps = {'Test Section': ['Test Page']}
    request = RequestFactory()
    request.GET = {'p': 2}
    request.scheme = 'http'

    # Call view and get response
    try:
        views.custom_sitemap(request, sitemaps, section)
    except Http404 as e:
        assert 'No sitemap available for section: Wrong Section' in str(e)
    else:
        assert False
예제 #2
0
def test__custom_sitemap__output():
    """Tests custom_sitemap view for proper details in response."""
    # Setup details to call view
    section = 'Test Section'
    sitemaps = {'Test Section': ['Test Page']}
    request = RequestFactory()
    request.GET = {'p': 2}
    request.scheme = 'http'

    # Call view and get response
    response = views.custom_sitemap(request, sitemaps, section)

    # Test for expected output details
    assert response.template_name == 'sitemap.xml'
    assert response.headers['Content-Type'] == 'application/xml'
    assert isinstance(response.context_data, dict)
    assert 'urlset' in response.context_data
    assert response.context_data['urlset'][0] == {'play': 1}
    assert 'play_urlset' in response.context_data
    assert response.context_data['play_urlset'] == 1
    assert 'study_urlset' in response.context_data
    assert response.context_data['study_urlset'] == 2
    assert 'tools_urlset' in response.context_data
    assert response.context_data['tools_urlset'] == 3
    assert 'read_urlset' in response.context_data
    assert response.context_data['read_urlset'] == 4
    assert 'other_urlset' in response.context_data
    assert response.context_data['other_urlset'] == 5
예제 #3
0
def test__custom_sitemap__without_sections():
    """Tests custom_sitemap view when sections are not provided."""
    # Setup details to call view
    section = None
    sitemaps = {'Test Section': ['Test Page']}
    request = RequestFactory()
    request.GET = {'p': 2}
    request.scheme = 'http'

    # Call view and get response
    response = views.custom_sitemap(request, sitemaps, section)

    # Test for the passed in sitemap details to confirm right
    # paths were followed
    assert list(response.context_data['urlset'][5])[0] == 'maps'
예제 #4
0
def test__custom_sitemap__without_all_lastmod(mock_get_urls):
    """Tests custom_sitemap view when all_sites_lastmod not provided."""
    # Setup details to call view
    section = 'Test Section'
    sitemaps = {'Test Section': ['Test Page']}
    request = RequestFactory()
    request.GET = {'p': 2}
    request.scheme = 'http'

    # Set patched return values for modify details
    mock_get_urls.return_value = (
        [],
        {
            'all_sites_lastmod': False,
            'lastmod': (2000, 1, 1, 0, 0, 0)
        },
    )

    # Call view and get response
    response = views.custom_sitemap(request, sitemaps, section)

    # Test that additional last-modified details not added
    assert 'Last-Modified' not in response