# Path: bingmaps/urls/locations_build_urls.py
# class LocationByQuerySchema(Location, Schema):
#     """Inherits from :class:`Location`
# 
#     Schema for query parameters in which all the fields will be in a ordered
#     way. All the fields will be dumped in the same order as mentioned in the
#     schema.
# 
#     Data Fields for the schema (taken from
#     https://msdn.microsoft.com/en-us/library/ff701711.aspx):
# 
#     :ivar q[Required]: A string (query) that contains information about a
#         location, such as an address or landmark name.
#     :ivar includeNeighborhood[Optional]: One of the following
#         values:
#           - 1: Include neighborhood information when available.
#           - 0 [default]: Do not include neighborhood information.
#     :ivar include[Optional]: One or more of the following
#         options:
#           - queryParse: Specifies that the response shows how the query string
#             was parsed into address values, such as addressLine, locality,
#             adminDistrict, and postalCode.
#           - ciso2: Specifies to include the two-letter ISO country code.
#         If you specify more than one include value, separate the values with a
#         comma.
#     :ivar c[Optional]: A string specifying the culture parameter
#     :ivar o[Optional]: A string for specifying the format of output(response)
#         Ex. - xml/json
#           - If empty, default output would be a JSON data string
#           - If given xml, the output would be an xml data string
#     :ivar maxResults[Optional]: An integer between 1 and 20 (number of
#         results)
#           - default=20
#     :ivar key[Required]: Bing maps api
#         key
#           - Required
# 
#     Post-Dump:
#         After dumping the data, build_query_string builds up the
#         queryParameters string. The final value after dumping the data would
#         be a string. The string would be similar to the one mentioned in the
#         below example.
# 
#     Example:
# 
#         ::
# 
#             >>> data = {'q': '1014 Oatney Ridge Ln., Morrisville,NC-27560',
#             ...         'key': 'abs'}
#             >>> query = LocationByQuerySchema()
#             >>> query.dump(data).data
#             OrderedDict([('version', 'v1'), ('restApi', 'Locations'), ('query\
# ', 'q=1014%20Oatney%20Ridge%20Ln.%2C%20Morrisville\
# %2CNC-27560&includeNeighborhood=0&include=ciso2&maxResults=20&key=abs')])
# 
#         In the output, you can see 'include', 'maxResults' in the string
#         although we haven't specified any values because they are default
#         values specified in the schema.
#     """
#     q = fields.Str(
#         required=True,
#         error_messages={'required': 'require a query string'}
#     )
#     includeNeighborhood = fields.Int(
#         default=0
#     )
#     include = fields.Str(
#         default='ciso2'
#     )
#     c = fields.Str()
#     o = fields.Str()
#     maxResults = fields.Int(
#         default=20
#     )
#     key = fields.Str(
#         required=True,
#         error_messages={'required': 'Please provide a key'}
#     )
# 
#     class Meta:
#         fields = ('version', 'restApi', 'resourcePath',
#                   'q', 'includeNeighborhood', 'include', 'c', 'o',
#                   'maxResults', 'key')
#         ordered = True
# 
#     @post_dump
#     def build_query_string(self, data):
#         """This method occurs after dumping the data into the class.
# 
#         Args:
#             data (dict): dictionary of all the query values
# 
#         Returns:
#             data (dict): ordered dict of all the values
# 
#         The query string consists of all the values concatenated
#         with '&'. As part of the location by query services, the url will
#         be encoded. If the 'query' consists of spaces, commas, or other
#         special characters all those will be encoded.
# 
#         For example:
#           - space(' ') - %20
#           - comma(,) - %2C, etc.
#         """
#         query_params = []
#         keys_to_be_removed = []
#         for key, value in data.items():
#             if key not in ['version', 'restApi', 'resourcePath']:
#                 if key == 'q':
#                     query_params.append('{0}={1}'.format(key,
#                                                          quote(value)))
#                     keys_to_be_removed.append(key)
#                 else:
#                     query_params.append('{0}={1}'.format(key,
#                                                          value))
#                     keys_to_be_removed.append(key)
#         for k in list(set(keys_to_be_removed)):
#             del data[k]
#         data['query'] = "&".join(query_params)
#         return data
# 
# Path: tests/fixtures.py
# BING_MAPS_KEY = 'Av6_H8GIYQyP-DLQwLOKDknW64Qfm' \
#                 'VgJmVpfiSO861v0x_j1pLPCOW6s-70nCzEW'
# def create_tmp_dir(tmpdir):


from bingmaps.urls import LocationByQuerySchema
from .fixtures import parametrize, BING_MAPS_KEY

DATA = [
    {'q': '1014 Oatney Ridge Ln., Morrisville, NC-27560',
     'key': BING_MAPS_KEY},
    {'q': '1014 Oatney Ridge Ln., Morrisville, NC-27560'},
    {
        'q': '1014 Oatney Ridge Ln., Morrisville, NC-27560',
        'key': BING_MAPS_KEY
    }
]

EXPECTED = [
    False,
    True,
    'q=1014%20Oatney%20Ridge%20Ln.%2C%20Morrisville%2C%20NC-27560&'
    'includeNeighborhood=0&include=ciso2&maxResults=20&key={0}'.format(

# Path: bingmaps/urls/locations_build_urls.py
# class LocationByQuerySchema(Location, Schema):
#     """Inherits from :class:`Location`
# 
#     Schema for query parameters in which all the fields will be in a ordered
#     way. All the fields will be dumped in the same order as mentioned in the
#     schema.
# 
#     Data Fields for the schema (taken from
#     https://msdn.microsoft.com/en-us/library/ff701711.aspx):
# 
#     :ivar q[Required]: A string (query) that contains information about a
#         location, such as an address or landmark name.
#     :ivar includeNeighborhood[Optional]: One of the following
#         values:
#           - 1: Include neighborhood information when available.
#           - 0 [default]: Do not include neighborhood information.
#     :ivar include[Optional]: One or more of the following
#         options:
#           - queryParse: Specifies that the response shows how the query string
#             was parsed into address values, such as addressLine, locality,
#             adminDistrict, and postalCode.
#           - ciso2: Specifies to include the two-letter ISO country code.
#         If you specify more than one include value, separate the values with a
#         comma.
#     :ivar c[Optional]: A string specifying the culture parameter
#     :ivar o[Optional]: A string for specifying the format of output(response)
#         Ex. - xml/json
#           - If empty, default output would be a JSON data string
#           - If given xml, the output would be an xml data string
#     :ivar maxResults[Optional]: An integer between 1 and 20 (number of
#         results)
#           - default=20
#     :ivar key[Required]: Bing maps api
#         key
#           - Required
# 
#     Post-Dump:
#         After dumping the data, build_query_string builds up the
#         queryParameters string. The final value after dumping the data would
#         be a string. The string would be similar to the one mentioned in the
#         below example.
# 
#     Example:
# 
#         ::
# 
#             >>> data = {'q': '1014 Oatney Ridge Ln., Morrisville,NC-27560',
#             ...         'key': 'abs'}
#             >>> query = LocationByQuerySchema()
#             >>> query.dump(data).data
#             OrderedDict([('version', 'v1'), ('restApi', 'Locations'), ('query\
# ', 'q=1014%20Oatney%20Ridge%20Ln.%2C%20Morrisville\
# %2CNC-27560&includeNeighborhood=0&include=ciso2&maxResults=20&key=abs')])
# 
#         In the output, you can see 'include', 'maxResults' in the string
#         although we haven't specified any values because they are default
#         values specified in the schema.
#     """
#     q = fields.Str(
#         required=True,
#         error_messages={'required': 'require a query string'}
#     )
#     includeNeighborhood = fields.Int(
#         default=0
#     )
#     include = fields.Str(
#         default='ciso2'
#     )
#     c = fields.Str()
#     o = fields.Str()
#     maxResults = fields.Int(
#         default=20
#     )
#     key = fields.Str(
#         required=True,
#         error_messages={'required': 'Please provide a key'}
#     )
# 
#     class Meta:
#         fields = ('version', 'restApi', 'resourcePath',
#                   'q', 'includeNeighborhood', 'include', 'c', 'o',
#                   'maxResults', 'key')
#         ordered = True
# 
#     @post_dump
#     def build_query_string(self, data):
#         """This method occurs after dumping the data into the class.
# 
#         Args:
#             data (dict): dictionary of all the query values
# 
#         Returns:
#             data (dict): ordered dict of all the values
# 
#         The query string consists of all the values concatenated
#         with '&'. As part of the location by query services, the url will
#         be encoded. If the 'query' consists of spaces, commas, or other
#         special characters all those will be encoded.
# 
#         For example:
#           - space(' ') - %20
#           - comma(,) - %2C, etc.
#         """
#         query_params = []
#         keys_to_be_removed = []
#         for key, value in data.items():
#             if key not in ['version', 'restApi', 'resourcePath']:
#                 if key == 'q':
#                     query_params.append('{0}={1}'.format(key,
#                                                          quote(value)))
#                     keys_to_be_removed.append(key)
#                 else:
#                     query_params.append('{0}={1}'.format(key,
#                                                          value))
#                     keys_to_be_removed.append(key)
#         for k in list(set(keys_to_be_removed)):
#             del data[k]
#         data['query'] = "&".join(query_params)
#         return data
# 
# Path: tests/fixtures.py
# BING_MAPS_KEY = 'Av6_H8GIYQyP-DLQwLOKDknW64Qfm' \
#                 'VgJmVpfiSO861v0x_j1pLPCOW6s-70nCzEW'
# def create_tmp_dir(tmpdir):


# Path: tests/test_location_by_query_string.py
from bingmaps.urls import LocationByQuerySchema
from .fixtures import parametrize, BING_MAPS_KEY


DATA = [
    {'q': '1014 Oatney Ridge Ln., Morrisville, NC-27560',
     'key': BING_MAPS_KEY},
    {'q': '1014 Oatney Ridge Ln., Morrisville, NC-27560'},
    {
        'q': '1014 Oatney Ridge Ln., Morrisville, NC-27560',
        'key': BING_MAPS_KEY
    }
]

EXPECTED = [
    False,
    True,
    'q=1014%20Oatney%20Ridge%20Ln.%2C%20Morrisville%2C%20NC-27560&'
    'includeNeighborhood=0&include=ciso2&maxResults=20&key={0}'.format(

        BING_MAPS_KEY