Skip to content

Commit

Permalink
Turn validation off by default
Browse files Browse the repository at this point in the history
  • Loading branch information
omarryhan committed Sep 20, 2021
1 parent 9982f20 commit d8c73a7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion aiogoogle/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__about__ = "Async Google API client"
__description__ = __about__
__url__ = "https://github.com/omarryhan/aiogoogle"
__version_info__ = ("2", "1", "1")
__version_info__ = ("3", "0", "0")
__version__ = ".".join(__version_info__)
__author__ = "Omar Ryhan"
__author_email__ = "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions aiogoogle/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async def list_api(self, name, preferred=None, fields=None):
)
return await self.as_anon(request)

async def discover(self, api_name, api_version=None, validate=True):
async def discover(self, api_name, api_version=None, validate=False):
"""
Donwloads a discovery document from Google's Discovery Service V1 and sets it a ``aiogoogle.resource.GoogleAPI``
Expand All @@ -157,7 +157,7 @@ async def discover(self, api_name, api_version=None, validate=True):
api_version (str): API version to discover *e.g.: "v3" not "3" and not 3*
validate (bool): Set this to False to disallow input validation on calling methods
validate (bool): Set this to True to use this lib's built in parameter validation logic. Note that you shouldn't rely on this for critical user input validation.
Returns:
Expand Down
4 changes: 2 additions & 2 deletions aiogoogle/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,10 @@ class GoogleAPI:
discovery_document (dict): A discovery document
validate (bool): Whther or not to validate user input again the schema defined in the discovery document
validate (bool): Set this to True to use this lib's built in parameter validation logic. Note that you shouldn't rely on this for critical user input validation.
"""

def __init__(self, discovery_document, validate=True):
def __init__(self, discovery_document, validate=False):
self.discovery_document = self._add_extra_query_param_definitions(
discovery_document
)
Expand Down
4 changes: 2 additions & 2 deletions tests/ALL_APIS.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
('compute', 'v1'),
('container', 'v1'),
('customsearch', 'v1'),
('datacatalog', 'v1'),
('dataproc', 'v1'),
('datastore', 'v1'),
('deploymentmanager', 'v2'),
Expand All @@ -62,7 +63,6 @@
('firestore', 'v1'),
('fitness', 'v1'),
('games', 'v1'),
('genomics', 'v1'),
('gmail', 'v1'),
('groupsmigration', 'v1'),
('groupssettings', 'v1'),
Expand Down Expand Up @@ -94,7 +94,6 @@
('pubsub', 'v1'),
('recommender', 'v1'),
('redis', 'v1'),
('remotebuildexecution', 'v2'),
('reseller', 'v1'),
('run', 'v1'),
('runtimeconfig', 'v1'),
Expand All @@ -113,6 +112,7 @@
('sourcerepo', 'v1'),
('spanner', 'v1'),
('speech', 'v1'),
('sqladmin', 'v1'),
('storage', 'v1'),
('storagetransfer', 'v1'),
('streetviewpublish', 'v1'),
Expand Down
34 changes: 25 additions & 9 deletions tests/test_units/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_validates_body_json_12(create_api):
"response"
] # Testing arrays and objects
with pytest.raises(ValidationError):
calendar.calendarList.list(json={"items": {}})
calendar.calendarList.list(validate=True, json={"items": {}})


def test_validates_body_json_13(create_api):
Expand All @@ -174,7 +174,7 @@ def test_validates_body_json_13(create_api):
] = calendar.calendarList.list._method_specs[
"response"
] # Testing arrays and objects
calendar.calendarList.list(json={"items": [{"accessRole": "a_valid_access_role"}]})
calendar.calendarList.list(validate=True, json={"items": [{"accessRole": "a_valid_access_role"}]})


def test_validates_body_json_14(create_api):
Expand All @@ -186,7 +186,7 @@ def test_validates_body_json_14(create_api):
"response"
] # Testing arrays and objects
with pytest.raises(ValidationError):
calendar.calendarList.list(json={"items": [{"accessRole": 1}]})
calendar.calendarList.list(validate=True, json={"items": [{"accessRole": 1}]})


def test_validates_body_json_15(create_api):
Expand All @@ -199,6 +199,7 @@ def test_validates_body_json_15(create_api):
] # Testing arrays and objects
with pytest.warns(UserWarning, match="this_isnt_supposed_to_be_here"):
calendar.calendarList.list(
validate=True,
json={
"items": [
{"accessRole": "a_valid_access_role"},
Expand All @@ -218,6 +219,7 @@ def test_validates_body_json_16(create_api):
] # Testing arrays and objects
with pytest.warns(UserWarning, match="this_isnt_supposed_to_be_here"):
calendar.calendarList.list(
validate=True,
json={
"items": [
{"accessRole": "a_valid_access_role"},
Expand All @@ -237,6 +239,7 @@ def test_validates_body_json_17(create_api):
] # Testing arrays and objects
with pytest.warns(UserWarning, match="this_isnt_supposed_to_be_here"):
calendar.calendarList.list(
validate=True,
json={"items": [{"this_isnt_supposed_to_be_here": True}]}
)

Expand All @@ -251,6 +254,7 @@ def test_validates_body_json_18(create_api):
] # Testing arrays and objects
with pytest.warns(UserWarning, match="this_isnt_supposed_to_be_here"):
calendar.calendarList.list(
validate=True,
json={"items": [{"this_isnt_supposed_to_be_here": "asdasdasd"}]}
)

Expand All @@ -266,6 +270,7 @@ def test_validates_body_json_19(create_api):
with pytest.warns(UserWarning, match="this_isnt_supposed_to_be_here"):
with pytest.raises(ValidationError):
calendar.calendarList.list(
validate=True,
json={
"items": [{"accessRole": 1, "this_isnt_supposed_to_be_here": 123}]
}
Expand All @@ -283,6 +288,7 @@ def test_validates_body_json_20(create_api):
with pytest.warns(UserWarning, match="this_isnt_supposed_to_be_here"):
with pytest.raises(ValidationError):
calendar.calendarList.list(
validate=True,
json={
"items": [
{"accessRole": 1, "this_isnt_supposed_to_be_here": "asdsda"}
Expand All @@ -300,6 +306,7 @@ def test_validates_body_json_21(create_api):
"response"
] # Testing arrays and objects
calendar.calendarList.list(
validate=True,
json={
"etag": "asd",
"items": [
Expand All @@ -325,6 +332,7 @@ def test_validates_body_json_22(create_api):
] # Testing arrays and objects
with pytest.raises(ValidationError):
calendar.calendarList.list(
validate=True,
json={
"etag": "asd",
"items": [
Expand All @@ -350,6 +358,7 @@ def test_validates_body_json_23(create_api):
] # Testing arrays and objects
with pytest.raises(ValidationError):
calendar.calendarList.list(
validate=True,
json={
"etag": "asd",
"items": [
Expand All @@ -376,6 +385,7 @@ def test_validates_body_json_24(create_api):
] # Testing arrays and objects
with pytest.raises(ValidationError):
calendar.calendarList.list(
validate=True,
json={
"etag": "asd",
"items": [
Expand Down Expand Up @@ -416,32 +426,38 @@ def test_validates_repeated(create_api):
sheets = create_api("sheets", "v4")
sheets.spreadsheets.values.batchGet(
spreadsheetId="IRRELEVANT",
ranges=['one', 'two']
ranges=['one', 'two'],
validate=True
)

sheets.spreadsheets.values.batchGet(
spreadsheetId="IRRELEVANT",
ranges=('one', 'two')
ranges=('one', 'two'),
validate=True
)

sheets.spreadsheets.values.batchGet(
spreadsheetId="IRRELEVANT",
ranges=set(['one', 'two'])
ranges=set(['one', 'two']),
validate=True
)

sheets.spreadsheets.values.batchGet(
spreadsheetId="IRRELEVANT",
ranges='one'
ranges='one',
validate=True
)

with pytest.raises(ValidationError):
sheets.spreadsheets.values.batchGet(
spreadsheetId="IRRELEVANT",
ranges=1
ranges=1,
validate=True
)

with pytest.raises(ValidationError):
sheets.spreadsheets.values.batchGet(
spreadsheetId="IRRELEVANT",
ranges=[132, 'valid'] # Only first item is invalid
ranges=[132, 'valid'], # Only first item is invalid
validate=True
)

0 comments on commit d8c73a7

Please sign in to comment.