def test_passthrough_unchanged(self):
     """Test the data should not be changed on its way through validation.
     """
     user = dict(
         username="******",
         password="******",
         email="*****@*****.**",
     )
     self.assertEquals(userdata.creation_required_fields(user), user)
def user_add(request):
    """Add a new user to the system when the data is PUT to the server.

    The user dict that's posted must validate against
    userdata.creation_required_fields(user_data).

    """
    log = get_log("user_add")

    user_data = request.json_body
    log.debug(
        "Validating new user<{}>: {!r}".format(type(user_data), user_data)
    )

    user_data = userdata.creation_required_fields(user_data)

    rc = user.add(**user_data)

    return rc
Exemple #3
0
    def add(self, user):
        """Add a new user to the system.

        :returns: The update user dict.

        """
        self.log.debug("add: attempting to add user <%s>" % user)

        user = userdata.creation_required_fields(user)

        if "password" in user:
            user['password'] = user['password'].encode("base64")

        uri = urljoin(self.base_uri, self.ADD)
        self.log.debug("add: uri <%s>" % uri)

        res = requests.put(uri, json.dumps(user), headers=self.JSON_CT)
        rc = res.json()
        if not rc['success']:
            raise userdata.UserServiceError(rc['message'])

        return rc['data']