diff --git a/django_v2/test_app/tests/base_tests/test_models.py b/django_v2/test_app/tests/base_tests/test_models.py index 5ab609d87eed7b9a9f9de76af8b3c501f44444d4..2bf5ccff78baef90b15ffe5c976e3b3c4951b972 100644 --- a/django_v2/test_app/tests/base_tests/test_models.py +++ b/django_v2/test_app/tests/base_tests/test_models.py @@ -76,13 +76,16 @@ class ModelTestCase(TestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - if response.context is not None: - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" diff --git a/django_v2/test_app/tests/base_tests/test_views.py b/django_v2/test_app/tests/base_tests/test_views.py index 5e07b92fbda587d286d769fd85d9e4da4dfa44cc..6be565223ddca5ca7c6192fea69bd76a9748d035 100644 --- a/django_v2/test_app/tests/base_tests/test_views.py +++ b/django_v2/test_app/tests/base_tests/test_views.py @@ -74,13 +74,16 @@ class ViewTestCase(TestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - if response.context is not None: - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" diff --git a/django_v2/test_app/tests/etc_tests/test_models.py b/django_v2/test_app/tests/etc_tests/test_models.py index 444c9dd67048b0f9bde10ff770c8912f036bdbe1..926fdab9f77db2e1c2b69cadbadd78f76fe8ef5c 100644 --- a/django_v2/test_app/tests/etc_tests/test_models.py +++ b/django_v2/test_app/tests/etc_tests/test_models.py @@ -43,13 +43,16 @@ class ModelTestCase(IntegrationTestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - if response.context is not None: - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" @@ -159,12 +162,16 @@ class ModelTestCase(IntegrationTestCase): self.assertTrue(isinstance(uwsgi_user, AnonymousUser)) self.assertFalse(isinstance(uwsgi_user, get_user_model())) self.assertNotEqual(self.test_inactive_user, uwsgi_user) + self.assertTrue(isinstance(response.user, AnonymousUser)) + self.assertFalse(isinstance(response.user, get_user_model())) # Try again, to make sure that accessing any of the above values didn't somehow clear the client. self.assertEqual(self.test_inactive_user.pk, int(self.client.session.get('_auth_user_id', None))) self.assertTrue(isinstance(uwsgi_user, AnonymousUser)) self.assertFalse(isinstance(uwsgi_user, get_user_model())) self.assertNotEqual(self.test_inactive_user, uwsgi_user) + self.assertTrue(isinstance(response.user, AnonymousUser)) + self.assertFalse(isinstance(response.user, get_user_model())) with self.subTest('Check login using standard user'): # Get response object. diff --git a/django_v2/test_app/tests/etc_tests/test_views.py b/django_v2/test_app/tests/etc_tests/test_views.py index f65fded4d48186f5d6cd39f0260b8090a0a113eb..e31e1f33f9b3d0e2fbe37e480a2523ebc5be88bf 100644 --- a/django_v2/test_app/tests/etc_tests/test_views.py +++ b/django_v2/test_app/tests/etc_tests/test_views.py @@ -41,13 +41,16 @@ class ViewTestCase(IntegrationTestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - if response.context is not None: - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" diff --git a/django_v2/test_app/urls.py b/django_v2/test_app/urls.py index 64e1c14a921dab94c72e2c75590411881040d5f4..84b947941aa733af9c7e4e729f193ef0232abd66 100644 --- a/django_v2/test_app/urls.py +++ b/django_v2/test_app/urls.py @@ -12,9 +12,9 @@ from . import views app_name = 'test_app' urlpatterns = [ # Test views that have various login/permission requirements. - path('view_with_login_check', views.view_with_login_check, name='view_with_login_check'), - path('view_with_permission_check', views.view_with_permission_check, name='view_with_permission_check'), - path('view_with_group_check', views.view_with_group_check, name='view_with_group_check'), + path('view_with_login_check/', views.view_with_login_check, name='view_with_login_check'), + path('view_with_permission_check/', views.view_with_permission_check, name='view_with_permission_check'), + path('view_with_group_check/', views.view_with_group_check, name='view_with_group_check'), # App root. path('', views.index, name='index') diff --git a/django_v3/test_app/tests/base_tests/test_models.py b/django_v3/test_app/tests/base_tests/test_models.py index f187c64079dead3119ba630366bde59c2b1eadcf..737ea488e7eb6b9847c20abb20989c805e5f62e5 100644 --- a/django_v3/test_app/tests/base_tests/test_models.py +++ b/django_v3/test_app/tests/base_tests/test_models.py @@ -76,12 +76,16 @@ class ModelTestCase(TestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" diff --git a/django_v3/test_app/tests/base_tests/test_views.py b/django_v3/test_app/tests/base_tests/test_views.py index d8d537431ad47b3290f3df93e7d488866d922f09..43ca3086b0fb695bcb703f8a2020c298f3161609 100644 --- a/django_v3/test_app/tests/base_tests/test_views.py +++ b/django_v3/test_app/tests/base_tests/test_views.py @@ -74,13 +74,16 @@ class ViewTestCase(TestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - if response.context is not None: - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" diff --git a/django_v3/test_app/tests/etc_tests/test_models.py b/django_v3/test_app/tests/etc_tests/test_models.py index 14a0a8473018d9eea61352a501fe7634234a5b9a..8b4bea160f1724208a20492762113bc6b5b905c8 100644 --- a/django_v3/test_app/tests/etc_tests/test_models.py +++ b/django_v3/test_app/tests/etc_tests/test_models.py @@ -43,12 +43,16 @@ class ModelTestCase(IntegrationTestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" @@ -162,14 +166,16 @@ class ModelTestCase(IntegrationTestCase): self.assertTrue(isinstance(uwsgi_user, AnonymousUser)) self.assertFalse(isinstance(uwsgi_user, get_user_model())) self.assertNotEqual(self.test_inactive_user, uwsgi_user) - self.assertIsNone(response.user) + self.assertTrue(isinstance(response.user, AnonymousUser)) + self.assertFalse(isinstance(response.user, get_user_model())) # Try again, to make sure that accessing any of the above values didn't somehow clear the client. self.assertEqual(self.test_inactive_user.pk, int(self.client.session.get('_auth_user_id', None))) self.assertTrue(isinstance(uwsgi_user, AnonymousUser)) self.assertFalse(isinstance(uwsgi_user, get_user_model())) self.assertNotEqual(self.test_inactive_user, uwsgi_user) - self.assertIsNone(response.user) + self.assertTrue(isinstance(response.user, AnonymousUser)) + self.assertFalse(isinstance(response.user, get_user_model())) with self.subTest('Check login using standard user'): # Get response object. diff --git a/django_v3/test_app/tests/etc_tests/test_views.py b/django_v3/test_app/tests/etc_tests/test_views.py index 8ab1beb6ebc6c46efd9903e9d94a31a0e1b08598..abc2ec4302405310d876c071affacc39245a1d5d 100644 --- a/django_v3/test_app/tests/etc_tests/test_views.py +++ b/django_v3/test_app/tests/etc_tests/test_views.py @@ -41,13 +41,16 @@ class ViewTestCase(IntegrationTestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - if response.context is not None: - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" diff --git a/django_v3/test_app/urls.py b/django_v3/test_app/urls.py index d91454398f94e8e00719702bd7dc69080cd9344d..116c5b7156a577b87854ef7dee19f86200680336 100644 --- a/django_v3/test_app/urls.py +++ b/django_v3/test_app/urls.py @@ -12,9 +12,9 @@ from . import views app_name = 'test_app' urlpatterns = [ # Test views that have various login/permission requirements. - path('view_with_login_check', views.view_with_login_check, name='view_with_login_check'), - path('view_with_permission_check', views.view_with_permission_check, name='view_with_permission_check'), - path('view_with_group_check', views.view_with_group_check, name='view_with_group_check'), + path('view_with_login_check/', views.view_with_login_check, name='view_with_login_check'), + path('view_with_permission_check/', views.view_with_permission_check, name='view_with_permission_check'), + path('view_with_group_check/', views.view_with_group_check, name='view_with_group_check'), # App root. path('', views.index, name='index') diff --git a/django_v4/test_app/tests/base_tests/test_models.py b/django_v4/test_app/tests/base_tests/test_models.py index 205ed3814730d8b7942ee3ca7088251e0e97add7..250373a93da01ae78d17984d25833f3d8a88ea08 100644 --- a/django_v4/test_app/tests/base_tests/test_models.py +++ b/django_v4/test_app/tests/base_tests/test_models.py @@ -76,12 +76,16 @@ class ModelTestCase(TestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" diff --git a/django_v4/test_app/tests/base_tests/test_views.py b/django_v4/test_app/tests/base_tests/test_views.py index 56fe7a9ff37fb083941aa23df31ba4586ebf7ffe..181c20e1fb381166a327bbd816be40e00faa5a7e 100644 --- a/django_v4/test_app/tests/base_tests/test_views.py +++ b/django_v4/test_app/tests/base_tests/test_views.py @@ -74,13 +74,16 @@ class ViewTestCase(TestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - if response.context is not None: - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" diff --git a/django_v4/test_app/tests/etc_tests/test_models.py b/django_v4/test_app/tests/etc_tests/test_models.py index 6f3ed21ecfeada5e5f8ad2dde9d46448363962fc..ed5139df9a450f5829ece5f0f2464baf333d1470 100644 --- a/django_v4/test_app/tests/etc_tests/test_models.py +++ b/django_v4/test_app/tests/etc_tests/test_models.py @@ -43,12 +43,16 @@ class ModelTestCase(IntegrationTestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" @@ -158,12 +162,16 @@ class ModelTestCase(IntegrationTestCase): self.assertTrue(isinstance(uwsgi_user, AnonymousUser)) self.assertFalse(isinstance(uwsgi_user, get_user_model())) self.assertNotEqual(self.test_inactive_user, uwsgi_user) + self.assertTrue(isinstance(response.user, AnonymousUser)) + self.assertFalse(isinstance(response.user, get_user_model())) # Try again, to make sure that accessing any of the above values didn't somehow clear the client. self.assertEqual(self.test_inactive_user.pk, int(self.client.session.get('_auth_user_id', None))) self.assertTrue(isinstance(uwsgi_user, AnonymousUser)) self.assertFalse(isinstance(uwsgi_user, get_user_model())) self.assertNotEqual(self.test_inactive_user, uwsgi_user) + self.assertTrue(isinstance(response.user, AnonymousUser)) + self.assertFalse(isinstance(response.user, get_user_model())) with self.subTest('Check login using standard user'): # Get response object. diff --git a/django_v4/test_app/tests/etc_tests/test_views.py b/django_v4/test_app/tests/etc_tests/test_views.py index 54a17a141fb968b614922e979668081d07fd018f..af9f44c3141758704612022e361c4b580fb32337 100644 --- a/django_v4/test_app/tests/etc_tests/test_views.py +++ b/django_v4/test_app/tests/etc_tests/test_views.py @@ -42,13 +42,16 @@ class ViewTestCase(IntegrationTestCase): """Prints out all context values to terminal.""" print('{0} {1} {0}'.format('=' * 10, 'response.context')) - if response.context is not None: - for key in response.context.keys(): - context_value = str(response.context.get(key)) - # Truncate display if very long. - if len(context_value) > 80: - context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) - print(' * {0}: {1}'.format(key, context_value)) + try: + if response.context is not None: + for key in response.context.keys(): + context_value = str(response.context.get(key)) + # Truncate display if very long. + if len(context_value) > 80: + context_value = '"{0}"..."{1}"'.format(context_value[:40], context_value[-40:]) + print(' * {0}: {1}'.format(key, context_value)) + except AttributeError: + pass def display_session(self): """Prints out all session values to terminal.""" @@ -227,7 +230,7 @@ class ViewTestCase(IntegrationTestCase): with self.subTest('Check views without login'): # Get response object. - response = self.assertGetResponse('test_app:view_with_permission_check', login=False) + response = self.assertGetResponse('test_app:view_with_permission_check', auto_login=False) # Display debug data to console on test failure. self.debug_data(response) diff --git a/django_v4/test_app/urls.py b/django_v4/test_app/urls.py index fdf8584176d237676e1479056e8a3e0decc984a4..a71f531863162eeba0acecfe369ee0ae6ef01d75 100644 --- a/django_v4/test_app/urls.py +++ b/django_v4/test_app/urls.py @@ -12,9 +12,9 @@ from . import views app_name = 'test_app' urlpatterns = [ # Test views that have various login/permission requirements. - path('view_with_login_check', views.view_with_login_check, name='view_with_login_check'), - path('view_with_permission_check', views.view_with_permission_check, name='view_with_permission_check'), - path('view_with_group_check', views.view_with_group_check, name='view_with_group_check'), + path('view_with_login_check/', views.view_with_login_check, name='view_with_login_check'), + path('view_with_permission_check/', views.view_with_permission_check, name='view_with_permission_check'), + path('view_with_group_check/', views.view_with_group_check, name='view_with_group_check'), # App root. path('', views.index, name='index')