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_resources_available_property():
resource = Resource(
name="irrelevant",
resource_specs={
"resources": {"first_resource": 1, "second_resource": 2},
"methods": {"third_method": 3, "forth_method": 4},
},
global_parameters=None,
schemas=None,
batch_path=None,
root_url=None,
validate=False,
service_path=None,
)
assert "first_resource" in resource.resources_available
assert "second_resource" in resource.resources_available
def test_resource_constructor(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_object = getattr(api, resource_name)
assert isinstance(resource_object, Resource)
assert resource_name == resource_object.name
assert (
resource_object._resource_specs
== discovery_document["resources"][resource_name]
)
assert resource_object._global_parameters == discovery_document.get(
"parameters"
)
assert resource_object._schemas == discovery_document.get("schemas")
##
assert api["schemas"] is resource_object._schemas
assert api["parameters"] is resource_object._global_parameters
def test_methods_available_property():
resource = Resource(
name="irrelevant",
resource_specs={
"resources": {"first_resource": 1, "second_resource": 2},
"methods": {"third_method": 3, "forth_method": 4},
},
global_parameters=None,
schemas=None,
batch_path=None,
root_url=None,
validate=False,
service_path=None,
)
assert "third_method" in resource.methods_available
assert "forth_method" in resource.methods_available
def test_resource_len_are_counted_correctly():
resource = Resource(
name="irrelevant",
resource_specs={
"resources": {"first_resource": 1, "second_resource": 2, "basdasd": 239},
"methods": {"third_method": 3, "forth_method": 4},
},
global_parameters=None,
schemas=None,
root_url=None,
batch_path=None,
validate=False,
service_path=None,
)
assert len(resource) == 2
def test_getattr(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_object = getattr(api, resource_name)
assert isinstance(resource_object, Resource)
assert resource_name == resource_object.name
def _get_resource(self, resource_name):
return Resource(
name=resource_name,
resource_specs=self["resources"][resource_name],
global_parameters=self["parameters"],
schemas=self["schemas"]
or {}, # josnschema validator will fail if schemas isn't a dict
root_url=self["rootUrl"],
service_path=self["servicePath"],
batch_path=self["batchPath"],
validate=self._validate,
)
def _get_resource(self, resource_name):
return Resource(
name=resource_name,
resource_specs=self["resources"][resource_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,
)