def test_init_ok(self): raw_data = "{}" model = _batch_model.BatchResponseData(raw_data, None, None) assert model.prepared_data is None assert model.decode_pairs == {} assert model._raw_data is None
def test_raise_for_status_ok(self, mock_prepared_data): model = _batch_model.BatchResponseData( p=mock_prepared_data, raw_data=self.RAW_DATA, decode_pairs=BATCH_DECODE_DEFAULT_PAIRS, static_mode=True) model.raise_for_status()
def test_get_batch_status_msg(self, mock_prepared_data): model = _batch_model.BatchResponseData( p=mock_prepared_data, raw_data=self.RAW_DATA, decode_pairs=BATCH_DECODE_DEFAULT_PAIRS, static_mode=True) assert len(model.batch_status_msg) == 2 assert model.batch_status_msg[0] == model.data[0].status_msg assert model.batch_status_msg[1] == model.data[1].status_msg
def test_raise_for_status_request_err(self): raw_data = """{"status":"0","info":"INVALID_BATCH_PARAM", "infocode":"20005"}""" model = _batch_model.BatchResponseData( p=None, raw_data=raw_data, decode_pairs=BATCH_DECODE_DEFAULT_PAIRS, static_mode=True) from thrall.exceptions import AMapStatusError with pytest.raises(AMapStatusError) as err: model.raise_for_status() assert '20005-INVALID_BATCH_PARAM' in str(err.value)
def test_raise_for_status_batch_params_err(self, mock_prepared_data): raw_data = ( '[{"status":200,"body":{"info":"OK","status":"1","count":"1",' '"geocodes":[{"level":"兴趣点","city":"上海市","province":"上海市",' '"neighborhood":{"name":{},"type":{}},"building":{"name":{},"type":{' '}},"street":{},"number":{},"township":{},' '"formatted_address":"上海市普陀区近铁城市广场","location":"121.380638,' '31.231571","adcode":"310107","district":"普陀区","citycode":"021"}],' '"infocode":"10000"},"header":{' '"gsid":"011131017040151133202135800187559487341",' '"Content-Type":"application\/json;charset=UTF-8",' '"Access-Control-Allow-Methods":"*",' '"Access-Control-Allow-Origin":"*","sc":"0.010",' '"Content-Length":393,"Access-Control-Allow-Headers":"DNT,' 'X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,' 'If-Modified-Since,Cache-Control,Content-Type,key,x-biz,x-info,' 'platinfo,encr,enginever,gzipped,poiid",' '"X-Powered-By":"ring\/1.0.0"}},{"status":200,"body":{"status":"0",' '"info":"INVALID_USER_KEY","infocode":"10001"},"header":{' '"gsid":"011131017040151133202135800187559487341",' '"Content-Type":"application\/json",' '"Access-Control-Allow-Methods":"*",' '"Access-Control-Allow-Origin":"*","sc":"0.000","Content-Length":59,' '"Access-Control-Allow-Headers":"DNT,X-CustomHeader,Keep-Alive,' 'User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,' 'Content-Type,key,x-biz,x-info,platinfo,encr,enginever,gzipped,' 'poiid","X-Powered-By":"ring\/1.0.0"}}]') model = _batch_model.BatchResponseData( p=mock_prepared_data, raw_data=raw_data, decode_pairs=BATCH_DECODE_DEFAULT_PAIRS, static_mode=True) from thrall.exceptions import AMapStatusError with pytest.raises(AMapBatchStatusError) as e: model.raise_for_status() assert e.value.errors[0] is None assert isinstance(e.value.errors[1], AMapStatusError)
def test_status_msg(self, raw_data, status_msg): model = _batch_model.BatchResponseData(raw_data, None, None) assert model.status_msg == status_msg
def test_count(self, raw_data, count): model = _batch_model.BatchResponseData(raw_data, None, None) assert model.count == count