# Path: tests/fixtures.py
# BING_MAPS_KEY = 'Av6_H8GIYQyP-DLQwLOKDknW64Qfm' \
#                 'VgJmVpfiSO861v0x_j1pLPCOW6s-70nCzEW'
# def create_tmp_dir(tmpdir):
# 
# Path: bingmaps/urls/traffic_build_urls.py
# class TrafficIncidentsSchema(MainParams, Schema):
#     """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/hh441726.aspx):
# 
#     :ivar mapArea[Required]: A rectangular area specified as a bounding box.
#         The size of the area can be a maximum of 500 km x 500 km. A bounding
#         box defines an area by specifying SouthLatitude, WestLongitude,
#         NorthLatitude, and EastLongitude values.
#     :ivar includeLocationCodes[Optional]:  One of the following
#         values:
#           - 'true'
#           - 'false' [default]
#         If you want to use the default value, you can omit this parameter from
#         the URL request.
#     :ivar severity[Optional]: One or more of the following integer
#         values:
#           - 1: LowImpact
#           - 2: Minor
#           - 3: Moderate
#           - 4: Serious
#         The default is to return traffic incidents for all severity levels.
#     :ivar type[Optional]: One or more of the following integer
#         values:
#           - 1: Accident
#           - 2: Congestion
#           - 3: DisabledVehicle
#           - 4: MassTransit
#           - 5: Miscellaneous
#           - 6: OtherNews
#           - 7: PlannedEvent
#           - 8: RoadHazard
#           - 9: Construction
#           - 10: Alert
#           - 11: Weather
#     :ivar o[Optional]: A string specifying the output as JSON or xml.
#     :ivar key[Required]: Bing maps key - REQUIRED field
# 
#     This schema helps in serializing the data.
# 
#     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.
# 
#     Example:
# 
#         ::
# 
#             >>> data = {'mapArea': [37, -105, 45, -94],
#             ...         'includeLocationCodes': 'true',
#             ...         'type': [5],
#             ...         'o': 'xml',
#             ...         'key': 'abs'}
#             >>> query = TrafficIncidentsSchema()
#             >>> query.dump(data).data
#             OrderedDict([('version', 'v1'), ('restApi', 'Traffic'), \
# ('resourcePath', 'Incidents'), ('query', \
# '37.0,-105.0,45.0,-94.0/true?type=5&o=xml&key=abs')])
#     """
#     mapArea = fields.List(
#         fields.Float,
#         required=True,
#         error_messages={'required': 'All the four coordinates required'},
#         validate=validate.Length(
#             min=4,
#             max=4,
#             error='All the four coordinates should be entered: south latitude,'
#                   'west longitude, north latitude and east longitude in the '
#                   'same order'
#         )
#     )
#     includeLocationCodes = fields.Str(
#         default='false'
#     )
#     severity = fields.List(
#         fields.Int
#     )
#     type = fields.List(
#         fields.Int
#     )
#     o = fields.Str()
#     key = fields.Str(
#         required=True,
#         error_messages={'required': 'Bing Maps API key required'}
#     )
# 
#     class Meta:
#         fields = ('version', 'restApi', 'resourcePath', 'mapArea',
#                   'includeLocationCodes', 'severity', 'type', 'o', 'key')
#         ordered = True
# 
#     @post_dump
#     def build_url(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
#         """
#         query_part_one = []
#         query_part_two = []
#         keys_to_be_removed = []
#         for key, value in data.items():
#             if key not in ['version', 'restApi', 'resourcePath']:
#                 if key == 'mapArea':
#                     query_part_one.append(','.join(str(val) for val in value))
#                     keys_to_be_removed.append(key)
#                 elif key == 'includeLocationCodes':
#                     query_part_one.append(value)
#                     keys_to_be_removed.append(key)
#                 else:
#                     if isinstance(value, list):
#                         value = ','.join(str(val) for val in value)
#                     query_part_two.append('{0}={1}'.format(key, value))
#                     keys_to_be_removed.append(key)
#         for k in keys_to_be_removed:
#             del data[k]
#         data['query'] = '{0}?{1}'.format('/'.join(query_part_one),
#                                          '&'.join(query_part_two))
#         return data


from .fixtures import parametrize
from bingmaps.urls import TrafficIncidentsSchema

DATA = [
    {'mapArea': [1, 2, 3, 4],
     'includeLocationCodes': 'true',
     'severity': [2, 4],
     'type': [2, 3],
     'key': 'abs'},
    {'includeLocationCodes': 'true',
     'severity': [2, 4],
     'type': [2, 3]}
]

EXPECTED = [
    ['v1', 'Traffic', 'Incidents',
     '1.0,2.0,3.0,4.0/true?severity=2,4&type=2,3&key=abs']
]


@parametrize('data,expected', [
    (DATA[0], EXPECTED[0])
])
def test_traffic_build_query_url(data, expected):
    traffic_data = TrafficIncidentsSchema()
    traffic_query = traffic_data.dump(data).data
    assert traffic_query['version'] in expected
    assert traffic_query['restApi'] in expected
    assert traffic_query['resourcePath'] in expected
    assert traffic_query['query'] in expected



# Path: tests/fixtures.py
# BING_MAPS_KEY = 'Av6_H8GIYQyP-DLQwLOKDknW64Qfm' \
#                 'VgJmVpfiSO861v0x_j1pLPCOW6s-70nCzEW'
# def create_tmp_dir(tmpdir):
# 
# Path: bingmaps/urls/traffic_build_urls.py
# class TrafficIncidentsSchema(MainParams, Schema):
#     """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/hh441726.aspx):
# 
#     :ivar mapArea[Required]: A rectangular area specified as a bounding box.
#         The size of the area can be a maximum of 500 km x 500 km. A bounding
#         box defines an area by specifying SouthLatitude, WestLongitude,
#         NorthLatitude, and EastLongitude values.
#     :ivar includeLocationCodes[Optional]:  One of the following
#         values:
#           - 'true'
#           - 'false' [default]
#         If you want to use the default value, you can omit this parameter from
#         the URL request.
#     :ivar severity[Optional]: One or more of the following integer
#         values:
#           - 1: LowImpact
#           - 2: Minor
#           - 3: Moderate
#           - 4: Serious
#         The default is to return traffic incidents for all severity levels.
#     :ivar type[Optional]: One or more of the following integer
#         values:
#           - 1: Accident
#           - 2: Congestion
#           - 3: DisabledVehicle
#           - 4: MassTransit
#           - 5: Miscellaneous
#           - 6: OtherNews
#           - 7: PlannedEvent
#           - 8: RoadHazard
#           - 9: Construction
#           - 10: Alert
#           - 11: Weather
#     :ivar o[Optional]: A string specifying the output as JSON or xml.
#     :ivar key[Required]: Bing maps key - REQUIRED field
# 
#     This schema helps in serializing the data.
# 
#     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.
# 
#     Example:
# 
#         ::
# 
#             >>> data = {'mapArea': [37, -105, 45, -94],
#             ...         'includeLocationCodes': 'true',
#             ...         'type': [5],
#             ...         'o': 'xml',
#             ...         'key': 'abs'}
#             >>> query = TrafficIncidentsSchema()
#             >>> query.dump(data).data
#             OrderedDict([('version', 'v1'), ('restApi', 'Traffic'), \
# ('resourcePath', 'Incidents'), ('query', \
# '37.0,-105.0,45.0,-94.0/true?type=5&o=xml&key=abs')])
#     """
#     mapArea = fields.List(
#         fields.Float,
#         required=True,
#         error_messages={'required': 'All the four coordinates required'},
#         validate=validate.Length(
#             min=4,
#             max=4,
#             error='All the four coordinates should be entered: south latitude,'
#                   'west longitude, north latitude and east longitude in the '
#                   'same order'
#         )
#     )
#     includeLocationCodes = fields.Str(
#         default='false'
#     )
#     severity = fields.List(
#         fields.Int
#     )
#     type = fields.List(
#         fields.Int
#     )
#     o = fields.Str()
#     key = fields.Str(
#         required=True,
#         error_messages={'required': 'Bing Maps API key required'}
#     )
# 
#     class Meta:
#         fields = ('version', 'restApi', 'resourcePath', 'mapArea',
#                   'includeLocationCodes', 'severity', 'type', 'o', 'key')
#         ordered = True
# 
#     @post_dump
#     def build_url(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
#         """
#         query_part_one = []
#         query_part_two = []
#         keys_to_be_removed = []
#         for key, value in data.items():
#             if key not in ['version', 'restApi', 'resourcePath']:
#                 if key == 'mapArea':
#                     query_part_one.append(','.join(str(val) for val in value))
#                     keys_to_be_removed.append(key)
#                 elif key == 'includeLocationCodes':
#                     query_part_one.append(value)
#                     keys_to_be_removed.append(key)
#                 else:
#                     if isinstance(value, list):
#                         value = ','.join(str(val) for val in value)
#                     query_part_two.append('{0}={1}'.format(key, value))
#                     keys_to_be_removed.append(key)
#         for k in keys_to_be_removed:
#             del data[k]
#         data['query'] = '{0}?{1}'.format('/'.join(query_part_one),
#                                          '&'.join(query_part_two))
#         return data


# Path: tests/test_traffic_query_string.py
from .fixtures import parametrize
from bingmaps.urls import TrafficIncidentsSchema


DATA = [
    {'mapArea': [1, 2, 3, 4],
     'includeLocationCodes': 'true',
     'severity': [2, 4],
     'type': [2, 3],
     'key': 'abs'},
    {'includeLocationCodes': 'true',
     'severity': [2, 4],
     'type': [2, 3]}
]

EXPECTED = [
    ['v1', 'Traffic', 'Incidents',
     '1.0,2.0,3.0,4.0/true?severity=2,4&type=2,3&key=abs']
]


@parametrize('data,expected', [
    (DATA[0], EXPECTED[0])
])
def test_traffic_build_query_url(data, expected):
    traffic_data = TrafficIncidentsSchema()
    traffic_query = traffic_data.dump(data).data
    assert traffic_query['version'] in expected
    assert traffic_query['restApi'] in expected
    assert traffic_query['resourcePath'] in expected
    assert traffic_query['query'] in expected



@parametrize('data', [