help: Update test for contribute view

- Verify that issue data is sent in context properly.

- Ensure that an external request is not made during testing.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2022-08-01 15:44:10 -07:00
parent e5a866dd64
commit 9647b00278
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -9,6 +9,7 @@ Pending: - status log
"""
import json
import pathlib
import subprocess
from unittest.mock import patch
@ -42,7 +43,6 @@ def fixture_app_urls():
@pytest.mark.parametrize("view_name, view", (
('contribute', views.contribute),
('feedback', views.feedback),
('support', views.support),
('index', views.index),
@ -53,6 +53,40 @@ def test_simple_help_pages(rf, view_name, view):
assert _is_page(response)
@patch('apt.Cache')
@patch('gzip.decompress')
@patch('requests.get')
def test_contribute_page(requests_get, decompress, apt_cache, rf):
"""Test the contribute page."""
issues = [{
'type': 'testing-autorm',
'packages': ['autormpkg'],
'source': 'autormsrc',
'bugs': ['123']
}, {
'type': 'no-testing',
'package': ['notestingpkg'],
'source': 'nottestingsrc',
}, {
'type': 'gift',
'package': ['giftpkg'],
'bug': '456',
'title': 'bug 456 title',
}, {
'type': 'help',
'package': ['helppkg'],
'bug': '567',
'title': 'bug 567 title',
}]
decompress.return_value = json.dumps(issues)
response = views.contribute(rf.get(urls.reverse('help:contribute')))
assert _is_page(response)
assert issues == (response.context_data['testing_autorm'] +
response.context_data['no_testing'] +
response.context_data['gift'] +
response.context_data['help'])
def test_about(rf):
"""Test some expected items in about view."""
manual_url = urls.reverse('help:manual')