-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1456 from onaio/track_password_edit
Track password edit
- Loading branch information
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,12 @@ | |
from django.test import TransactionTestCase | ||
from datetime import timedelta | ||
from django.utils.timezone import now | ||
from rest_framework.test import APIRequestFactory | ||
from onadata.apps.api.tests.viewsets.test_abstract_viewset import \ | ||
TestAbstractViewSet | ||
|
||
from onadata.libs.serializers.user_profile_serializer import\ | ||
UserProfileWithTokenSerializer | ||
UserProfileWithTokenSerializer, UserProfileSerializer | ||
from onadata.apps.main.models import UserProfile | ||
from onadata.apps.api.models.temp_token import TempToken | ||
from onadata.libs.authentication import expired | ||
|
@@ -45,7 +48,7 @@ def create_user_profile(profile_data): | |
return new_profile | ||
|
||
|
||
class TestUserProfileSerializer(TransactionTestCase): | ||
class TestUserProfileWithTokenSerializer(TransactionTestCase): | ||
|
||
def setUp(self): | ||
self.serializer = UserProfileWithTokenSerializer() | ||
|
@@ -75,3 +78,25 @@ def test_get_temp_token_recreates_if_expired(self): | |
is_expired = expired(temp_token.created) | ||
|
||
self.assertFalse(is_expired) | ||
|
||
|
||
class TestUserProfileSerializer(TestAbstractViewSet): | ||
|
||
def test_metadata_view_for_owner_only(self): | ||
request = APIRequestFactory().get('/') | ||
alice_data = {'username': 'alice', 'email': '[email protected]'} | ||
bob_profile = self._create_user_profile() | ||
alice_profile = self._create_user_profile(extra_post_data=alice_data) | ||
request.user = bob_profile.user | ||
bob_serializer = UserProfileSerializer( | ||
instance=bob_profile, | ||
context={'request': request}) | ||
self.assertIn('metadata', bob_serializer.data.keys()) | ||
alice_serializer = UserProfileSerializer( | ||
instance=alice_profile, | ||
context={'request': request}) | ||
self.assertNotIn('metadata', alice_serializer.data.keys()) | ||
self.assertEqual(bob_profile.user.username, | ||
bob_serializer.data['username']) | ||
self.assertEqual(alice_profile.user.username, | ||
alice_serializer.data['username']) |