diff --git a/qgis-app/plugins/tests/test_plugin_list.py b/qgis-app/plugins/tests/test_plugin_list.py new file mode 100644 index 00000000..d5984f1b --- /dev/null +++ b/qgis-app/plugins/tests/test_plugin_list.py @@ -0,0 +1,55 @@ +from django.test import TestCase +from django.urls import reverse + +class PluginsListViewTestCase(TestCase): + fixtures = [ + "fixtures/styles.json", + "fixtures/auth.json", + "fixtures/simplemenu.json", + "fixtures/plugins.json", + ] + + def setUp(self): + pass + + def test_plugins_list_view(self): + # Test the main plugins list view without any parameters + response = self.client.get(reverse('approved_plugins')) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'plugins/plugin_list.html') + self.assertTrue('current_sort_query' in response.context) + self.assertTrue('current_querystring' in response.context) + self.assertTrue('per_page_list' in response.context) + self.assertTrue('show_more_items_number' in response.context) + + def test_plugins_list_pagination(self): + # Test the plugins list view with pagination + response = self.client.get(reverse('approved_plugins'), {'per_page': 20}) + self.assertEqual(response.status_code, 200) + self.assertTrue('current_sort_query' in response.context) + self.assertTrue('current_querystring' in response.context) + self.assertTrue('per_page_list' in response.context) + self.assertTrue('show_more_items_number' in response.context) + + show_more_items_number = response.context['show_more_items_number'] + self.assertEqual(show_more_items_number, 70) + + response = self.client.get(reverse('approved_plugins'), {'per_page': show_more_items_number}) + self.assertEqual(response.status_code, 200) + self.assertTrue('current_sort_query' in response.context) + self.assertTrue('current_querystring' in response.context) + self.assertTrue('per_page_list' in response.context) + self.assertTrue('show_more_items_number' in response.context) + + show_more_items_number = response.context['show_more_items_number'] + self.assertEqual(show_more_items_number, 120) + + def test_plugins_list_sorting(self): + # Test the plugins list view with sorting + response = self.client.get(reverse('approved_plugins'), {'sort': 'name'}) + self.assertEqual(response.status_code, 200) + self.assertTrue('current_sort_query' in response.context) + self.assertTrue('current_querystring' in response.context) + self.assertTrue('per_page_list' in response.context) + self.assertTrue('show_more_items_number' in response.context) +