Debian Codegraph @

src/globus_sdk/testing/data/auth/create_native_app_instance.py

raw
1 import typing as t
2 import uuid
3
4 from responses.matchers import json_params_matcher
5
6 from globus_sdk.testing.models import RegisteredResponse, ResponseSet
7
8 APP_REQUEST_ARGS = {
9 "template_id": str(uuid.uuid1()),
10 "name": str(uuid.uuid1()).replace("-", ""),
11 }
12
13
14 def make_app_request_body(request_args: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
15 request_body = request_args.copy()
16 request_body["template_id"] = str(request_args["template_id"])
17 return request_body
18
19
20 def make_app_response_body(request_args: t.Mapping[str, t.Any]) -> t.Dict[str, t.Any]:
21 return {
22 "client": {
23 "fqdns": [],
24 "name": request_args["name"],
25 "id": "e634cc2a-d528-494e-8dda-92ec54a883c9",
26 "public_client": False,
27 "scopes": [],
28 "required_idp": None,
29 "grant_types": [
30 "authorization_code",
31 "client_credentials",
32 "refresh_token",
33 ],
34 "userinfo_from_effective_identity": True,
35 "client_type": "confidential_client",
36 "prompt_for_named_grant": False,
37 "links": {"privacy_policy": None, "terms_and_conditions": None},
38 "visibility": "private",
39 "preselect_idp": None,
40 "parent_client": str(request_args["template_id"]),
41 "project": None,
42 "redirect_uris": [],
43 },
44 "included": {
45 "client_credential": {
46 "name": "Auto-created at client creation",
47 "id": "b4840855-2de8-4035-b1b4-4e7c8f518943",
48 "client": "e634cc2a-d528-494e-8dda-92ec54a883c9",
49 "secret": "cgK1HG9Y0DcZw79YlQEJpZCF4CMxIbaFf5sohWxjcfY=",
50 }
51 },
52 }
53
54
55 def register_response(
56 args: t.Mapping[str, t.Any],
57 ) -> RegisteredResponse:
58 request_args = {**APP_REQUEST_ARGS, **args}
59 request_body = make_app_request_body(request_args)
60 response_body = make_app_response_body(request_args)
61
62 return RegisteredResponse(
63 service="auth",
64 method="POST",
65 path="/v2/api/clients",
66 json={"client": response_body},
67 metadata={
68 # Test functions use 'args' to form request
69 "args": request_args,
70 # Test functions use 'response' to verify response
71 "response": response_body,
72 },
73 match=[
74 json_params_matcher(
75 {"client": request_body},
76 )
77 ],
78 )
79
80
81 RESPONSES = ResponseSet(
82 default=register_response({}),
83 template_id_str=register_response({"template_id": str(uuid.uuid1())}),
84 template_id_uuid=register_response({"template_id": uuid.uuid1()}),
85 name=register_response({"name": str(uuid.uuid1()).replace("-", "")}),
86 )