From 81c4fea7f58ac4d72fbaa711dd08df832bd1962a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 29 Jan 2024 12:05:07 +0100 Subject: [PATCH 1/2] fix exception --- idhub/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/idhub/models.py b/idhub/models.py index ec808d9..fea0156 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -491,8 +491,9 @@ class Schemas(models.Model): try: if is_json: return json.loads(field_value) - except json.decoder.JSONDecodeError: - return field_value + except Exception: + pass + return field_value def _update_model_field(self, field_attr, field_value): From 946bde01ab8d24d64858cf065c5e879c2f3fc5d3 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 29 Jan 2024 12:05:23 +0100 Subject: [PATCH 2/2] fix tests --- idhub/tests/test_tables.py | 18 +++++++++++++++++- idhub/tests/test_templates.py | 3 +++ idhub/tests/test_views.py | 17 +++++++++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/idhub/tests/test_tables.py b/idhub/tests/test_tables.py index 7c3ad89..2a6b28b 100644 --- a/idhub/tests/test_tables.py +++ b/idhub/tests/test_tables.py @@ -1,6 +1,9 @@ +import json + from datetime import datetime from unittest.mock import MagicMock +from django.conf import settings from django.test import TestCase from django.urls import reverse from django.core.exceptions import FieldError @@ -15,6 +18,8 @@ class AdminDashboardTableTest(TestCase): self.admin_user = User.objects.create_superuser( email='adminuser@example.org', password='adminpass12') + self.admin_user.accept_gdpr=True + self.admin_user.save() @classmethod def setUpTestData(cls): @@ -118,7 +123,18 @@ class TemplateTableTest(TestCase): ) def format_data_for_json_reader(self, name, description): - return '{"name": "'+name+'", "description": "'+description+'"}' + v = { + "name": [{ + "lang": settings.LANGUAGE_CODE, + "value": name + }], + "description": [{ + "lang": settings.LANGUAGE_CODE, + "value": description + }] + } + return json.dumps(v) + # return '{"name": "'+name+'", "description": "'+description+'"}' def test_order_table_by_name_throws_no_exception(self): try: diff --git a/idhub/tests/test_templates.py b/idhub/tests/test_templates.py index c1b8f3c..d505d11 100644 --- a/idhub/tests/test_templates.py +++ b/idhub/tests/test_templates.py @@ -2,6 +2,7 @@ from django.urls import reverse from django.test import Client, TestCase from idhub_auth.models import User +from django.conf import settings class TemplateTest(TestCase): @@ -10,6 +11,8 @@ class TemplateTest(TestCase): self.admin_user = User.objects.create_superuser( email='adminuser@example.org', password='adminpass12') + self.admin_user.accept_gdpr=True + self.admin_user.save() def test_dashboard_template(self): self.client.login(email='adminuser@example.org', password='adminpass12') diff --git a/idhub/tests/test_views.py b/idhub/tests/test_views.py index fd131c0..b23f9de 100644 --- a/idhub/tests/test_views.py +++ b/idhub/tests/test_views.py @@ -8,11 +8,18 @@ from idhub.admin.views import PeopleListView class AdminDashboardViewTest(TestCase): def setUp(self): - self.user = User.objects.create_user(email='normaluser@example.org', - password='testpass12') + self.user = User.objects.create_user( + email='normaluser@example.org', + password='testpass12', + ) + self.user.accept_gdpr=True + self.user.save() + self.admin_user = User.objects.create_superuser( email='adminuser@example.org', password='adminpass12') + self.admin_user.accept_gdpr=True + self.admin_user.save() def test_view_url_exists_at_desired_location(self): response = self.client.get('/admin/dashboard/', follow=True) @@ -62,14 +69,20 @@ class PeopleListViewTest(TestCase): # Create some user instances for testing self.user = User.objects.create_user(email='normaluser@example.org', password='testpass12') + self.user.accept_gdpr=True + self.user.save() self.admin_user = User.objects.create_superuser( email='adminuser@example.org', password='adminpass12') + self.admin_user.accept_gdpr=True + self.admin_user.save() # Create a request object for the view self.request = self.factory.get(reverse('idhub:admin_people_list')) self.request.user = self.admin_user + self.client.login(email='adminuser@example.org', password='adminpass12') + self.request.session = self.client.session def test_template_used(self): response = PeopleListView.as_view()(self.request)