Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_get(self):
        """ Test users/get.
        """
        # Create a random user, and log in.

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

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

        # Make sure we can get the details of the logged-in user.

        user_2 = users.get(session=session_token)

        self.assertEqual(user, user_2)

        # Log out, and make sure we can't get the user's details any more.

        users.logout(session_token)

        with self.assertRaises(InvalidSessionException):
            user_2 = users.get(session=session_token)
Exemplo n.º 3
0
    def test_logout(self):
        """ Test users/logout.
        """
        # Create a random user, and log in.

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

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

        # Check that we are indeed logged in.

        sessionHandler.validate(session_token)

        # Now log out.

        users.logout(session_token)

        # Finally, check that we are indeed logged out.

        with self.assertRaises(InvalidSessionException):
            sessionHandler.validate(session_token)