def test_update_endpoint_rewrites_activation_servers(client):
    """
    Update endpoint, validate results
    """
    epid = "example-id"
    register_api_route_fixture_file("transfer",
                                    f"/endpoint/{epid}",
                                    "ep_create.json",
                                    method="PUT")

    # sending myproxy_server implicitly adds oauth_server=null
    update_data = {"myproxy_server": "foo"}
    client.update_endpoint(epid, update_data.copy())
    req = get_last_request()
    assert json.loads(req.body) != update_data
    update_data["oauth_server"] = None
    assert json.loads(req.body) == update_data

    # sending oauth_server implicitly adds myproxy_server=null
    update_data = {"oauth_server": "foo"}
    client.update_endpoint(epid, update_data.copy())
    req = get_last_request()
    assert json.loads(req.body) != update_data
    update_data["myproxy_server"] = None
    assert json.loads(req.body) == update_data
Beispiel #2
0
def test_get_identities_multiple_success(usernames, expect, client,
                                         identities_multiple_response):
    res = client.get_identities(usernames=usernames)

    assert res.data == json.loads(IDENTITIES_MULTIPLE_RESPONSE)

    lastreq = get_last_request()
    assert "usernames" in lastreq.params
    assert lastreq.params["usernames"] == expect
Beispiel #3
0
def test_get_identities_success(usernames, client, identities_single_response):
    res = client.get_identities(usernames=usernames)

    assert res.data == json.loads(IDENTITIES_SINGLE_RESPONSE)

    lastreq = get_last_request()
    assert lastreq.params == {
        "usernames": "*****@*****.**",
        "provision": "false",  # provision defaults to false
    }
Beispiel #4
0
def test_get_identities_multiple_ids_success(ids, client,
                                             identities_multiple_response):
    expect = ",".join([
        "46bd0f56-e24f-11e5-a510-131bef46955c",
        "ae341a98-d274-11e5-b888-dbae3a8ba545"
    ])
    res = client.get_identities(ids=ids)

    assert res.data == json.loads(IDENTITIES_MULTIPLE_RESPONSE)

    lastreq = get_last_request()
    assert "ids" in lastreq.params
    assert lastreq.params["ids"] == expect
def test_identity_map_keyerror(client):
    register_api_route("auth",
                       "/v2/api/identities",
                       body=IDENTITIES_SINGLE_RESPONSE)
    idmap = globus_sdk.IdentityMap(client)
    # a name which doesn't come back, indicating that it was not found, will KeyError
    with pytest.raises(KeyError):
        idmap["*****@*****.**"]

    last_req = get_last_request()
    assert last_req.params == {
        "usernames": "*****@*****.**",
        "provision": "false"
    }
def test_create_endpoint(client):
    register_api_route_fixture_file("transfer",
                                    "/endpoint",
                                    "ep_create.json",
                                    method="POST")

    create_data = {"display_name": "Name", "description": "desc"}
    create_doc = client.create_endpoint(create_data)

    # make sure response is a successful update
    assert create_doc["DATA_TYPE"] == "endpoint_create_result"
    assert create_doc["code"] == "Created"
    assert create_doc["message"] == "Endpoint created successfully"

    req = get_last_request()
    assert json.loads(req.body) == create_data
def test_identity_map_multiple(client):
    register_api_route("auth", ("/v2/api/identities"),
                       body=IDENTITIES_MULTIPLE_RESPONSE)
    idmap = globus_sdk.IdentityMap(client,
                                   ["*****@*****.**", "*****@*****.**"])
    assert idmap["*****@*****.**"]["organization"] == "Globus Team"
    assert idmap["*****@*****.**"]["organization"] is None

    last_req = get_last_request()
    # order doesn't matter, but it should be just these two
    # if IdentityMap doesn't deduplicate correctly, it could send
    # `[email protected],[email protected],[email protected]` on the first lookup
    assert last_req.params["usernames"] in [
        "[email protected],[email protected]",
        "[email protected],[email protected]",
    ]
    assert last_req.params["provision"] == "false"
def test_identity_map(client):
    register_api_route("auth",
                       "/v2/api/identities",
                       body=IDENTITIES_SINGLE_RESPONSE)
    idmap = globus_sdk.IdentityMap(client, ["*****@*****.**"])
    assert idmap["*****@*****.**"]["organization"] == "Globus Team"

    # lookup by ID also works
    assert (idmap["ae341a98-d274-11e5-b888-dbae3a8ba545"]["organization"] ==
            "Globus Team")

    # the last (only) API call was the one by username
    last_req = get_last_request()
    assert "ids" not in last_req.params
    assert last_req.params == {
        "usernames": "*****@*****.**",
        "provision": "false"
    }
def test_update_endpoint(client):
    epid = uuid.uuid1()
    register_api_route_fixture_file("transfer",
                                    f"/endpoint/{epid}",
                                    "ep_update.json",
                                    method="PUT")

    # NOTE: pass epid as UUID, not str
    # requires that TransferClient correctly translates it
    update_data = {
        "display_name": "Updated Name",
        "description": "Updated description"
    }
    update_doc = client.update_endpoint(epid, update_data)

    # make sure response is a successful update
    assert update_doc["DATA_TYPE"] == "result"
    assert update_doc["code"] == "Updated"
    assert update_doc["message"] == "Endpoint updated successfully"

    req = get_last_request()
    assert json.loads(req.body) == update_data
def test_http_methods(method, allows_body, base_client):
    """
    BaseClient.{get, delete, post, put, patch} on a path does "the right thing"
    Sends a text body or JSON body as requested
    Raises a GlobusAPIError if the response is not a 200

    NOTE: tests sending request bodies even on GET (which
    *shouldn't* have bodies but *may* have them in reality).
    """
    methodname = method.upper()
    resolved_method = getattr(base_client, method)
    register_api_route(
        "transfer", "/madeuppath/objectname", method=methodname, json={"x": "y"}
    )

    # client should be able to compose the path itself
    path = base_client.qjoin_path("madeuppath", "objectname")

    # request with no body
    res = resolved_method(path)
    req = get_last_request()

    assert req.method == methodname
    assert req.body is None
    assert "x" in res
    assert res["x"] == "y"

    if allows_body:
        jsonbody = {"foo": "bar"}
        res = resolved_method(path, json_body=jsonbody)
        req = get_last_request()

        assert req.method == methodname
        assert req.body == json.dumps(jsonbody)
        assert "x" in res
        assert res["x"] == "y"

        res = resolved_method(path, text_body="abc")
        req = get_last_request()

        assert req.method == methodname
        assert req.body == "abc"
        assert "x" in res
        assert res["x"] == "y"

    # send "bad" request
    for status in ERROR_STATUS_CODES:
        register_api_route(
            "transfer",
            "/madeuppath/objectname",
            method=methodname,
            status=status,
            json={"x": "y", "code": "ErrorCode", "message": "foo"},
            replace=True,
        )

        with pytest.raises(globus_sdk.GlobusAPIError) as excinfo:
            resolved_method("/madeuppath/objectname")

        assert excinfo.value.http_status == status
        assert excinfo.value.raw_json["x"] == "y"
        assert excinfo.value.code == "ErrorCode"
        assert excinfo.value.message == "foo"
Beispiel #11
0
def test_get_identities_provision(inval, outval, client,
                                  identities_single_response):
    client.get_identities(usernames="*****@*****.**", provision=inval)
    lastreq = get_last_request()
    assert "provision" in lastreq.params
    assert lastreq.params["provision"] == outval