<commit_before>import pytest

from bingmaps import BING_MAPS_KEY
from bingmaps.location import LocationByAddress
from bingmaps.urlschema import LocationByAddressQueryString
from .fixtures import parametrize

http_protocol = 'http'
https_protocol = 'https'

DATA = [{'queryParameters': {'adminDistrict': 'WA'}},
        {'key': 'vds'},
        {'queryParameters':
            {'adminDistrict': 'WA',
             'locality': 'Seattle',
             'key': 'abs'}},
        {'queryParameters':
            {'adminDistrict': 'WA',
             'locality': 'Seattle',
             'key': BING_MAPS_KEY}},
        {'queryParameters':
            {'adminDistrict': 'WA',
             'locality': 'Seattle',
             'key': BING_MAPS_KEY}},
        {'queryParameters':
            {'adminDistrict': 'WA',
             'locality': 'Seattle',
             'o': 'xml',
             'key': BING_MAPS_KEY}}
        ]

EXPECTED = [
    True,
    False,
    'adminDistrict=WA&locality=Seattle&includeNeighborhood='
    '1&include=ciso2&maxResults=20&key=abs',
    'http://dev.virtualearth.net/REST/v1/Locations?'
    'adminDistrict=WA&locality=Seattle&includeNeighborhood='
    '1&include=ciso2&maxResults='
    '20&key={0}'.format(BING_MAPS_KEY),
    'https://dev.virtualearth.net/REST/v1/Locations?'
    'adminDistrict=WA&locality=Seattle&includeNeighborhood='
    '1&include=ciso2&maxResults='
    '20&key={0}'.format(BING_MAPS_KEY),
    'https://dev.virtualearth.net/REST/v1/Locations?'
    'adminDistrict=WA&locality=Seattle&o=xml&includeNeighborhood='
    '1&include=ciso2&maxResults='
    '20&key={0}'.format(BING_MAPS_KEY)
]


@parametrize('data,expected', [
    (DATA[0], EXPECTED[0]),
    (DATA[1], EXPECTED[1])
])
def test_schema_without_key(data, expected):
    schema = LocationByAddressQueryString()
    is_valid_schema = schema.validate(data)
    assert bool(is_valid_schema) is expected


@parametrize('data,expected', [
    (DATA[2], EXPECTED[2])
])
def test_consolidate_query_dict(data, expected):
    query = LocationByAddressQueryString()
    query_string = query.dump(data['queryParameters']).data
    assert query_string == expected


@parametrize('data,expected', [
    (DATA[3], EXPECTED[3])
])
def test_build_url_http_protocol(data, expected):
    loc_by_address = LocationByAddress(data, http_protocol)
    url = loc_by_address.build_url()
    assert url == expected
<commit_msg>Change includeNeighborhood default value to 0<commit_after>import pytest

from bingmaps import BING_MAPS_KEY
from bingmaps.location import LocationByAddress
from bingmaps.urlschema import LocationByAddressQueryString
from .fixtures import parametrize

http_protocol = 'http'
https_protocol = 'https'

DATA = [{'queryParameters': {'adminDistrict': 'WA'}},
        {'key': 'vds'},
        {'queryParameters':
            {'adminDistrict': 'WA',
             'locality': 'Seattle',
             'key': 'abs'}},
        {'queryParameters':
            {'adminDistrict': 'WA',
             'locality': 'Seattle',
             'key': BING_MAPS_KEY}},
        {'queryParameters':
            {'adminDistrict': 'WA',
             'locality': 'Seattle',
             'key': BING_MAPS_KEY}},
        {'queryParameters':
            {'adminDistrict': 'WA',
             'locality': 'Seattle',
             'o': 'xml',
             'key': BING_MAPS_KEY}}
        ]

EXPECTED = [
    True,
    False,
    'adminDistrict=WA&locality=Seattle&includeNeighborhood='
    '0&include=ciso2&maxResults=20&key=abs',
    'http://dev.virtualearth.net/REST/v1/Locations?'
    'adminDistrict=WA&locality=Seattle&includeNeighborhood='
    '0&include=ciso2&maxResults='
    '20&key={0}'.format(BING_MAPS_KEY),
    'https://dev.virtualearth.net/REST/v1/Locations?'
    'adminDistrict=WA&locality=Seattle&includeNeighborhood='
    '0&include=ciso2&maxResults='
    '20&key={0}'.format(BING_MAPS_KEY),
    'https://dev.virtualearth.net/REST/v1/Locations?'
    'adminDistrict=WA&locality=Seattle&o=xml&includeNeighborhood='
    '0&include=ciso2&maxResults='
    '20&key={0}'.format(BING_MAPS_KEY)
]


@parametrize('data,expected', [
    (DATA[0], EXPECTED[0]),
    (DATA[1], EXPECTED[1])
])
def test_schema_without_key(data, expected):
    schema = LocationByAddressQueryString()
    is_valid_schema = schema.validate(data)
    assert bool(is_valid_schema) is expected


@parametrize('data,expected', [
    (DATA[2], EXPECTED[2])
])
def test_consolidate_query_dict(data, expected):
    query = LocationByAddressQueryString()
    query_string = query.dump(data['queryParameters']).data
    assert query_string == expected


@parametrize('data,expected', [
    (DATA[3], EXPECTED[3])
])
def test_build_url_http_protocol(data, expected):
    loc_by_address = LocationByAddress(data, http_protocol)
    url = loc_by_address.build_url()
    assert url == expected

{'fraction_non_alphanumeric': 0.1493156366652841, 'fraction_numerical': 0.012650352550808793, 'mean_word_length': 3.7099609375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '124181', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1581, 'n_words': 241}