- Notifications
You must be signed in to change notification settings - Fork 37
Params validation for API methods #119
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
Changes from 9 commits
1af4507
567f7f6
785dc01
b807baa
add9feb
691c9ea
2bd8ece
c08f264
487b66c
28b9a78
7398ccf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2016-2017, Optimizely | ||
# Copyright 2016-2018, Optimizely | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
| @@ -14,6 +14,7 @@ | |
import json | ||
import jsonschema | ||
| ||
from six import string_types | ||
from optimizely.user_profile import UserProfile | ||
from . import constants | ||
| ||
| @@ -151,3 +152,18 @@ def is_user_profile_valid(user_profile): | |
return False | ||
| ||
return True | ||
| ||
| ||
def is_non_empty_string(input_id_key): | ||
""" Determine if provided input_id_key is a non-empty string or not. | ||
| ||
Args: | ||
input_id_key: Variable which needs to be validated. | ||
| ||
Returns: | ||
Boolean depending upon whether input is valid or not. | ||
""" | ||
if isinstance(input_id_key, string_types) and input_id_key: | ||
| ||
return True | ||
| ||
return False |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2016-2017, Optimizely | ||
# Copyright 2016-2018, Optimizely | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
| @@ -130,6 +130,22 @@ def test_is_user_profile_valid__returns_false(self): | |
'experiment_bucket_map': {'1234': {'variation_id': '5678'}, | ||
'1235': {'some_key': 'some_value'}}})) | ||
| ||
def test_is_non_empty_string(self): | ||
""" Test that the method returns True only for a non-empty string. """ | ||
| ||
self.assertFalse(validator.is_non_empty_string(None)) | ||
self.assertFalse(validator.is_non_empty_string([])) | ||
self.assertFalse(validator.is_non_empty_string({})) | ||
self.assertFalse(validator.is_non_empty_string(0)) | ||
self.assertFalse(validator.is_non_empty_string(99)) | ||
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("")) | ||
| ||
| ||
self.assertTrue(validator.is_non_empty_string("0")) | ||
| ||
self.assertTrue(validator.is_non_empty_string("test_user")) | ||
| ||
| ||
| ||
class DatafileValidationTests(base.BaseTest): | ||
| ||
|
There was a problem hiding this comment.
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.