Пример #1
0
    def save(self, file_name, contents, options):
        """ Save the given photo.
        """
        session = options['session']

        f = identity_api.InMemoryFileWithName(file_name, contents)
        updated_profile = profiles.update(session, photo=f)
        f.close()

        if "photo_url_72x72" in updated_profile:
            photo_url = updated_profile['photo_url_72x72']
        else:
            photo_url = ""

        return {'success'   : True,
                'photo_url' : photo_url}
Пример #2
0
    def test_profiles(self):
        """ Test the various api.profiles functions.
        """
        # Create a dummy user with a random username and password.  This should
        # also create a dummy identity within the 3taps identity API.

        username = utils.random_username()
        password = utils.random_password()

        user = users.create(username=username, password=password)

        # Attempt to log in as this user.

        session_token = users.login(username=username,
                                    password=password)

        sessionHandler.validate(session_token)

        # Retrieve the new user's profile, and make sure that it is empty.

        profile = profiles.get(session_token)
        self.assertItemsEqual(profile.keys(), [])

        # Set the user's profile, including uploading a photo.

        photo_file = file(os.path.join(os.path.dirname(__file__),
                                       "data", "photo.jpg"), "rb")

        ignore = profiles.update(session_token,
                                 photo=photo_file,
                                 name="Test User",
                                 email="*****@*****.**")

        # Check that the profile has been updated.

        profile = profiles.get(session_token)
        self.assertItemsEqual(profile.keys(), ["photo_url_48x48",
                                               "photo_url_72x72",
                                               "photo_url_128x128",
                                               "name",
                                               "email"])

        # Finally, log out again.

        users.logout(session_token)