Esempio n. 1
0
    def test_check_unique(self):
        """Test method check_unique in User"""
        #Test something that really shouldn't be there
        with pytest.raises(DbException) as err:
            User.check_unique('Admin', '@', True)
        assert str(err.value) == "(400, 'username')"
        with pytest.raises(DbException) as err:
            User.check_unique('@', '*****@*****.**', True)
        assert str(err.value) == "(400, 'email')"

        assert User.check_unique('@', '@')

        assert not User.check_unique('Admin', '@')
        assert not User.check_unique('@', '*****@*****.**')
Esempio n. 2
0
def registration_action():
    """
    Registration
    """
    data = request.get_json()
    validate_data(data, {'username', 'password', 'email'})
    if not validate_email(data['email']):
        raise ApiException(400, "email")
    if not validate_username(data['username']):
        raise ApiException(400, "username")
    if not validate_password(data['password']):
        raise ApiException(400, "password")
    if User.check_unique(data['username'], data['email'], True):
        userEntity = User(data['username'], data['email'], data['password'])
        userEntity.save_entity()
        token = authenticate(None, True, userEntity.id)
        data = {"user_id": userEntity.id, "token": token.token}
        return response_ok(data)