def test_repr(self): raw_data = """{"status": "1", "info": "OK", "infocode": "10000", "count": "1", "geocodes":[]}""" model = _base_model.BaseResponseData(raw_data) for i in ['status=', 'status_msg=', 'count=', 'version=']: assert i in repr(model)
def test_auto_check_version_v4_init(self): raw_data = '{"errcode": 0, "errdetail": null, "errmsg": "OK"}' model = _base_model.BaseResponseData(raw_data, auto_version=True) assert model.status == 1 assert model.status_msg.code == 0 assert model.status_msg.msg == 'OK' assert model.status_msg.detail is None assert model.version == 4 assert model.count == 0
def test_init_v4_ok(self): raw_data = '{"errcode": 0, "errdetail": null, "errmsg": "OK"}' model = _base_model.BaseResponseData(raw_data, AMapVersion.V4) assert model.status == 1 assert model.status_msg.code == 0 assert model.status_msg.msg == 'OK' assert model.status_msg.detail is None assert model.version == 4 assert model.count == 0
def test_auto_check_version_init(self): raw_data = """{"status": "1", "info": "OK", "infocode": "10000", "count": "1", "geocodes":[]}""" model = _base_model.BaseResponseData(raw_data, auto_version=True) assert model.status == 1 assert model.status_msg.code == 10000 assert model.status_msg.msg == 'OK' assert model.status_msg.detail == '' assert model.version == 3 assert model.count == 1
def test_init_v4_err(self): raw_data = """{"errcode": 30006, "errdetail": "您输入的起点信息有误,请检验是否符合接口使用规范", "errmsg": "INVALID_PARAMETER_VALUE"}""" model = _base_model.BaseResponseData(raw_data, AMapVersion.V4) assert model.status == 0 assert model.status_msg.code == 30006 assert model.status_msg.msg == 'INVALID_PARAMETER_VALUE' assert model.status_msg.detail == u"您输入的起点信息有误,请检验是否符合接口使用规范" assert model.count == 0 assert model.version == 4
def test_init_no_count(self): raw_data = """{"status": "1", "info": "OK", "infocode": "10000", "geocodes":[]}""" model = _base_model.BaseResponseData(raw_data) assert model.status == 1 assert model.status_msg.code == 10000 assert model.status_msg.msg == 'OK' assert model.status_msg.detail == '' assert model.version == 3 assert model.count == 0 model.raise_for_status()
def test_init_err(self): raw_data = """{"status": "0", "info": "INVALID_USER_KEY", "infocode": "10001"}""" model = _base_model.BaseResponseData(raw_data) assert model.status == 0 assert model.status_msg.code == 10001 assert model.status_msg.msg == 'INVALID_USER_KEY' assert model.status_msg.detail == '' assert model.count == 0 assert model.version == 3 with pytest.raises(AMapStatusError): model.raise_for_status()
def test_init_ok(self): raw_data = """{"status": "1", "info": "OK", "infocode": "10000", "count": "1", "geocodes":[]}""" model = _base_model.BaseResponseData(raw_data) assert model.status == 1 assert isinstance(model.status, StatusFlag) assert model.status_msg.code == 10000 assert model.status_msg.msg == 'OK' assert model.status_msg.detail == '' assert isinstance(model.status_msg, MapStatusMessage) assert model.count == 1 assert model.version == 3 model.raise_for_status()
def test_get_data(self): with pytest.raises(NotImplementedError): raw_data = """{"status": "1", "info": "OK", "infocode": "10000", "count": "1", "geocodes":[]}""" model = _base_model.BaseResponseData(raw_data) model._get_data()