From 4efe97d6e4f2d70a42479de59219fe485787e99b Mon Sep 17 00:00:00 2001 From: Elijah Date: Wed, 22 Nov 2023 19:46:36 +0100 Subject: [PATCH 01/11] Added pagination and column sorting to the admin dashboard, User, and Roles tables --- idhub/admin/tables.py | 24 ++++++++++++++++ idhub/admin/views.py | 33 +++++++++++++--------- idhub/templates/idhub/admin/dashboard.html | 22 ++------------- idhub/templates/idhub/admin/people.html | 32 ++------------------- idhub/templates/idhub/admin/roles.html | 31 ++------------------ trustchain_idhub/settings.py | 1 + 6 files changed, 51 insertions(+), 92 deletions(-) create mode 100644 idhub/admin/tables.py diff --git a/idhub/admin/tables.py b/idhub/admin/tables.py new file mode 100644 index 0000000..7bd76d8 --- /dev/null +++ b/idhub/admin/tables.py @@ -0,0 +1,24 @@ +import django_tables2 as tables +from idhub.models import Rol, Event +from idhub_auth.models import User + + +class UserTable(tables.Table): + class Meta: + model = User + template_name = "idhub/custom_table.html" + fields = ("first_name", "last_name", "email", "is_active", "is_admin") + + +class RolesTable(tables.Table): + class Meta: + model = Rol + template_name = "idhub/custom_table.html" + fields = ("name", "description") + + +class DashboardTable(tables.Table): + class Meta: + model = Event + template_name = "idhub/custom_table.html" + fields = ("type", "message", "created") diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 1b380d2..6cf48db 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -5,6 +5,7 @@ import pandas as pd from pathlib import Path from jsonschema import validate from smtplib import SMTPException +from django_tables2 import SingleTableView from django.conf import settings from django.utils.translation import gettext_lazy as _ @@ -30,6 +31,11 @@ from idhub.admin.forms import ( SchemaForm, UserRolForm, ) +from idhub.admin.tables import ( + UserTable, + DashboardTable, + RolesTable +) from idhub.models import ( DID, Event, @@ -43,19 +49,15 @@ from idhub.models import ( ) -class DashboardView(AdminView, TemplateView): +class DashboardView(AdminView, SingleTableView): template_name = "idhub/admin/dashboard.html" + table_class = DashboardTable title = _('Dashboard') subtitle = _('Events') icon = 'bi bi-bell' section = "Home" + model = Event - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context.update({ - 'events': Event.objects.filter(user=None), - }) - return context class People(AdminView): title = _("User management") @@ -82,10 +84,12 @@ class ImportExport(AdminView): section = "ImportExport" -class PeopleListView(People, TemplateView): +class PeopleListView(People, SingleTableView): template_name = "idhub/admin/people.html" subtitle = _('View users') icon = 'bi bi-person' + table_class = UserTable + model = User def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -402,13 +406,16 @@ class RolesView(AccessControl): template_name = "idhub/admin/roles.html" subtitle = _('Manage roles') icon = '' + table_class = RolesTable + model = Rol def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context.update({ - 'roles': Rol.objects, - }) - return context + queryset = kwargs.pop('object_list', None) + if queryset is None: + self.object_list = self.model.objects.all() + + return super().get_context_data(**kwargs) + class RolRegisterView(AccessControl, CreateView): template_name = "idhub/admin/rol_register.html" diff --git a/idhub/templates/idhub/admin/dashboard.html b/idhub/templates/idhub/admin/dashboard.html index d1317e7..4862f82 100644 --- a/idhub/templates/idhub/admin/dashboard.html +++ b/idhub/templates/idhub/admin/dashboard.html @@ -1,29 +1,11 @@ {% extends "idhub/base_admin.html" %} {% load i18n %} +{% load render_table from django_tables2 %} {% block content %}

{{ subtitle }}

-
- - - - - - - - - - {% for ev in events %} - - - - - - {% endfor %} - -
{{ ev.get_type_name }}{{ ev.message }}{{ ev.created }}
-
+{% render_table table %} {% endblock %} diff --git a/idhub/templates/idhub/admin/people.html b/idhub/templates/idhub/admin/people.html index 25b7c61..4862f82 100644 --- a/idhub/templates/idhub/admin/people.html +++ b/idhub/templates/idhub/admin/people.html @@ -1,39 +1,11 @@ {% extends "idhub/base_admin.html" %} {% load i18n %} +{% load render_table from django_tables2 %} {% block content %}

{{ subtitle }}

-
- - - - - - - - - - - - - {% for user in users %} - - - - - - - - - {% endfor %} - -
{{ user.last_name|default:'' }}{{ user.first_name|default:'' }}{{ user.email }} - {{ user.get_memberships }} - - {{ user.get_roles }} -
-
+{% render_table table %} {% endblock %} diff --git a/idhub/templates/idhub/admin/roles.html b/idhub/templates/idhub/admin/roles.html index 25bfd93..4862f82 100644 --- a/idhub/templates/idhub/admin/roles.html +++ b/idhub/templates/idhub/admin/roles.html @@ -1,38 +1,11 @@ {% extends "idhub/base_admin.html" %} {% load i18n %} +{% load render_table from django_tables2 %} {% block content %}

{{ subtitle }}

-
-
-
- - - - - - - - - - - {% for rol in roles.all %} - - - - - - - {% endfor %} - -
{{ rol.name }}{{ rol.description|default:""}}
- -
-
-
+{% render_table table %} {% endblock %} diff --git a/trustchain_idhub/settings.py b/trustchain_idhub/settings.py index 30bbc0a..aef9742 100644 --- a/trustchain_idhub/settings.py +++ b/trustchain_idhub/settings.py @@ -70,6 +70,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'django_extensions', 'django_bootstrap5', + 'django_tables', 'idhub_auth', 'idhub' ] From de5f96afb8609e9ba65447d71bb4f9b2ac949014 Mon Sep 17 00:00:00 2001 From: Elijah Date: Wed, 22 Nov 2023 19:48:15 +0100 Subject: [PATCH 02/11] Added styling to the tables with new functionality so they resemble the existing tables --- idhub/templates/idhub/custom_table.html | 98 +++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 idhub/templates/idhub/custom_table.html diff --git a/idhub/templates/idhub/custom_table.html b/idhub/templates/idhub/custom_table.html new file mode 100644 index 0000000..2153191 --- /dev/null +++ b/idhub/templates/idhub/custom_table.html @@ -0,0 +1,98 @@ +{% load django_tables2 %} +{% load i18n %} +{% block table-wrapper %} +
+ {% block table %} + + {% block table.thead %} + {% if table.show_header %} + + + {% for column in table.columns %} + + {% endfor %} + + + {% endif %} + {% endblock table.thead %} + {% block table.tbody %} + + {% for row in table.paginated_rows %} + {% block table.tbody.row %} + + {% for column, cell in row.items %} + + {% endfor %} + + {% endblock table.tbody.row %} + {% empty %} + {% if table.empty_text %} + {% block table.tbody.empty_text %} + + {% endblock table.tbody.empty_text %} + {% endif %} + {% endfor %} + + {% endblock table.tbody %} + {% block table.tfoot %} + {% if table.has_footer %} + + + {% for column in table.columns %} + + {% endfor %} + + + {% endif %} + {% endblock table.tfoot %} +
+ {% if column.orderable %} + {{ column.header }} + {% else %} + {{ column.header }} + {% endif %} +
{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}
{{ table.empty_text }}
{{ column.footer }}
+ {% endblock table %} + + {% block pagination %} + {% if table.page and table.paginator.num_pages > 1 %} +
    + {% if table.page.has_previous %} + {% block pagination.previous %} + + {% endblock pagination.previous %} + {% endif %} + {% if table.page.has_previous or table.page.has_next %} + {% block pagination.range %} + {% for p in table.page|table_page_range:table.paginator %} +
  • + {% if p == '...' %} + {{ p }} + {% else %} + + {{ p }} + + {% endif %} +
  • + {% endfor %} + {% endblock pagination.range %} + {% endif %} + {% if table.page.has_next %} + {% block pagination.next %} + + {% endblock pagination.next %} + {% endif %} +
+ {% endif %} + {% endblock pagination %} +
+{% endblock table-wrapper %} From 058698a44d79e8ee5e57b33c9e596722b996b17b Mon Sep 17 00:00:00 2001 From: Elahi-cs Date: Thu, 23 Nov 2023 10:33:13 +0100 Subject: [PATCH 03/11] Updated requirements.txt to add django-tables2 --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 745c483..140c49f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ django==4.2.5 django-bootstrap5==23.3 django-extensions==3.2.3 +django-tables2==2.6.0 black==23.9.1 python-decouple==3.8 jsonschema==4.19.1 From 7b638d3efb9edd05575e163edc54d31e07fab7ed Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 23 Nov 2023 18:31:12 +0100 Subject: [PATCH 04/11] Added a missing 2 to django-tables in INSTALLED_APPS --- trustchain_idhub/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trustchain_idhub/settings.py b/trustchain_idhub/settings.py index aef9742..61d9637 100644 --- a/trustchain_idhub/settings.py +++ b/trustchain_idhub/settings.py @@ -70,7 +70,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'django_extensions', 'django_bootstrap5', - 'django_tables', + 'django_tables2', 'idhub_auth', 'idhub' ] From d2f8fcd56ae229f71a63af9af6169fdc51b67c65 Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 23 Nov 2023 18:38:09 +0100 Subject: [PATCH 05/11] Fixed missing table in RolesView --- idhub/admin/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 6cf48db..b19df1e 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -402,7 +402,7 @@ class PeopleRolDeleteView(PeopleView): return redirect('idhub:admin_people_edit', user.id) -class RolesView(AccessControl): +class RolesView(AccessControl, SingleTableView): template_name = "idhub/admin/roles.html" subtitle = _('Manage roles') icon = '' From 3192694fba249becf615808240a0376a7ca270ca Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 24 Nov 2023 12:19:27 +0100 Subject: [PATCH 06/11] Stylized paginator buttons --- idhub/templates/idhub/custom_table.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/idhub/templates/idhub/custom_table.html b/idhub/templates/idhub/custom_table.html index 2153191..808de83 100644 --- a/idhub/templates/idhub/custom_table.html +++ b/idhub/templates/idhub/custom_table.html @@ -61,8 +61,8 @@ {% if table.page.has_previous %} {% block pagination.previous %} {% endblock pagination.previous %} @@ -72,9 +72,9 @@ {% for p in table.page|table_page_range:table.paginator %}
  • {% if p == '...' %} - {{ p }} + {{ p }} {% else %} - + {{ p }} {% endif %} @@ -85,8 +85,8 @@ {% if table.page.has_next %} {% block pagination.next %}
  • {% endblock pagination.next %} From ffa582f609e0ebc385a7dc16e16f8efd2bc89c07 Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 24 Nov 2023 13:04:17 +0100 Subject: [PATCH 07/11] Changed admin dashboard column names to reflect recent changes in main --- idhub/admin/tables.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/idhub/admin/tables.py b/idhub/admin/tables.py index 7bd76d8..7ce7d43 100644 --- a/idhub/admin/tables.py +++ b/idhub/admin/tables.py @@ -18,6 +18,10 @@ class RolesTable(tables.Table): class DashboardTable(tables.Table): + type = tables.Column(verbose_name="Event") + message = tables.Column(verbose_name="Description") + created = tables.Column(verbose_name="Date") + class Meta: model = Event template_name = "idhub/custom_table.html" From de5663177813f58a6b77c27118e2df64b4c8d990 Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 24 Nov 2023 15:23:48 +0100 Subject: [PATCH 08/11] Added tests for Admin Dashboard model, view, template, and table --- idhub/tests.py | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 idhub/tests.py diff --git a/idhub/tests.py b/idhub/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/idhub/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. From f25cee86c82bd9be8ee9dbd50cb7e24a97d83c93 Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 24 Nov 2023 15:23:59 +0100 Subject: [PATCH 09/11] Added tests for Admin Dashboard model, view, template, and table --- idhub/tests/__init__.py | 0 idhub/tests/test_models.py | 17 +++++++++ idhub/tests/test_tables.py | 65 +++++++++++++++++++++++++++++++++++ idhub/tests/test_templates.py | 18 ++++++++++ idhub/tests/test_views.py | 50 +++++++++++++++++++++++++++ 5 files changed, 150 insertions(+) create mode 100644 idhub/tests/__init__.py create mode 100644 idhub/tests/test_models.py create mode 100644 idhub/tests/test_tables.py create mode 100644 idhub/tests/test_templates.py create mode 100644 idhub/tests/test_views.py diff --git a/idhub/tests/__init__.py b/idhub/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/idhub/tests/test_models.py b/idhub/tests/test_models.py new file mode 100644 index 0000000..1709861 --- /dev/null +++ b/idhub/tests/test_models.py @@ -0,0 +1,17 @@ +from django.test import TestCase +from idhub.models import Event +from idhub_auth.models import User + + +class EventModelTest(TestCase): + @classmethod + def setUpTestData(cls): + user = User.objects.create(email='testuser@email.com') + Event.objects.create(message='Test Event', type=1, user=user) + + def test_event_creation(self): + event = Event.objects.get(id=1) + self.assertEqual(event.message, 'Test Event') + self.assertEqual(event.get_type_name(), 'User registered') + + # Add more tests for other model methods and properties diff --git a/idhub/tests/test_tables.py b/idhub/tests/test_tables.py new file mode 100644 index 0000000..cde5acb --- /dev/null +++ b/idhub/tests/test_tables.py @@ -0,0 +1,65 @@ +from datetime import datetime + +from django.test import TestCase +from django.urls import reverse + +from idhub_auth.models import User +from idhub.admin.tables import DashboardTable +from idhub.models import Event + + +class AdminDashboardTableTest(TestCase): + def setUp(self): + self.admin_user = User.objects.create_superuser( + email='adminuser@mail.com', + password='adminpass12') + + @classmethod + def setUpTestData(cls): + # Creating test events with different dates + Event.objects.create(message='Event 1', type=1, + created=datetime(2023, 1, 3)) + Event.objects.create(message='Event 2', type=2, + created=datetime(2023, 1, 2)) + Event.objects.create(message='Event 3', type=3, + created=datetime(2023, 1, 25)) + + def test_sorting_by_date(self): + # Create the table + table = DashboardTable(Event.objects.all()) + + # Apply sorting + table.order_by = 'created' + + # Fetch the sorted records + sorted_records = list(table.rows) + + # Verify the order is as expected + self.assertTrue(sorted_records[0].record.created + < sorted_records[1].record.created) + self.assertTrue(sorted_records[1].record.created + < sorted_records[2].record.created) + + def test_table_in_template(self): + self.client.login(email='adminuser@mail.com', password='adminpass12') + response = self.client.get(reverse('idhub:admin_dashboard')) + + self.assertTemplateUsed(response, 'idhub/custom_table.html') + + def test_table_data(self): + Event.objects.create(message="test_event", type=2) + Event.objects.create(message="test_event", type=9) + + table = DashboardTable(Event.objects.all()) + self.assertTrue(isinstance(table, DashboardTable)) + self.assertEqual(len(table.rows), Event.objects.count()) + + def test_table_columns(self): + table = DashboardTable(Event.objects.all()) + expected_columns = ['type', 'message', 'created'] + for column in expected_columns: + self.assertIn(column, table.columns) + + def test_pagination(self): + # TODO + pass diff --git a/idhub/tests/test_templates.py b/idhub/tests/test_templates.py new file mode 100644 index 0000000..d04e0ca --- /dev/null +++ b/idhub/tests/test_templates.py @@ -0,0 +1,18 @@ +from django.urls import reverse +from django.test import Client, TestCase + +from idhub_auth.models import User + + +class TemplateTest(TestCase): + def setUp(self): + self.client = Client() + self.admin_user = User.objects.create_superuser( + email='adminuser@mail.com', + password='adminpass12') + + def test_dashboard_template(self): + self.client.login(email='adminuser@mail.com', password='adminpass12') + response = self.client.get(reverse('idhub:admin_dashboard')) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'idhub/base_admin.html') diff --git a/idhub/tests/test_views.py b/idhub/tests/test_views.py new file mode 100644 index 0000000..ee5f3f4 --- /dev/null +++ b/idhub/tests/test_views.py @@ -0,0 +1,50 @@ +from django.urls import reverse +from django.test import TestCase + +from idhub_auth.models import User + + +class AdminDashboardViewTest(TestCase): + + def setUp(self): + self.user = User.objects.create_user(email='normaluser@mail.com', + password='testpass12') + self.admin_user = User.objects.create_superuser( + email='adminuser@mail.com', + password='adminpass12') + + def test_view_url_exists_at_desired_location(self): + response = self.client.get('/admin/dashboard/', follow=True) + + self.assertEqual(response.status_code, 200) + + def test_view_redirects_to_login_when_not_authenticated(self): + response = self.client.get(reverse("idhub:admin_dashboard"), + follow=True) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'auth/login.html') + + def test_view_redirects_on_incorrect_login_attempt(self): + self.client.login(email='adminuser@mail.com', password='wrongpass') + response = self.client.get(reverse('idhub:admin_dashboard')) + + self.assertEqual(response.status_code, 302) + + def test_view_redirects_to_login_on_incorrect_login_attempt(self): + self.client.login(email='adminuser@mail.com', password='wrongpass') + response = self.client.get(reverse('idhub:admin_dashboard'), + follow=True) + + self.assertTemplateUsed(response, 'auth/login.html') + + def test_login_admin_user(self): + self.client.login(email='adminuser@mail.com', password='adminpass12') + response = self.client.get(reverse('idhub:admin_dashboard')) + + self.assertEqual(response.status_code, 200) + + def test_view_uses_correct_template(self): + self.client.login(email='adminuser@mail.com', password='adminpass12') + response = self.client.get(reverse('idhub:admin_dashboard')) + + self.assertTemplateUsed(response, 'idhub/admin/dashboard.html') From ae7cadb738ab83e7d622c0817b36c7185eed313e Mon Sep 17 00:00:00 2001 From: Elahi-cs Date: Mon, 27 Nov 2023 11:23:53 +0100 Subject: [PATCH 10/11] Restored People and Roles to the original tables --- idhub/admin/views.py | 23 +++++++----------- idhub/templates/idhub/admin/people.html | 32 +++++++++++++++++++++++-- idhub/templates/idhub/admin/roles.html | 31 ++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 19 deletions(-) diff --git a/idhub/admin/views.py b/idhub/admin/views.py index b19df1e..f8fd6d0 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -32,9 +32,7 @@ from idhub.admin.forms import ( UserRolForm, ) from idhub.admin.tables import ( - UserTable, - DashboardTable, - RolesTable + DashboardTable ) from idhub.models import ( DID, @@ -84,12 +82,10 @@ class ImportExport(AdminView): section = "ImportExport" -class PeopleListView(People, SingleTableView): +class PeopleListView(People, TemplateView): template_name = "idhub/admin/people.html" subtitle = _('View users') icon = 'bi bi-person' - table_class = UserTable - model = User def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -402,20 +398,17 @@ class PeopleRolDeleteView(PeopleView): return redirect('idhub:admin_people_edit', user.id) -class RolesView(AccessControl, SingleTableView): +class RolesView(AccessControl): template_name = "idhub/admin/roles.html" subtitle = _('Manage roles') icon = '' - table_class = RolesTable - model = Rol def get_context_data(self, **kwargs): - queryset = kwargs.pop('object_list', None) - if queryset is None: - self.object_list = self.model.objects.all() - - return super().get_context_data(**kwargs) - + context = super().get_context_data(**kwargs) + context.update({ + 'roles': Rol.objects, + }) + return context class RolRegisterView(AccessControl, CreateView): template_name = "idhub/admin/rol_register.html" diff --git a/idhub/templates/idhub/admin/people.html b/idhub/templates/idhub/admin/people.html index 4862f82..25b7c61 100644 --- a/idhub/templates/idhub/admin/people.html +++ b/idhub/templates/idhub/admin/people.html @@ -1,11 +1,39 @@ {% extends "idhub/base_admin.html" %} {% load i18n %} -{% load render_table from django_tables2 %} {% block content %}

    {{ subtitle }}

    -{% render_table table %} +
    + + + + + + + + + + + + + {% for user in users %} + + + + + + + + + {% endfor %} + +
    {{ user.last_name|default:'' }}{{ user.first_name|default:'' }}{{ user.email }} + {{ user.get_memberships }} + + {{ user.get_roles }} +
    +
    {% endblock %} diff --git a/idhub/templates/idhub/admin/roles.html b/idhub/templates/idhub/admin/roles.html index 4862f82..25bfd93 100644 --- a/idhub/templates/idhub/admin/roles.html +++ b/idhub/templates/idhub/admin/roles.html @@ -1,11 +1,38 @@ {% extends "idhub/base_admin.html" %} {% load i18n %} -{% load render_table from django_tables2 %} {% block content %}

    {{ subtitle }}

    -{% render_table table %} +
    +
    +
    + + + + + + + + + + + {% for rol in roles.all %} + + + + + + + {% endfor %} + +
    {{ rol.name }}{{ rol.description|default:""}}
    + +
    +
    +
    {% endblock %} From ae60981a08271ebb9eeea0ce4c821be59bc24879 Mon Sep 17 00:00:00 2001 From: Elahi-cs Date: Mon, 27 Nov 2023 11:26:23 +0100 Subject: [PATCH 11/11] Changed testing mail domain to @example.org to avoid potential spamming --- idhub/tests/test_models.py | 2 +- idhub/tests/test_tables.py | 4 ++-- idhub/tests/test_templates.py | 4 ++-- idhub/tests/test_views.py | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/idhub/tests/test_models.py b/idhub/tests/test_models.py index 1709861..62bcdb3 100644 --- a/idhub/tests/test_models.py +++ b/idhub/tests/test_models.py @@ -6,7 +6,7 @@ from idhub_auth.models import User class EventModelTest(TestCase): @classmethod def setUpTestData(cls): - user = User.objects.create(email='testuser@email.com') + user = User.objects.create(email='testuser@example.org') Event.objects.create(message='Test Event', type=1, user=user) def test_event_creation(self): diff --git a/idhub/tests/test_tables.py b/idhub/tests/test_tables.py index cde5acb..a78fde9 100644 --- a/idhub/tests/test_tables.py +++ b/idhub/tests/test_tables.py @@ -11,7 +11,7 @@ from idhub.models import Event class AdminDashboardTableTest(TestCase): def setUp(self): self.admin_user = User.objects.create_superuser( - email='adminuser@mail.com', + email='adminuser@example.org', password='adminpass12') @classmethod @@ -41,7 +41,7 @@ class AdminDashboardTableTest(TestCase): < sorted_records[2].record.created) def test_table_in_template(self): - self.client.login(email='adminuser@mail.com', password='adminpass12') + self.client.login(email='adminuser@example.org', password='adminpass12') response = self.client.get(reverse('idhub:admin_dashboard')) self.assertTemplateUsed(response, 'idhub/custom_table.html') diff --git a/idhub/tests/test_templates.py b/idhub/tests/test_templates.py index d04e0ca..c1b8f3c 100644 --- a/idhub/tests/test_templates.py +++ b/idhub/tests/test_templates.py @@ -8,11 +8,11 @@ class TemplateTest(TestCase): def setUp(self): self.client = Client() self.admin_user = User.objects.create_superuser( - email='adminuser@mail.com', + email='adminuser@example.org', password='adminpass12') def test_dashboard_template(self): - self.client.login(email='adminuser@mail.com', password='adminpass12') + self.client.login(email='adminuser@example.org', password='adminpass12') response = self.client.get(reverse('idhub:admin_dashboard')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'idhub/base_admin.html') diff --git a/idhub/tests/test_views.py b/idhub/tests/test_views.py index ee5f3f4..cb9bbd5 100644 --- a/idhub/tests/test_views.py +++ b/idhub/tests/test_views.py @@ -7,10 +7,10 @@ from idhub_auth.models import User class AdminDashboardViewTest(TestCase): def setUp(self): - self.user = User.objects.create_user(email='normaluser@mail.com', + self.user = User.objects.create_user(email='normaluser@example.org', password='testpass12') self.admin_user = User.objects.create_superuser( - email='adminuser@mail.com', + email='adminuser@example.org', password='adminpass12') def test_view_url_exists_at_desired_location(self): @@ -25,26 +25,26 @@ class AdminDashboardViewTest(TestCase): self.assertTemplateUsed(response, 'auth/login.html') def test_view_redirects_on_incorrect_login_attempt(self): - self.client.login(email='adminuser@mail.com', password='wrongpass') + self.client.login(email='adminuser@example.org', password='wrongpass') response = self.client.get(reverse('idhub:admin_dashboard')) self.assertEqual(response.status_code, 302) def test_view_redirects_to_login_on_incorrect_login_attempt(self): - self.client.login(email='adminuser@mail.com', password='wrongpass') + self.client.login(email='adminuser@example.org', password='wrongpass') response = self.client.get(reverse('idhub:admin_dashboard'), follow=True) self.assertTemplateUsed(response, 'auth/login.html') def test_login_admin_user(self): - self.client.login(email='adminuser@mail.com', password='adminpass12') + self.client.login(email='adminuser@example.org', password='adminpass12') response = self.client.get(reverse('idhub:admin_dashboard')) self.assertEqual(response.status_code, 200) def test_view_uses_correct_template(self): - self.client.login(email='adminuser@mail.com', password='adminpass12') + self.client.login(email='adminuser@example.org', password='adminpass12') response = self.client.get(reverse('idhub:admin_dashboard')) self.assertTemplateUsed(response, 'idhub/admin/dashboard.html')