Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Params validation for API methods #119

Merged
merged 11 commits into from
Aug 28, 2018
Merged

Conversation

oakbani
Copy link
Contributor

@oakbani oakbani commented Apr 20, 2018

No description provided.

@coveralls
Copy link

coveralls commented Apr 20, 2018

Coverage Status

Coverage increased (+0.008%) to 99.661% when pulling 7398ccf on oakbani/validate-inputs into 90e172d on master.

@@ -151,3 +152,25 @@ def is_user_profile_valid(user_profile):
return False

return True


def is_non_empty_string(test_var):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. test_var is not a good variable name.

"""
PY3 = sys.version_info[0] == 3

if PY3:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you don't do this?

Copy link
Contributor Author

@oakbani oakbani Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Namerror. basestring was removed in Python3. https://docs.python.org/3.0/whatsnew/3.0.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if there is a better way to accomplish what you are doing here.

Returns:
Boolean depending upon whether input is valid or not.
"""
if isinstance(input, string_types) and input:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input is a built in Python function name. Please change this name.

Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please address comments before merging.

@@ -14,6 +14,7 @@
import json
import jsonschema

from six import string_types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. This is an external package so it should be imported on line 16 and line 17 should be empty.

Returns:
Boolean depending upon whether input is valid or not.
"""
if isinstance(input_id_key, string_types) and input_id_key:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps flip it to be:

if input_id_key and isinstance(input_id_key, string_types)

self.assertFalse(validator.is_non_empty_string(1.2))
self.assertFalse(validator.is_non_empty_string(True))
self.assertFalse(validator.is_non_empty_string(False))
self.assertFalse(validator.is_non_empty_string(""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. Single quotes

self.assertFalse(validator.is_non_empty_string(False))
self.assertFalse(validator.is_non_empty_string(""))

self.assertTrue(validator.is_non_empty_string("0"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. Single quotes.

self.assertFalse(validator.is_non_empty_string(""))

self.assertTrue(validator.is_non_empty_string("0"))
self.assertTrue(validator.is_non_empty_string("test_user"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@msohailhussain
Copy link
Contributor

travis ci is getting failed on Python 3.5, let us investigate this issue.

@aliabbasrizvi
Copy link
Contributor

@oakbani can you rebase against master and re-submit. Travis tests should pass then.

@aliabbasrizvi aliabbasrizvi merged commit 84736de into master Aug 28, 2018
@aliabbasrizvi aliabbasrizvi deleted the oakbani/validate-inputs branch August 28, 2018 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants