From dcc0e53062576552e09f4a5c56e96bdf9ee85c6c Mon Sep 17 00:00:00 2001 From: Arona Jones Date: Thu, 17 Sep 2020 09:08:00 +0100 Subject: [PATCH] Various misc fixes --- PyRIGS/settings.py | 4 +- PyRIGS/urls.py | 3 +- RIGS/templates/event_table.html | 9 +--- assets/tests/test_assets.py | 43 ------------------- .../registration/activation_complete.html | 0 .../registration/activation_email.txt | 0 .../registration/activation_email_subject.txt | 0 .../registration/logged_out.html | 0 .../registration/login.html | 0 .../registration/login_embed.html | 0 .../registration/loginform.html | 0 .../registration/password_change_done.html | 0 .../registration/password_change_form.html | 0 .../registration/password_reset_complete.html | 0 .../registration/password_reset_confirm.html | 0 .../registration/password_reset_done.html | 0 .../registration/password_reset_email.html | 0 .../registration/password_reset_form.html | 0 .../registration/registration_complete.html | 0 .../registration/registration_form.html | 0 users/urls.py | 6 +-- versioning/tests/test_versioning.py | 31 +++++++++++++ versioning/versioning.py | 2 +- 23 files changed, 41 insertions(+), 57 deletions(-) rename {users/templates => templates}/registration/activation_complete.html (100%) rename {users/templates => templates}/registration/activation_email.txt (100%) rename {users/templates => templates}/registration/activation_email_subject.txt (100%) rename {users/templates => templates}/registration/logged_out.html (100%) rename {users/templates => templates}/registration/login.html (100%) rename {users/templates => templates}/registration/login_embed.html (100%) rename {users/templates => templates}/registration/loginform.html (100%) rename {users/templates => templates}/registration/password_change_done.html (100%) rename {users/templates => templates}/registration/password_change_form.html (100%) rename {users/templates => templates}/registration/password_reset_complete.html (100%) rename {users/templates => templates}/registration/password_reset_confirm.html (100%) rename {users/templates => templates}/registration/password_reset_done.html (100%) rename {users/templates => templates}/registration/password_reset_email.html (100%) rename {users/templates => templates}/registration/password_reset_form.html (100%) rename {users/templates => templates}/registration/registration_complete.html (100%) rename {users/templates => templates}/registration/registration_form.html (100%) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 685cd6bb..e8d46fed 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -28,6 +28,8 @@ DEBUG = bool(int(os.environ.get('DEBUG'))) if os.environ.get('DEBUG') else True STAGING = bool(int(os.environ.get('STAGING'))) if os.environ.get('STAGING') else False +CI = bool(int(os.environ.get('CI'))) if os.environ.get('CI') else False + ALLOWED_HOSTS = ['pyrigs.nottinghamtec.co.uk', 'rigs.nottinghamtec.co.uk', 'pyrigs.herokuapp.com'] if STAGING: @@ -158,7 +160,7 @@ CACHES = { } } # Tests lock up SQLite otherwise -if DEBUG or STAGING: +if DEBUG or STAGING or CI: CACHES['default'] = { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' } diff --git a/PyRIGS/urls.py b/PyRIGS/urls.py index e4a675e4..525480b3 100644 --- a/PyRIGS/urls.py +++ b/PyRIGS/urls.py @@ -15,7 +15,6 @@ import versioning from PyRIGS import views urlpatterns = [ - path('', include('users.urls')), path('', include('versioning.urls')), path('', include('RIGS.urls')), path('assets/', include('assets.urls')), @@ -31,6 +30,8 @@ urlpatterns = [ path('closemodal/', views.CloseModal.as_view(), name='closemodal'), path('search_help/', views.SearchHelp.as_view(), name='search_help'), + path('', include('users.urls')), + path('admin/', admin.site.urls), ] diff --git a/RIGS/templates/event_table.html b/RIGS/templates/event_table.html index 012a7f27..418f8f88 100644 --- a/RIGS/templates/event_table.html +++ b/RIGS/templates/event_table.html @@ -1,6 +1,5 @@ {% load namewithnotes from filters %} -{% comment %}
{% endcomment %} -
+
@@ -87,9 +86,3 @@
-{% comment %} -
-
- {% include 'event_table_mobile.html' %} -
-{% endcomment %} diff --git a/assets/tests/test_assets.py b/assets/tests/test_assets.py index c73286af..dd7db6b9 100644 --- a/assets/tests/test_assets.py +++ b/assets/tests/test_assets.py @@ -549,49 +549,6 @@ class TestSampleDataGenerator(TestCase): self.assertRaisesRegex(CommandError, ".*production", call_command, 'deleteSampleData') -class TestVersioningViews(TestCase): - @classmethod - def setUpTestData(cls): - cls.profile = rigsmodels.Profile.objects.create(username="VersionTest", email="version@test.com", is_superuser=True, is_active=True, is_staff=True) - - working = models.AssetStatus.objects.create(name="Working", should_show=True) - broken = models.AssetStatus.objects.create(name="Broken", should_show=False) - general = models.AssetCategory.objects.create(name="General") - lighting = models.AssetCategory.objects.create(name="Lighting") - - cls.assets = {} - - with reversion.create_revision(): - reversion.set_user(cls.profile) - cls.assets[1] = models.Asset.objects.create(asset_id="1991", description="Spaceflower", status=broken, category=lighting, date_acquired=datetime.date(1991, 12, 26)) - - with reversion.create_revision(): - reversion.set_user(cls.profile) - cls.assets[2] = models.Asset.objects.create(asset_id="0001", description="Virgil", status=working, category=lighting, date_acquired=datetime.date(2015, 1, 1)) - - with reversion.create_revision(): - reversion.set_user(cls.profile) - cls.assets[1].status = working - cls.assets[1].save() - - def setUp(self): - self.profile.set_password('testuser') - self.profile.save() - self.assertTrue(self.client.login(username=self.profile.username, password='testuser')) - - def test_history_loads_successfully(self): - request_url = reverse('asset_history', kwargs={'pk': self.assets[1].asset_id}) - - response = self.client.get(request_url, follow=True) - self.assertEqual(response.status_code, 200) - - def test_activity_table_loads_successfully(self): - request_url = reverse('assets_activity_table') - - response = self.client.get(request_url, follow=True) - self.assertEqual(response.status_code, 200) - - class TestEmbeddedViews(TestCase): @classmethod def setUpTestData(cls): diff --git a/users/templates/registration/activation_complete.html b/templates/registration/activation_complete.html similarity index 100% rename from users/templates/registration/activation_complete.html rename to templates/registration/activation_complete.html diff --git a/users/templates/registration/activation_email.txt b/templates/registration/activation_email.txt similarity index 100% rename from users/templates/registration/activation_email.txt rename to templates/registration/activation_email.txt diff --git a/users/templates/registration/activation_email_subject.txt b/templates/registration/activation_email_subject.txt similarity index 100% rename from users/templates/registration/activation_email_subject.txt rename to templates/registration/activation_email_subject.txt diff --git a/users/templates/registration/logged_out.html b/templates/registration/logged_out.html similarity index 100% rename from users/templates/registration/logged_out.html rename to templates/registration/logged_out.html diff --git a/users/templates/registration/login.html b/templates/registration/login.html similarity index 100% rename from users/templates/registration/login.html rename to templates/registration/login.html diff --git a/users/templates/registration/login_embed.html b/templates/registration/login_embed.html similarity index 100% rename from users/templates/registration/login_embed.html rename to templates/registration/login_embed.html diff --git a/users/templates/registration/loginform.html b/templates/registration/loginform.html similarity index 100% rename from users/templates/registration/loginform.html rename to templates/registration/loginform.html diff --git a/users/templates/registration/password_change_done.html b/templates/registration/password_change_done.html similarity index 100% rename from users/templates/registration/password_change_done.html rename to templates/registration/password_change_done.html diff --git a/users/templates/registration/password_change_form.html b/templates/registration/password_change_form.html similarity index 100% rename from users/templates/registration/password_change_form.html rename to templates/registration/password_change_form.html diff --git a/users/templates/registration/password_reset_complete.html b/templates/registration/password_reset_complete.html similarity index 100% rename from users/templates/registration/password_reset_complete.html rename to templates/registration/password_reset_complete.html diff --git a/users/templates/registration/password_reset_confirm.html b/templates/registration/password_reset_confirm.html similarity index 100% rename from users/templates/registration/password_reset_confirm.html rename to templates/registration/password_reset_confirm.html diff --git a/users/templates/registration/password_reset_done.html b/templates/registration/password_reset_done.html similarity index 100% rename from users/templates/registration/password_reset_done.html rename to templates/registration/password_reset_done.html diff --git a/users/templates/registration/password_reset_email.html b/templates/registration/password_reset_email.html similarity index 100% rename from users/templates/registration/password_reset_email.html rename to templates/registration/password_reset_email.html diff --git a/users/templates/registration/password_reset_form.html b/templates/registration/password_reset_form.html similarity index 100% rename from users/templates/registration/password_reset_form.html rename to templates/registration/password_reset_form.html diff --git a/users/templates/registration/registration_complete.html b/templates/registration/registration_complete.html similarity index 100% rename from users/templates/registration/registration_complete.html rename to templates/registration/registration_complete.html diff --git a/users/templates/registration/registration_form.html b/templates/registration/registration_form.html similarity index 100% rename from users/templates/registration/registration_form.html rename to templates/registration/registration_form.html diff --git a/users/urls.py b/users/urls.py index 7fc9303d..3d59c9b6 100644 --- a/users/urls.py +++ b/users/urls.py @@ -11,8 +11,6 @@ from PyRIGS.decorators import permission_required_with_403 from users import regbackend, forms, views urlpatterns = [ - path('user/', include('django.contrib.auth.urls')), - path('user/', include('registration.backends.default.urls')), path('user/register/', RegistrationView.as_view(form_class=forms.ProfileRegistrationFormUniqueEmail), name="registration_register"), path('user/login/', LoginView.as_view(authentication_form=forms.CheckApprovedForm), name='login'), @@ -23,7 +21,9 @@ urlpatterns = [ path('user/reset_api_key', login_required(views.ResetApiKey.as_view(permanent=False)), name='reset_api_key'), path('user/', login_required(views.ProfileDetail.as_view()), name='profile_detail'), - path('user//', + path('user//', permission_required_with_403('RIGS.view_profile')(views.ProfileDetail.as_view()), name='profile_detail'), + path('user/', include('django.contrib.auth.urls')), + path('user/', include('registration.backends.default.urls')), ] diff --git a/versioning/tests/test_versioning.py b/versioning/tests/test_versioning.py index 9f724b8e..1bf9526b 100644 --- a/versioning/tests/test_versioning.py +++ b/versioning/tests/test_versioning.py @@ -221,6 +221,26 @@ class TestVersioningViews(TestCase): cls.events[1].description = "A test description" cls.events[1].save() + working = models.AssetStatus.objects.create(name="Working", should_show=True) + broken = models.AssetStatus.objects.create(name="Broken", should_show=False) + general = models.AssetCategory.objects.create(name="General") + lighting = models.AssetCategory.objects.create(name="Lighting") + + cls.assets = {} + + with reversion.create_revision(): + reversion.set_user(cls.profile) + cls.assets[1] = models.Asset.objects.create(asset_id="1991", description="Spaceflower", status=broken, category=lighting, date_acquired=datetime.date(1991, 12, 26)) + + with reversion.create_revision(): + reversion.set_user(cls.profile) + cls.assets[2] = models.Asset.objects.create(asset_id="0001", description="Virgil", status=working, category=lighting, date_acquired=datetime.date(2015, 1, 1)) + + with reversion.create_revision(): + reversion.set_user(cls.profile) + cls.assets[1].status = working + cls.assets[1].save() + def setUp(self): self.profile.set_password('testuser') self.profile.save() @@ -244,6 +264,17 @@ class TestVersioningViews(TestCase): response = self.client.get(request_url, follow=True) self.assertEqual(response.status_code, 200) + request_url = reverse('assets_activity_table') + + response = self.client.get(request_url, follow=True) + self.assertEqual(response.status_code, 200) + + def test_asset_history_loads_successfully(self): + request_url = reverse('asset_history', kwargs={'pk': self.assets[1].asset_id}) + + response = self.client.get(request_url, follow=True) + self.assertEqual(response.status_code, 200) + # Some edge cases that have caused server errors in the past def test_deleted_event(self): request_url = reverse('activity_feed') diff --git a/versioning/versioning.py b/versioning/versioning.py index c6afcbae..4546c0d7 100644 --- a/versioning/versioning.py +++ b/versioning/versioning.py @@ -123,7 +123,7 @@ class ModelComparison(object): old_item_versions = self.version.parent.revision.version_set.exclude(content_type=item_type) new_item_versions = self.version.revision.version_set.exclude(content_type=item_type) - comparisonParams = {'excluded_keys': ['id', 'event', 'order', 'checklist']} + comparisonParams = {'excluded_keys': ['id', 'event', 'order', 'checklist', 'invoice']} # Build some dicts of what we have item_dict = {} # build a list of items, key is the item_pk