Пример #1
0
def test_set_group_policies_explicit_payload(groups_client):
    register_api_route_fixture_file(
        "groups",
        "/v2/groups/d3974728-6458-11e4-b72d-123139141556/policies",
        "set_group_policies.json",
        method="PUT",
    )
    # same payload as the above test, but formulated without GroupsManager
    payload = GroupPolicies(
        is_high_assurance=False,
        group_visibility=GroupVisibility.private,
        group_members_visibility=GroupMemberVisibility.managers,
        join_requests=False,
        signup_fields=[GroupRequiredSignupFields.address1],
        authentication_assurance_timeout=28800,
    )
    # set a string in the payload directly
    # this will pass through GroupPolicies.__setitem__
    payload["group_visibility"] = "authenticated"
    # now send it... (but ignore the response)
    groups_client.set_group_policies("d3974728-6458-11e4-b72d-123139141556",
                                     payload)
    # ensure enums were stringified correctly, but also that the raw string came through
    req = get_last_request()
    req_body = json.loads(req.body)
    assert req_body["group_visibility"] == "authenticated"
    assert req_body["group_members_visibility"] == "managers"
    assert req_body["signup_fields"] == ["address1"]
Пример #2
0
def test_get_endpoint(client):
    """
    Gets endpoint on go#ep1 and go#ep2, validate results
    """
    # register get_endpoint mock data
    register_api_route_fixture_file(
        "transfer", "/endpoint/{}".format(GO_EP1_ID), "get_endpoint_goep1.json"
    )
    register_api_route_fixture_file(
        "transfer", "/endpoint/{}".format(GO_EP2_ID), "get_endpoint_goep2.json"
    )

    # load the tutorial endpoint documents
    ep1_doc = client.get_endpoint(GO_EP1_ID)
    ep2_doc = client.get_endpoint(GO_EP2_ID)

    # check that their contents are at least basically sane (i.e. we didn't
    # get empty dicts or something)
    assert "display_name" in ep1_doc
    assert "display_name" in ep2_doc
    assert "canonical_name" in ep1_doc
    assert "canonical_name" in ep2_doc

    # double check a couple of fields, consider this done
    assert ep1_doc["canonical_name"] == "go#ep1"
    assert ep1_doc["DATA"][0]["id"] == GO_EP1_SERVER_ID
    assert ep2_doc["canonical_name"] == "go#ep2"
Пример #3
0
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
Пример #4
0
def test_update_endpoint_rewrites_activation_servers(client):
    """
    Update endpoint, validate results
    """
    epid = "example-id"
    register_api_route_fixture_file("transfer",
                                    "/endpoint/{}".format(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 = httpretty.last_request()
    assert req.body != six.b(json.dumps(update_data))
    update_data["oauth_server"] = None
    assert req.body == six.b(json.dumps(update_data))

    # sending oauth_server implicitly adds myproxy_server=null
    update_data = {"oauth_server": "foo"}
    client.update_endpoint(epid, update_data.copy())
    req = httpretty.last_request()
    assert req.body != six.b(json.dumps(update_data))
    update_data["myproxy_server"] = None
    assert req.body == six.b(json.dumps(update_data))
Пример #5
0
def test_get_endpoint(client):
    """
    Gets endpoint on go#ep1 and go#ep2, validate results
    """
    # register get_endpoint mock data
    register_api_route_fixture_file("transfer",
                                    "/endpoint/{}".format(GO_EP1_ID),
                                    "get_endpoint_goep1.json")
    register_api_route_fixture_file("transfer",
                                    "/endpoint/{}".format(GO_EP2_ID),
                                    "get_endpoint_goep2.json")

    # load the tutorial endpoint documents
    ep1_doc = client.get_endpoint(GO_EP1_ID)
    ep2_doc = client.get_endpoint(GO_EP2_ID)

    # check that their contents are at least basically sane (i.e. we didn't
    # get empty dicts or something)
    assert "display_name" in ep1_doc
    assert "display_name" in ep2_doc
    assert "canonical_name" in ep1_doc
    assert "canonical_name" in ep2_doc

    # double check a couple of fields, consider this done
    assert ep1_doc["canonical_name"] == "go#ep1"
    assert ep1_doc["DATA"][0]["id"] == GO_EP1_SERVER_ID
    assert ep2_doc["canonical_name"] == "go#ep2"
Пример #6
0
def test_task_list(client, client_kwargs, qs):
    register_api_route_fixture_file("transfer", "/task_list", "task_list.json")
    client.task_list(**client_kwargs)

    req = get_last_request()
    parsed_qs = urllib.parse.parse_qs(urllib.parse.urlparse(req.url).query)
    # parsed_qs will have each value as a list (because query-params are a multidict)
    # so transform the test data to match before comparison
    assert parsed_qs == {k: [v] for k, v in qs.items()}
Пример #7
0
def test_delete_role(client):
    register_api_route_fixture_file("gcs",
                                    "/roles/ROLE_ID",
                                    "empty_success.json",
                                    method="DELETE")
    res = client.delete_role("ROLE_ID")
    assert res["DATA_TYPE"] == "result#1.0.0"
    assert "detail" in res.data
    assert res.data["detail"] == "success"
Пример #8
0
def test_get_role(client):
    register_api_route_fixture_file("gcs", "/roles/ROLE_ID",
                                    "role_document.json")
    res = client.get_role("ROLE_ID")
    assert res["DATA_TYPE"] == "role#1.0.0"
    assert res["id"] == "{role_id_1}"
    assert res["collection"] is None
    assert res["principal"] == "urn:globus:auth:identity:{user_id_1}"
    assert res["role"] == "owner"
Пример #9
0
def test_task_wait_bad_args_min_wait(client, mocksleep, add_kwargs):
    # register task mock data even though it should not be needed
    register_api_route_fixture_file("transfer", f"/task/{TASK1_ID}",
                                    "get_task1_active.json")

    with pytest.raises(globus_sdk.GlobusSDKUsageError):
        client.task_wait(TASK1_ID, **add_kwargs)

    # no requests sent, no sleep done
    assert get_last_request() is None
    mocksleep.assert_not_called()
Пример #10
0
def test_task_wait_unfinished_case(client, mocksleep):
    # the task is in the active state no matter how many times we ask
    register_api_route_fixture_file("transfer", f"/task/{TASK1_ID}",
                                    "get_task1_active.json")

    # do the task wait, it should return false (the task didn't complete)
    result = client.task_wait(TASK1_ID, timeout=5, polling_interval=1)
    assert result is False

    # a number of sleeps equal to timeout/polling_interval
    # a number of requests equal to sleeps+1
    mocksleep.assert_has_calls([mock.call(1) for x in range(5)])
    assert len(responses.calls) == 6
Пример #11
0
def test_get_role_list(client):
    register_api_route_fixture_file("gcs", "/roles", "role_list.json")
    res = client.get_role_list()

    assert len(list(res)) == 2
    # sanity check some fields
    assert res["DATA_TYPE"] == "result#1.0.0"
    for item in res:
        assert item["DATA_TYPE"] == "role#1.0.0"
        assert "id" in item
        assert item["id"] in ("{role_id_1}", "{role_id_2}")
        assert "principal" in item
        assert "role" in item
Пример #12
0
def test_create_group(groups_manager):
    register_api_route_fixture_file(
        "groups",
        "/v2/groups",
        "created_group.json",
        method="POST",
    )

    res = groups_manager.create_group(name="Claptrap's Rough Riders",
                                      description="No stairs allowed.")
    assert res.http_status == 200
    assert "Claptrap" in res.data["name"]
    assert "No stairs allowed." in res.data["description"]
Пример #13
0
def test_task_wait_success_case(client, mocksleep):
    # first the task will show as active, then as succeded
    register_api_route_fixture_file("transfer", f"/task/{TASK1_ID}",
                                    "get_task1_active.json")
    register_api_route_fixture_file("transfer", f"/task/{TASK1_ID}",
                                    "get_task1_succeeded.json")

    # do the task wait, it should return true (the task completed in time)
    result = client.task_wait(TASK1_ID, timeout=5, polling_interval=1)
    assert result is True

    # one sleep, two network calls
    mocksleep.assert_called_once_with(1)
    assert len(responses.calls) == 2
Пример #14
0
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
Пример #15
0
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 = httpretty.last_request()
    assert req.body == six.b(json.dumps(create_data))
Пример #16
0
def test_operation_ls(client):
    """
    Does an `ls` on go#ep1, validate results, and check that the request parameters were
    formatted and sent correctly.
    """
    # register get_endpoint mock data
    register_api_route_fixture_file(
        "transfer", f"/operation/endpoint/{GO_EP1_ID}/ls", "operation_ls_goep1.json"
    )
    ls_path = f"https://transfer.api.globus.org/v0.10/operation/endpoint/{GO_EP1_ID}/ls"

    # load the tutorial endpoint ls doc
    ls_doc = client.operation_ls(GO_EP1_ID)

    # check that the result is an iterable of file and dir dict objects
    count = 0
    for x in ls_doc:
        assert "DATA_TYPE" in x
        assert x["DATA_TYPE"] in ("file", "dir")
        count += 1
    # not exact, just make sure the fixture wasn't empty
    assert count > 3

    req = get_last_request()
    assert req.url == ls_path

    # don't change the registered response
    # the resulting data might be "wrong", but we're just checking request formatting

    # orderby with a single str
    client.operation_ls(GO_EP1_ID, orderby="name")
    req = get_last_request()
    parsed_qs = urllib.parse.parse_qs(urllib.parse.urlparse(req.url).query)
    assert parsed_qs == {"orderby": ["name"]}

    # orderby multiple strs
    client.operation_ls(GO_EP1_ID, orderby=["size DESC", "name", "type"])
    req = get_last_request()
    parsed_qs = urllib.parse.parse_qs(urllib.parse.urlparse(req.url).query)
    assert parsed_qs == {"orderby": ["size DESC,name,type"]}

    # orderby + filter
    client.operation_ls(GO_EP1_ID, orderby="name", filter="name:~*.png")
    req = get_last_request()
    parsed_qs = urllib.parse.parse_qs(urllib.parse.urlparse(req.url).query)
    assert parsed_qs == {"orderby": ["name"], "filter": ["name:~*.png"]}
def test_approve_pending(groups_manager):
    register_api_route_fixture_file(
        "groups",
        "/v2/groups/d3974728-6458-11e4-b72d-123139141556",
        "approve_pending.json",
        method="POST",
    )

    res = groups_manager.approve_pending(
        "d3974728-6458-11e4-b72d-123139141556",
        "ae332d86-d274-11e5-b885-b31714a110e9")
    assert res.http_status == 200

    data = res.data
    assert isinstance(data, dict)
    assert "approve" in data
    assert data["approve"][0]["status"] == "active"
Пример #18
0
def test_update_group(groups_client):
    register_api_route_fixture_file(
        "groups",
        "/v2/groups/592e0566-5201-4207-b5e1-7cd6c516e9a0",
        "updated_group.json",
        method="PUT",
    )

    data = {
        "name": "Claptrap's Rough Riders",
        "description": "Stairs strongly discouraged.",
    }
    res = groups_client.update_group(
        group_id="592e0566-5201-4207-b5e1-7cd6c516e9a0", data=data)
    assert res.http_status == 200
    assert "Claptrap" in res.data["name"]
    assert "Stairs strongly discouraged." in res.data["description"]
Пример #19
0
def test_get_group_policies(groups_client):
    register_api_route_fixture_file(
        "groups",
        "/v2/groups/d3974728-6458-11e4-b72d-123139141556/policies",
        "get_group_policies.json",
    )
    resp = groups_client.get_group_policies(
        "d3974728-6458-11e4-b72d-123139141556")
    assert resp.http_status == 200
    assert resp.data == {
        "is_high_assurance": False,
        "authentication_assurance_timeout": 28800,
        "group_visibility": "private",
        "group_members_visibility": "managers",
        "join_requests": False,
        "signup_fields": [],
    }
Пример #20
0
def test_update_endpoint(client):
    epid = uuid.uuid1()
    register_api_route_fixture_file(
        "transfer", "/endpoint/{}".format(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 = httpretty.last_request()
    assert req.body == six.b(json.dumps(update_data))
Пример #21
0
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
Пример #22
0
def test_get_role_list_params(client):
    """
    confirms include, collection_id, and arbitrary query_params arguments
    to get_role_list are assembled correctly
    """
    register_api_route_fixture_file("gcs", "/roles", "role_list.json")

    # no args
    res = client.get_role_list()
    assert res["code"] == "success"
    params = get_last_request().params
    assert params == {}

    # collection_id
    res = client.get_role_list(collection_id="{collection_id_1}")
    assert res["code"] == "success"
    params = get_last_request().params
    assert params == {"collection_id": "{collection_id_1}"}

    # include
    res = client.get_role_list(include="all_roles")
    assert res["code"] == "success"
    params = get_last_request().params
    assert params == {"include": "all_roles"}

    # query_params
    res = client.get_role_list(query_params={"foo": "bar"})
    assert res["code"] == "success"
    params = get_last_request().params
    assert params == {"foo": "bar"}

    # everything together
    res = client.get_role_list(
        collection_id="{collection_id_1}",
        include="all_roles",
        query_params={"foo": "bar"},
    )
    assert res["code"] == "success"
    params = get_last_request().params
    assert params == {
        "collection_id": "{collection_id_1}",
        "include": "all_roles",
        "foo": "bar",
    }
Пример #23
0
def test_create_role(client):
    register_api_route_fixture_file("gcs",
                                    "/roles",
                                    "role_document.json",
                                    method="POST")

    data = GCSRoleDocument(
        collection="{collection_id_1}",
        principal="urn:globus:auth:identity:{user_id_1}",
        role="owner",
    )
    res = client.create_role(data)
    assert res["id"] == "{role_id_1}"

    json_body = json.loads(get_last_request().body)

    assert json_body["collection"] in (None, "{collection_id_1}")
    assert json_body["principal"] == "urn:globus:auth:identity:{user_id_1}"
    assert json_body["role"] in ("owner", "administrator")
def test_add_member(groups_manager):
    register_api_route_fixture_file(
        "groups",
        "/v2/groups/d3974728-6458-11e4-b72d-123139141556",
        "add_member.json",
        method="POST",
    )

    res = groups_manager.add_member(
        "d3974728-6458-11e4-b72d-123139141556",
        "ae332d86-d274-11e5-b885-b31714a110e9",
        role=GroupRole.admin,
    )
    assert res.http_status == 200

    data = res.data
    assert isinstance(data, dict)
    assert "add" in data
    assert data["add"][0]["status"] == "active"
    assert data["add"][0]["role"] == "admin"
Пример #25
0
def test_autoactivation(client):
    """
    Do `autoactivate` on go#ep1, validate results, and check that `if_expires_in` can be
    passed correctly.
    """
    # register get_endpoint mock data
    register_api_route_fixture_file(
        "transfer",
        f"/endpoint/{GO_EP1_ID}/autoactivate",
        "activation_stub.json",
        method="POST",
    )

    # load and check the activation doc
    res = client.endpoint_autoactivate(GO_EP1_ID)
    assert res["code"] == "AutoActivated.CachedCredential"

    # check the formatted url for the request
    req = get_last_request()
    assert (
        req.url
        == f"https://transfer.api.globus.org/v0.10/endpoint/{GO_EP1_ID}/autoactivate"
    )

    register_api_route_fixture_file(
        "transfer",
        f"/endpoint/{GO_EP1_ID}/autoactivate",
        "activation_already_activated_stub.json",
        method="POST",
        replace=True,
    )
    res = client.endpoint_autoactivate(GO_EP1_ID, if_expires_in=300)
    assert res["code"] == "AlreadyActivated"

    req = get_last_request()
    parsed_qs = urllib.parse.parse_qs(urllib.parse.urlparse(req.url).query)
    assert parsed_qs == {"if_expires_in": ["300"]}
Пример #26
0
def test_search_paginated_scroll_query(search_client, query_doc):
    index_id = str(uuid.uuid1())
    register_api_route_fixture_file(
        "search",
        f"/v1/index/{index_id}/scroll",
        "scroll_result_1.json",
        method="POST",
        match=[responses.matchers.json_params_matcher({"q": "foo"})],
    )
    register_api_route_fixture_file(
        "search",
        f"/v1/index/{index_id}/scroll",
        "scroll_result_2.json",
        method="POST",
        match=[
            responses.matchers.json_params_matcher({
                "q":
                "foo",
                "marker":
                "3d34900e3e4211ebb0a806b2af333354"
            })
        ],
    )

    data = list(search_client.paginated.scroll(index_id, query_doc).items())
    assert len(responses.calls) == 2
    assert len(data) == 2

    assert isinstance(data[0], dict)
    assert data[0]["entries"][0]["content"]["foo"] == "bar"

    assert isinstance(data[1], dict)
    assert data[1]["entries"][0]["content"]["foo"] == "baz"

    # confirm that pagination was not side-effecting
    assert "marker" not in query_doc
Пример #27
0
def test_update_endpoint_rewrites_activation_servers(client):
    """
    Update endpoint, validate results
    """
    epid = "example-id"
    register_api_route_fixture_file(
        "transfer", "/endpoint/{}".format(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 = httpretty.last_request()
    assert req.body != six.b(json.dumps(update_data))
    update_data["oauth_server"] = None
    assert req.body == six.b(json.dumps(update_data))

    # sending oauth_server implicitly adds myproxy_server=null
    update_data = {"oauth_server": "foo"}
    client.update_endpoint(epid, update_data.copy())
    req = httpretty.last_request()
    assert req.body != six.b(json.dumps(update_data))
    update_data["myproxy_server"] = None
    assert req.body == six.b(json.dumps(update_data))
Пример #28
0
def test_set_group_policies(groups_manager):
    register_api_route_fixture_file(
        "groups",
        "/v2/groups/d3974728-6458-11e4-b72d-123139141556/policies",
        "set_group_policies.json",
        method="PUT",
    )
    resp = groups_manager.set_group_policies(
        "d3974728-6458-11e4-b72d-123139141556",
        is_high_assurance=False,
        group_visibility=GroupVisibility.private,
        group_members_visibility=GroupMemberVisibility.managers,
        join_requests=False,
        signup_fields=[GroupRequiredSignupFields.address1],
        authentication_assurance_timeout=28800,
    )
    assert resp.http_status == 200
    assert "address1" in resp.data["signup_fields"]
    # ensure enums were stringified correctly
    req = get_last_request()
    req_body = json.loads(req.body)
    assert req_body["group_visibility"] == "private"
    assert req_body["group_members_visibility"] == "managers"
    assert req_body["signup_fields"] == ["address1"]