def test_add_user__http_error_code__raises_api_error(error_code):
    response = Mock()
    response.status_code = error_code

    request_handler = Mock()
    request_handler.put = Mock(return_value=response)

    client = RabbitMQRestClient(request_handler=request_handler)

    with pytest.raises(APIError):
        client.add_user(
            'name', 'password',
            RabbitMQUserPermissions(configure=".*", write=".*", read=".*"))
def test_add_user():
    mock_create_user = Mock()
    mock_set_user_permissions = Mock()

    client = RabbitMQRestClient(request_handler=Mock())
    client.create_user = mock_create_user
    client.set_user_permissions = mock_set_user_permissions

    name = 'username'
    password = '******'
    tags = ['administrator']
    permissions = RabbitMQUserPermissions(configure=".*",
                                          write=".*",
                                          read=".*")

    client.add_user(name, password, permissions, tags)

    mock_create_user.assert_called_once_with(name, password, tags)
    mock_set_user_permissions.assert_called_once_with(name, permissions)