예제 #1
0
    def update_account(self, pk):
        user = get_user(pk)

        originator = get_user(self.request)
        if not originator.is_superuser or originator.pk == user.pk:
            raise exceptions.PermissionDenied("user must be superuser to change an account other than their own")

        kwargs = json.loads(self.request.REQUEST.get('user', self.request.body))
        hydroshare.update_account(user, **kwargs)
        return HttpResponse(pk, content_type='text/plain')
예제 #2
0
    def update_account(self, pk):
        user = get_user(pk)

        originator = get_user(self.request)
        if not originator.is_superuser or originator.pk == user.pk:
            raise exceptions.PermissionDenied(
                "user must be superuser to change an account other than their own"
            )

        kwargs = json.loads(self.request.REQUEST.get('user',
                                                     self.request.body))
        hydroshare.update_account(user, **kwargs)
        return HttpResponse(pk, content_type='text/plain')
예제 #3
0
    def test_basic(self):
        kwargs = {'groups': ('group0'),
                  'email': '*****@*****.**',
                  'username': '******',
                  'first_name': 'john',
                  'last_name': 'livingston',
                  'notes': 'these are some notes'}

        hydroshare.update_account(self.user, **kwargs)

        self.assertEqual(self.user.email, '*****@*****.**')
        self.assertEqual(self.user.first_name, 'john')
        self.assertEqual(self.user.last_name, 'livingston')
        self.assertEqual(self.user.get_profile().notes, 'these are some notes')
        self.assertTrue(Group.objects.filter(user=self.user).exists)
예제 #4
0
    def test_basic(self):
        kwargs = {
            "groups": ("group0"),
            "email": "*****@*****.**",
            "username": "******",
            "first_name": "john",
            "last_name": "livingston",
            "notes": "these are some notes",
        }

        hydroshare.update_account(self.user, **kwargs)

        self.assertEqual(self.user.email, "*****@*****.**")
        self.assertEqual(self.user.first_name, "john")
        self.assertEqual(self.user.last_name, "livingston")
        self.assertEqual(hydroshare.utils.get_profile(self.user).notes, "these are some notes")
        self.assertTrue(Group.objects.filter(user=self.user).exists)
예제 #5
0
    def test_basic(self):
        kwargs = {
            'groups': ('group0'),
            'email': '*****@*****.**',
            'username': '******',
            'first_name': 'john',
            'last_name': 'livingston',
            'notes': 'these are some notes'
        }

        hydroshare.update_account(self.user, **kwargs)

        self.assertEqual(self.user.email, '*****@*****.**')
        self.assertEqual(self.user.first_name, 'john')
        self.assertEqual(self.user.last_name, 'livingston')
        self.assertEqual(self.user.get_profile().notes, 'these are some notes')
        self.assertTrue(Group.objects.filter(user=self.user).exists)
예제 #6
0
    def test_account_update(self):
        # before update
        self.assertEqual(self.user.email, '*****@*****.**')
        self.assertEqual(self.user.first_name, 'shaun')
        self.assertEqual(self.user.last_name, 'john')
        self.assertEqual(self.user.username, 'shaunjl')

        kwargs = {'email': '*****@*****.**',
                  'username': '******',
                  'first_name': 'john',
                  'last_name': 'livingston',
                  }

        hydroshare.update_account(self.user, **kwargs)

        # after update
        self.assertEqual(self.user.email, '*****@*****.**')
        self.assertEqual(self.user.first_name, 'john')
        self.assertEqual(self.user.last_name, 'livingston')
        # username should not get changed
        self.assertEqual(self.user.username, 'shaunjl')
예제 #7
0
    def test_account_update(self):
        # before update
        self.assertEqual(self.user.email, '*****@*****.**')
        self.assertEqual(self.user.first_name, 'shaun')
        self.assertEqual(self.user.last_name, 'john')
        self.assertEqual(self.user.username, 'shaunjl')

        kwargs = {
            'email': '*****@*****.**',
            'username': '******',
            'first_name': 'john',
            'last_name': 'livingston',
        }

        hydroshare.update_account(self.user, **kwargs)

        # after update
        self.assertEqual(self.user.email, '*****@*****.**')
        self.assertEqual(self.user.first_name, 'john')
        self.assertEqual(self.user.last_name, 'livingston')
        # username should not get changed
        self.assertEqual(self.user.username, 'shaunjl')
예제 #8
0
    def test_profile_update(self):
        # test default profile data
        user_profile = hydroshare.utils.get_profile(self.user)
        self.assertEqual(user_profile.title, None)
        self.assertEqual(user_profile.middle_name, None)
        self.assertEqual(user_profile.user_type, 'Unspecified')
        self.assertEqual(user_profile.subject_areas, None)
        self.assertEqual(user_profile.organization, None)
        self.assertEqual(user_profile.phone_1, None)
        self.assertEqual(user_profile.phone_1_type, None)
        self.assertEqual(user_profile.phone_2, None)
        self.assertEqual(user_profile.phone_2_type, None)
        self.assertEqual(user_profile.details, None)
        self.assertEqual(user_profile.picture, None)
        self.assertEqual(user_profile.cv, None)
        self.assertEqual(user_profile.state, None)
        self.assertEqual(user_profile.country, None)
        self.assertTrue(user_profile.public)

        self.pic_file = open(self.pic_file.name, "w")
        self.pic_file.close()
        # open file for read to upload
        pic_file_obj = open(self.pic_file.name, "r")

        self.cv_file = open(self.cv_file.name, "w")
        self.cv_file.close()
        # open file for read to upload
        cv_file_obj = open(self.cv_file.name, "r")

        # add profile data
        profile_data = {
            'title': "Software Engineer",
            'middle_name': 'Larson',
            'user_type': 'Computer Programming',
            'subject_areas': 'Python, Django, SQL',
            'organization': 'Utah State University',
            'phone_1': '435-678-0987',
            'phone_1_type': 'Work',
            'phone_2': '435-345-9099',
            'phone_2_type': 'Home',
            'details': 'Some details about me',
            'country': 'USA',
            'state': 'UT',
            'public': False,
            'picture': pic_file_obj,
            'cv': cv_file_obj,
        }

        hydroshare.update_account(self.user, **profile_data)
        user_profile = hydroshare.utils.get_profile(self.user)

        # test profile data
        self.assertEqual(user_profile.title, 'Software Engineer')
        self.assertEqual(user_profile.middle_name, 'Larson')
        self.assertEqual(user_profile.user_type, 'Computer Programming')
        self.assertEqual(user_profile.subject_areas, 'Python, Django, SQL')
        self.assertEqual(user_profile.organization, 'Utah State University')
        self.assertEqual(user_profile.phone_1, '435-678-0987')
        self.assertEqual(user_profile.phone_1_type, 'Work')
        self.assertEqual(user_profile.phone_2, '435-345-9099')
        self.assertEqual(user_profile.phone_2_type, 'Home')
        self.assertEqual(user_profile.details, 'Some details about me')
        self.assertEqual(user_profile.country, 'USA')
        self.assertEqual(user_profile.state, 'UT')
        self.assertNotEqual(user_profile.picture, None)
        self.assertNotEqual(user_profile.cv, None)
        self.assertFalse(user_profile.public)
예제 #9
0
    def test_profile_update(self):
        # test default profile data
        user_profile = hydroshare.utils.get_profile(self.user)
        self.assertEqual(user_profile.title, None)
        self.assertEqual(user_profile.middle_name, None)
        self.assertEqual(user_profile.user_type, 'Unspecified')
        self.assertEqual(user_profile.subject_areas, None)
        self.assertEqual(user_profile.organization, None)
        self.assertEqual(user_profile.phone_1, None)
        self.assertEqual(user_profile.phone_1_type, None)
        self.assertEqual(user_profile.phone_2, None)
        self.assertEqual(user_profile.phone_2_type, None)
        self.assertEqual(user_profile.details, None)
        self.assertEqual(user_profile.picture, None)
        self.assertEqual(user_profile.cv, None)
        self.assertEqual(user_profile.state, None)
        self.assertEqual(user_profile.country, None)
        self.assertTrue(user_profile.public)

        self.pic_file = open(self.pic_file.name, "w")
        self.pic_file.close()
        # open file for read to upload
        pic_file_obj = open(self.pic_file.name, "r")

        self.cv_file = open(self.cv_file.name, "w")
        self.cv_file.close()
        # open file for read to upload
        cv_file_obj = open(self.cv_file.name, "r")

        # add profile data
        profile_data = {'title': "Software Engineer",
                        'middle_name': 'Larson',
                        'user_type': 'Computer Programming',
                        'subject_areas': 'Python, Django, SQL',
                        'organization': 'Utah State University',
                        'phone_1': '435-678-0987',
                        'phone_1_type': 'Work',
                        'phone_2': '435-345-9099',
                        'phone_2_type': 'Home',
                        'details': 'Some details about me',
                        'country': 'USA',
                        'state': 'UT',
                        'public': False,
                        'picture': pic_file_obj,
                        'cv': cv_file_obj,
                        }

        hydroshare.update_account(self.user, **profile_data)
        user_profile = hydroshare.utils.get_profile(self.user)

        # test profile data
        self.assertEqual(user_profile.title, 'Software Engineer')
        self.assertEqual(user_profile.middle_name, 'Larson')
        self.assertEqual(user_profile.user_type, 'Computer Programming')
        self.assertEqual(user_profile.subject_areas, 'Python, Django, SQL')
        self.assertEqual(user_profile.organization, 'Utah State University')
        self.assertEqual(user_profile.phone_1, '435-678-0987')
        self.assertEqual(user_profile.phone_1_type, 'Work')
        self.assertEqual(user_profile.phone_2, '435-345-9099')
        self.assertEqual(user_profile.phone_2_type, 'Home')
        self.assertEqual(user_profile.details, 'Some details about me')
        self.assertEqual(user_profile.country, 'USA')
        self.assertEqual(user_profile.state, 'UT')
        self.assertNotEquals(user_profile.picture, None)
        self.assertNotEquals(user_profile.cv, None)
        self.assertFalse(user_profile.public)