def test_search_text(self, mock_search_text_result): with responses.RequestsMock() as rsps: rsps.add(mock_search_text_result) result = AMapSession(default_key='xxx').search_text( prepared_hook=self.prepare_hook, response_hook=self.repsonse_hook, ) result.raise_for_status()
def test_district(self, mock_district_result): with responses.RequestsMock() as rsps: rsps.add(mock_district_result) result = AMapSession(default_key='x').district( keyword='x', prepared_hook=self.prepare_hook, response_hook=self.repsonse_hook, ) result.raise_for_status()
def test_search_around(self, mock_search_around_result): with responses.RequestsMock() as rsps: rsps.add(mock_search_around_result) result = AMapSession(default_key='x').search_around( location='1,2', prepared_hook=self.prepare_hook, response_hook=self.repsonse_hook, ) result.raise_for_status()
def test_regeo_code(self, mock_regeo_code_result): with responses.RequestsMock() as rsps: rsps.add(mock_regeo_code_result) result = AMapSession(default_key='xxx').regeo_code( location='1,2', prepared_hook=self.prepare_hook, response_hook=self.repsonse_hook, ) result.raise_for_status()
def test_mount(self, schema, coder): model = AMapSession() model.mount(schema, coder) if schema == 'encode': assert model.encoder == coder elif schema == 'decode': assert model.decoder == coder elif schema == 'request': assert model.request == coder
def test_driving(self, mock_driving_result): with responses.RequestsMock() as rsps: rsps.add(mock_driving_result) result = AMapSession(default_key='x').driving( origin='1,2', destination='1,2', prepared_hook=self.prepare_hook, response_hook=self.repsonse_hook, ) result.raise_for_status()
def test_batch(self, mock_batch_result): from thrall.amap.models import (GeoCodeRequestParams, ReGeoCodeRequestParams) from thrall.amap.session import (BATCH_URL_DEFAULT_PAIRS, BATCH_DECODE_DEFAULT_PAIRS) with responses.RequestsMock() as rsps: rsps.add(mock_batch_result) result = AMapSession(default_key='x').batch( batch_list=[ GeoCodeRequestParams(address='xx', key='xxx'), ReGeoCodeRequestParams(location='1,2', key='xss') ], url_pairs=BATCH_URL_DEFAULT_PAIRS, decode_pairs=BATCH_DECODE_DEFAULT_PAIRS, key='x', prepared_hook=self.prepare_hook, response_hook=self.repsonse_hook, ) result.raise_for_status()
def test_init(self, mocker, default_key, default_pkey): mocker.spy(AMapSession, 'mount') model = AMapSession(default_key=default_key, default_private_key=default_pkey) assert model.encoder is not None assert model.decoder is not None assert model.request is not None assert model.brequest is not None assert model.mount.call_count == 4
def test_mount_schema_error(self): model = AMapSession() with pytest.raises(TypeError): model.mount('code', AMapEncodeAdapter)
def test_mount_error(self, encoder): model = AMapSession() with pytest.raises(TypeError): model.mount('encode', encoder)