From 9647b0027805f1a2fc8ef6f891b182dd286ab7a5 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 1 Aug 2022 15:44:10 -0700 Subject: [PATCH] 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 --- plinth/modules/help/tests/test_views.py | 36 ++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/plinth/modules/help/tests/test_views.py b/plinth/modules/help/tests/test_views.py index dc8b86354..9c6037d58 100644 --- a/plinth/modules/help/tests/test_views.py +++ b/plinth/modules/help/tests/test_views.py @@ -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')