diff --git a/README.rst b/README.rst index b2fd783f..e3c872b7 100644 --- a/README.rst +++ b/README.rst @@ -139,9 +139,9 @@ You can run tests by executing:: .. |pypi| image:: https://badge.fury.io/py/djangocms-link.svg :target: http://badge.fury.io/py/djangocms-link .. |build| image:: https://travis-ci.org/divio/djangocms-link.svg?branch=master - :target: https://travis-ci.org/divio/djangocms-link -.. |coverage| image:: https://codecov.io/gh/divio/djangocms-link/branch/master/graph/badge.svg - :target: https://codecov.io/gh/divio/djangocms-link + :target: https://travis-ci.org/django-cms/djangocms-link +.. |coverage| image:: https://codecov.io/gh/django-cms/djangocms-link/branch/master/graph/badge.svg + :target: https://codecov.io/gh/django-cms/djangocms-link .. |python| image:: https://img.shields.io/badge/python-3.10+-blue.svg :target: https://pypi.org/project/djangocms-link/ diff --git a/djangocms_link/admin.py b/djangocms_link/admin.py index b28431c4..9b26465b 100644 --- a/djangocms_link/admin.py +++ b/djangocms_link/admin.py @@ -1,5 +1,3 @@ -import traceback - from django.apps import apps from django.contrib import admin from django.core.exceptions import FieldError, PermissionDenied @@ -118,7 +116,7 @@ def get_queryset(self): ).current_content().values_list("page_id", flat=True) qs = Page.objects.filter(pk__in=qs).order_by("path") if self.site: - qs = qs.filter(page__site_id=self.site) + qs = qs.filter(site_id=self.site) except (AttributeError, FieldError): # django CMS 3.11 - 4.1 if hasattr(PageContent, "admin_manager"): # V4 @@ -131,7 +129,7 @@ def get_queryset(self): ).values_list("page_id", flat=True) qs = Page.objects.filter(pk__in=qs).order_by("node__path") if self.site: - qs = qs.filter(page__site_id=self.site) + qs = qs.filter(node__site_id=self.site) return list(qs) def add_admin_querysets(self, qs): @@ -148,10 +146,10 @@ def add_admin_querysets(self, qs): new_qs = new_qs.distinct() qs += list(new_qs) - except Exception as e: - print("==>", e) - traceback.print_tb(e.__traceback__) - # raise e + except Exception: + # Still report back remaining urls even if one model fails + pass + return qs def process_request(self, request): @@ -185,7 +183,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.link_url_name = f"{self.opts.app_label}_{self.opts.model_name}_urls" - def has_module_permission(self, request): + def has_module_permission(self, request): # pragma: no cover # Remove from admin return False diff --git a/djangocms_link/validators.py b/djangocms_link/validators.py index eb2bac5a..0ba5aebd 100644 --- a/djangocms_link/validators.py +++ b/djangocms_link/validators.py @@ -54,7 +54,6 @@ def __call__(self, value): value = value.lstrip("#") if not value: return value - print("AnchorValidator", value) if not isinstance(value, str) or len(value) > 100: raise ValidationError(self.message, code=self.code, params={"value": value}) diff --git a/tests/test_endpoint.py b/tests/test_endpoint.py index fd33f401..ccc05d04 100644 --- a/tests/test_endpoint.py +++ b/tests/test_endpoint.py @@ -40,8 +40,32 @@ def tearDown(self): self.subling.delete() def test_api_endpoint(self): + + for query_params in ("", "?app_label=1"): + with self.subTest(query_params=query_params): + with self.login_user_context(self.get_superuser()): + response = self.client.get(self.endpoint + query_params) + self.assertEqual(response.status_code, 200) + data = response.json() + + self.assertIn("results", data) + self.assertEqual(len(data["results"]), 1) + self.assertIn("pagination", data) + self.assertEqual(data["pagination"]["more"], False) + + pages = data["results"][0] + self.assertEqual(pages["text"], "Pages") + for page in pages["children"]: + self.assertIn("id", page) + self.assertIn("text", page) + self.assertIn("url", page) + _, pk = page["id"].split(":") + db_page = Page.objects.get(pk=pk) + self.assertEqual(page["text"], str(db_page)) + + def test_filter(self): with self.login_user_context(self.get_superuser()): - response = self.client.get(self.endpoint) + response = self.client.get(self.endpoint + "?term=child") self.assertEqual(response.status_code, 200) data = response.json() @@ -51,18 +75,11 @@ def test_api_endpoint(self): self.assertEqual(data["pagination"]["more"], False) pages = data["results"][0] - self.assertEqual(pages["text"], "Pages") - for page in pages["children"]: - self.assertIn("id", page) - self.assertIn("text", page) - self.assertIn("url", page) - _, pk = page["id"].split(":") - db_page = Page.objects.get(pk=pk) - self.assertEqual(page["text"], str(db_page)) + self.assertEqual(len(pages["children"]), 2) - def test_filter(self): + def test_filter_with_empty_result(self): with self.login_user_context(self.get_superuser()): - response = self.client.get(self.endpoint + "?term=child") + response = self.client.get(self.endpoint + "?term=DJANGOCMS") self.assertEqual(response.status_code, 200) data = response.json() @@ -70,13 +87,12 @@ def test_filter(self): self.assertEqual(len(data["results"]), 1) self.assertIn("pagination", data) self.assertEqual(data["pagination"]["more"], False) - pages = data["results"][0] - self.assertEqual(len(pages["children"]), 2) + self.assertEqual(pages, {}) - def test_filter_with_empty_result(self): + def test_site_selector(self): with self.login_user_context(self.get_superuser()): - response = self.client.get(self.endpoint + "?term=DJANGOCMS") + response = self.client.get(self.endpoint + "?app_label=2") self.assertEqual(response.status_code, 200) data = response.json()