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_string_list_type():
class SchemaExample(schemas.Model):
area_list = schemas.StringListType(schemas.StringModelType(schemas.Area), separator="+")
string_list = schemas.StringListType(schemas.StringType, separator="+")
string_data = {"string_list": "a+b+c", "area_list": "10km@-36.847585,174.765742+10km@-41.288058,174.778265"}
list_data = {"string_list": ["a", "b", "c"], "area_list": ["10km@-36.847585,174.765742", "10km@-41.288058,174.778265"]}
dict_data = {"string_list": ["a", "b", "c"], "area_list": [{"radius": "10km", "latitude": -36.847585, "longitude": 174.765742}, {"radius": "10km", "latitude": -41.288058, "longitude": 174.778265}]}
expected_data = {"string_list": "a+b+c", "area_list": "10km@-36.847585,174.765742+10km@-41.288058,174.778265"}
m = SchemaExample()
assert m.import_data(string_data).to_primitive() == expected_data
assert m.import_data(list_data).to_primitive() == expected_data
assert m.import_data(dict_data).to_primitive() == expected_data
unique_item_data = {"string_list": "a", "area_list": "10km@-36.847585,174.765742"}
unique_item_dict_data = {"string_list": "a", "area_list": {"radius": "10km", "latitude": -36.847585, "longitude": 174.765742}}
assert m.import_data(unique_item_data).to_primitive() == unique_item_data
assert m.import_data(unique_item_dict_data).to_primitive() == unique_item_data
from predicthq.config import config
from predicthq.endpoints.schemas import Model, StringType, StringListType, IntType
class GetTokenParams(Model):
class Options:
serialize_when_none = False
client_id = StringType(default=lambda: config.OAUTH2_CLIENT_ID, required=True)
client_secret = StringType(default=lambda: config.OAUTH2_CLIENT_SECRET, required=True)
scope = StringListType(StringType, default=lambda: config.OAUTH2_SCOPE, separator=" ")
grant_type = StringType(choices=('client_credentials',), default='client_credentials', required=True)
class RevokeTokenParams(Model):
class Options:
serialize_when_none = False
client_id = StringType(default=lambda: config.OAUTH2_CLIENT_ID, required=True)
client_secret = StringType(default=lambda: config.OAUTH2_CLIENT_SECRET, required=True)
token = StringType(required=True)
token_type_hint = StringType(choices=('access_token', 'refresh_token'), default='access_token', required=True)
class AccessToken(Model):
class RevokeTokenParams(Model):
class Options:
serialize_when_none = False
client_id = StringType(default=lambda: config.OAUTH2_CLIENT_ID, required=True)
client_secret = StringType(default=lambda: config.OAUTH2_CLIENT_SECRET, required=True)
token = StringType(required=True)
token_type_hint = StringType(choices=('access_token', 'refresh_token'), default='access_token', required=True)
class AccessToken(Model):
access_token = StringType()
token_type = StringType()
scope = StringListType(StringType, separator=" ")
refresh_token = StringType(serialize_when_none=False)
expires_in = IntType(serialize_when_none=False)
def __init__(self, field, separator=" ", **kwargs):
self.separator = separator
super(StringListType, self).__init__(field, **kwargs)