Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_resource_returns_available_methods(open_discovery_document, name, version):
discovery_document = open_discovery_document(name, version)
api = GoogleAPI(discovery_document=discovery_document)
for resource_name, _ in discovery_document.get("resources", {}).items():
resource = getattr(api, resource_name)
if resource.methods_available:
# Assert that it returns methods not resources
for available_method_name in resource.methods_available:
available_method = resource._get_method(available_method_name)
assert isinstance(available_method, Method)
METHOD_SPECS = {
"path": "resource/",
"httpMethod": "GET",
"parameters": {},
"supportsMediaUpload": True,
"mediaUpload": {
"accept": ["*/*", "application/octet-stream", "text/xml"],
"maxSize": "100MB",
"protocols": {"simple": {"multipart": True, "path": "resource"}},
},
}
ROOT_URL = "https://example.com/"
BATCH_PATH = "https://example.com/api/v1/batch"
SERVICE_PATH = "service/"
method = Method(
name="upload",
method_specs=METHOD_SPECS,
global_parameters={},
schemas={},
batch_path=BATCH_PATH,
root_url=ROOT_URL,
service_path=SERVICE_PATH,
validate=False,
)
req = method(upload_file="/home/omar/resumable_file.file")
assert req.media_upload.resumable is None
def test_getitem():
method = Method(
name="IRRELEVANT",
method_specs={"am_i_here_1": True, "am_i_here_2": None},
global_parameters={"IRRELEVANT": "IRRELAVANT"},
schemas={"IRRELEVANT": "IRRELEVANT"},
batch_path="IRRELEVANT",
root_url="IRRELEVANT",
service_path="IRRELEVANT",
validate=False,
)
assert method["am_i_here_1"] is True
assert method["am_i_here_2"] is None
assert method["i_dont_exist"] is None
"parameters": {},
"supportsMediaUpload": True,
"mediaUpload": {
"accept": ["*/*", "application/octet-stream", "text/xml"],
"maxSize": "100MB",
"protocols": {
"simple": {"multipart": True, "path": "resource"},
"resumable": RESUMABLE_UPLOAD_SPECS,
},
},
}
ROOT_URL = "https://example.com/"
SERVICE_PATH = "example/v3/"
BATCH_PATH = "https://example.com/api/v1/batch"
method = Method(
name="upload",
method_specs=METHOD_SPECS,
global_parameters={},
schemas={},
batch_path=BATCH_PATH,
service_path=SERVICE_PATH,
root_url=ROOT_URL,
validate=False,
)
req = method(upload_file="/home/omar/resumable_file.file")
assert req.media_upload.resumable
assert (
req.media_upload.resumable.upload_path
== "https://example.com/resumable/upload/example/v3/resource/"
)
assert req.media_upload.resumable.multipart is True
def _get_method(self, method_name):
return Method(
name=method_name,
method_specs=self["methods"][method_name],
global_parameters=self._global_parameters,
schemas=self._schemas,
root_url=self._root_url,
service_path=self._service_path,
batch_path=self._batch_path,
validate=self._validate,
)