Merge branch 'tests'

This commit is contained in:
Cayo Puigdefabregas 2024-01-29 12:05:48 +01:00
commit 6b837926b2
4 changed files with 38 additions and 5 deletions

View File

@ -491,8 +491,9 @@ class Schemas(models.Model):
try: try:
if is_json: if is_json:
return json.loads(field_value) return json.loads(field_value)
except json.decoder.JSONDecodeError: except Exception:
return field_value pass
return field_value return field_value
def _update_model_field(self, field_attr, field_value): def _update_model_field(self, field_attr, field_value):

View File

@ -1,6 +1,9 @@
import json
from datetime import datetime from datetime import datetime
from unittest.mock import MagicMock from unittest.mock import MagicMock
from django.conf import settings
from django.test import TestCase from django.test import TestCase
from django.urls import reverse from django.urls import reverse
from django.core.exceptions import FieldError from django.core.exceptions import FieldError
@ -15,6 +18,8 @@ class AdminDashboardTableTest(TestCase):
self.admin_user = User.objects.create_superuser( self.admin_user = User.objects.create_superuser(
email='adminuser@example.org', email='adminuser@example.org',
password='adminpass12') password='adminpass12')
self.admin_user.accept_gdpr=True
self.admin_user.save()
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
@ -118,7 +123,18 @@ class TemplateTableTest(TestCase):
) )
def format_data_for_json_reader(self, name, description): 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): def test_order_table_by_name_throws_no_exception(self):
try: try:

View File

@ -2,6 +2,7 @@ from django.urls import reverse
from django.test import Client, TestCase from django.test import Client, TestCase
from idhub_auth.models import User from idhub_auth.models import User
from django.conf import settings
class TemplateTest(TestCase): class TemplateTest(TestCase):
@ -10,6 +11,8 @@ class TemplateTest(TestCase):
self.admin_user = User.objects.create_superuser( self.admin_user = User.objects.create_superuser(
email='adminuser@example.org', email='adminuser@example.org',
password='adminpass12') password='adminpass12')
self.admin_user.accept_gdpr=True
self.admin_user.save()
def test_dashboard_template(self): def test_dashboard_template(self):
self.client.login(email='adminuser@example.org', password='adminpass12') self.client.login(email='adminuser@example.org', password='adminpass12')

View File

@ -8,11 +8,18 @@ from idhub.admin.views import PeopleListView
class AdminDashboardViewTest(TestCase): class AdminDashboardViewTest(TestCase):
def setUp(self): def setUp(self):
self.user = User.objects.create_user(email='normaluser@example.org', self.user = User.objects.create_user(
password='testpass12') email='normaluser@example.org',
password='testpass12',
)
self.user.accept_gdpr=True
self.user.save()
self.admin_user = User.objects.create_superuser( self.admin_user = User.objects.create_superuser(
email='adminuser@example.org', email='adminuser@example.org',
password='adminpass12') password='adminpass12')
self.admin_user.accept_gdpr=True
self.admin_user.save()
def test_view_url_exists_at_desired_location(self): def test_view_url_exists_at_desired_location(self):
response = self.client.get('/admin/dashboard/', follow=True) response = self.client.get('/admin/dashboard/', follow=True)
@ -62,14 +69,20 @@ class PeopleListViewTest(TestCase):
# Create some user instances for testing # Create some user instances for testing
self.user = User.objects.create_user(email='normaluser@example.org', self.user = User.objects.create_user(email='normaluser@example.org',
password='testpass12') password='testpass12')
self.user.accept_gdpr=True
self.user.save()
self.admin_user = User.objects.create_superuser( self.admin_user = User.objects.create_superuser(
email='adminuser@example.org', email='adminuser@example.org',
password='adminpass12') password='adminpass12')
self.admin_user.accept_gdpr=True
self.admin_user.save()
# Create a request object for the view # Create a request object for the view
self.request = self.factory.get(reverse('idhub:admin_people_list')) self.request = self.factory.get(reverse('idhub:admin_people_list'))
self.request.user = self.admin_user 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): def test_template_used(self):
response = PeopleListView.as_view()(self.request) response = PeopleListView.as_view()(self.request)