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_oauth2_manager_has_valid_oauth2_api(manager):
assert isinstance(manager.oauth2_api, GoogleAPI)
def test_properties(open_discovery_document, name, version):
discovery_document = open_discovery_document(name, version)
api = GoogleAPI(discovery_document=discovery_document)
assert (name in str(api)) or (discovery_document.get("title") in str(api))
assert (version in str(api)) or (discovery_document.get("title") in str(api))
def test_getitem(open_discovery_document, name, version):
discovery_document = open_discovery_document(name, version)
api = GoogleAPI(discovery_document=discovery_document)
assert api['name'] == discovery_document.get('name')
assert api['version'] == discovery_document.get('version')
assert api['auth'] == discovery_document.get('auth')
def test_resource_returns_nested_resource(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.resources_available:
# Assert that it returns resources not methods
for nested_resource_name in resource.resources_available:
nested_resource = getattr(resource, nested_resource_name)
assert isinstance(nested_resource, Resource)
def test_required_parameters_are_filtered_correctly(
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)
for method_name in resource.methods_available:
method = resource._get_method(method_name)
for parameter_name in method.required_parameters:
parameter = method.parameters[parameter_name]
assert parameter.get("required") is True
def test_stack_parameters_are_passed_correctly(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)
for param_name in STACK_QUERY_PARAMETERS:
assert param_name in resource._global_parameters
assert (
resource._global_parameters[param_name]
== STACK_QUERY_PARAMETER_DEFAULT_VALUE
)
def test_calling_resource_fails(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)
with pytest.raises(TypeError):
resource()
def test__len__returns_int(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)
for method_name in resource.methods_available:
method = resource._get_method(method_name)
assert isinstance(len(method), int)
def test_stack_parameters_are_passed_correctly(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)
for method_name in resource.methods_available:
method = resource._get_method(method_name)
for stack_param_name in STACK_QUERY_PARAMETERS:
assert stack_param_name in method.optional_parameters
assert stack_param_name in method.parameters
def __init__(self, session_factory=AiohttpSession, verify=True, client_creds=None):
self.oauth2_api = GoogleAPI(OAUTH2_V2_DISCVOCERY_DOC)
self.openid_configs = WELLKNOWN_OPENID_CONFIGS
self.session_factory = session_factory
self.active_session = None
self.verify = verify
self.client_creds = client_creds