Skip to content

Commit

Permalink
[#137] Institute nag message for profile completion
Browse files Browse the repository at this point in the history
  • Loading branch information
philtuskha committed Apr 19, 2018
1 parent 67a507a commit a5df935
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
16 changes: 9 additions & 7 deletions hs_core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 10 additions & 10 deletions hs_core/tests/api/views/test_profile_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -82,21 +80,23 @@ 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
# on a view when a user has not filled out their profile
# 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')
Expand Down

0 comments on commit a5df935

Please sign in to comment.