From 6a66a37ccdc2eac68fc78732833031ca2c9f9889 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sat, 26 Jan 2019 13:04:11 -0500 Subject: [PATCH 1/2] Fixed theme settings page, added tests --- app/tests/test_app.py | 21 +++++++++++++++++++++ requirements.txt | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/tests/test_app.py b/app/tests/test_app.py index 5708c14b..60b44f3c 100644 --- a/app/tests/test_app.py +++ b/app/tests/test_app.py @@ -69,6 +69,10 @@ class TestApp(BootTestCase): # We should have a project created from the dashboard self.assertTrue(Project.objects.count() >= 1) + # Can access API page + res = c.get('/api/') + self.assertTrue(res.status_code == status.HTTP_200_OK) + # We can access a processingnode view that exists res = c.get('/processingnode/1/') self.assertTrue(res.status_code == 200) @@ -143,8 +147,25 @@ class TestApp(BootTestCase): ac = Client() test_public_views(ac, status.HTTP_200_OK) + def test_admin_views(self): + c = Client() + c.login(username="testsuperuser", password="test1234") + # Can access admin menu items + admin_menu_items = ['/admin/app/setting/1/change/', + '/admin/app/theme/1/change/', + '/admin/', + ] + for url in admin_menu_items: + res = c.get(url) + self.assertEqual(res.status_code, status.HTTP_200_OK) + # Cannot access admin views as normal user + c.login(username=self.credentials['username'], password=self.credentials['password']) + + for url in admin_menu_items: + res = c.get(url, follow=True) + self.assertRedirects(res, '/admin/login/?next={}'.format(url)) def test_default_group(self): diff --git a/requirements.txt b/requirements.txt index 089357a0..051fa566 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ coreapi==2.0.9 Django==2.1.5 django-appconf==1.0.2 django-codemirror2==0.2 -django-colorfield==0.1.14 +django-colorfield==0.1.15 django-compressor==2.2 django-cors-headers==2.2.0 django-filter==2.0.0 From 07998d0ec227ee1f0b65f06e02887ee45482e278 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sat, 26 Jan 2019 14:52:42 -0500 Subject: [PATCH 2/2] Fixed unit test --- app/tests/test_app.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/tests/test_app.py b/app/tests/test_app.py index 60b44f3c..6b3f4337 100644 --- a/app/tests/test_app.py +++ b/app/tests/test_app.py @@ -3,6 +3,8 @@ from django.test import Client from rest_framework import status from app.models import Project, Task +from app.models import Setting +from app.models import Theme from .classes import BootTestCase from django.core.exceptions import ValidationError @@ -21,8 +23,6 @@ class TestApp(BootTestCase): # Add user to test Group User.objects.get(pk=1).groups.add(my_group) - def tearDown(self): - pass def test_user_login(self): c = Client() @@ -149,19 +149,24 @@ class TestApp(BootTestCase): def test_admin_views(self): c = Client() - c.login(username="testsuperuser", password="test1234") + c.login(username='testsuperuser', password='test1234') + + settingId = Setting.objects.all()[0].id # During tests, sometimes this is != 1 + themeId = Theme.objects.all()[0].id # During tests, sometimes this is != 1 # Can access admin menu items - admin_menu_items = ['/admin/app/setting/1/change/', - '/admin/app/theme/1/change/', + admin_menu_items = ['/admin/app/setting/{}/change/'.format(settingId), + '/admin/app/theme/{}/change/'.format(themeId), '/admin/', ] + for url in admin_menu_items: res = c.get(url) self.assertEqual(res.status_code, status.HTTP_200_OK) # Cannot access admin views as normal user - c.login(username=self.credentials['username'], password=self.credentials['password']) + c.logout() + c.login(username='testuser', password='test1234') for url in admin_menu_items: res = c.get(url, follow=True)