diff --git a/hs_core/decorators.py b/hs_core/decorators.py index eee7ebd498..917cdf4e5b 100644 --- a/hs_core/decorators.py +++ b/hs_core/decorators.py @@ -13,13 +13,15 @@ def profile_required(view_func): @wraps(view_func, assigned=available_attrs(view_func)) def _wrapped_view(request, *args, **kwargs): profile = request.user.userprofile - profile_valid = (profile.middle_name and - profile.state and - profile.zipcode and - profile.country and - profile.date_of_birth and - profile.last_four_ss and - profile.phone_1) + profile_valid = ( + profile.middle_name and + profile.state and + profile.zipcode and + profile.country and + profile.date_of_birth and + profile.last_four_ss and + profile.phone_1 + ) if profile_valid: return view_func(request, *args, **kwargs) else: diff --git a/hs_core/tests/api/views/test_profile_required.py b/hs_core/tests/api/views/test_profile_required.py index c5386c96d3..447d0e4eea 100644 --- a/hs_core/tests/api/views/test_profile_required.py +++ b/hs_core/tests/api/views/test_profile_required.py @@ -6,11 +6,10 @@ from rest_framework import status -from mezzanine.pages.models import Page from mezzanine.pages.models import RichTextPage from hs_core import hydroshare -from hs_core.views import create_resource_select_resource_type, my_resources +from hs_core.views import create_resource_select_resource_type from hs_core.testing import MockIRODSTestCaseMixin, ViewTestCase @@ -64,11 +63,10 @@ def test_view_create_resource_profile_not_complete(self): # on a view when a user has not filled out their profile # removing fields from profile - self.user.userprofile.last_four_ss=None - self.user.userprofile.phone_1=None + self.user.userprofile.last_four_ss = None + self.user.userprofile.phone_1 = None self.user.userprofile.save() - url = reverse('create_resource_select_resource_type') request = self.factory.get(url) request.user = self.user @@ -82,12 +80,14 @@ def test_view_create_resource_profile_not_complete(self): redirect_url = response._headers['location'][1] self.assertEqual(redirect_url, "/my-documents/#_") + self.assertRedirects(response, "/my-documents/#_") + my_documents_page, _ = RichTextPage.objects.get_or_create(title='My Documents', slug='my-documents') - response2 = self.client.get(redirect_url, follow=True) + response = self.client.get(redirect_url, follow=True) # seeing if the redirect was successful and that the page - self.assertEqual(response2.status_code, status.HTTP_200_OK) - self.assertEqual(response2.context[-1]['_current_page'].id, my_documents_page.id) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.context[-1]['_current_page'].id, my_documents_page.id) def test_view_create_resource_profile_not_complete_with_referer(self): # here we are testing the profile_required decorator @@ -95,8 +95,8 @@ def test_view_create_resource_profile_not_complete_with_referer(self): # and where the user is coming from a specific page # removing fields from profile - self.user.userprofile.last_four_ss=None - self.user.userprofile.phone_1=None + self.user.userprofile.last_four_ss = None + self.user.userprofile.phone_1 = None self.user.userprofile.save() url = reverse('create_resource_select_resource_type')