def test_object_pair_serialization_defaults(inp): dumped = schema.ReportObjectPair().dumps(inp) out = json.loads(dumped) assert out['forecast'] == inp['forecast'] assert out['observation'] == inp['observation'] assert out['reference_forecast'] is None assert out['uncertainty'] is None assert out['forecast_type'] == 'forecast'
def test_object_pair_deserialization(user, inp): deserialized = schema.ReportObjectPair().loads(inp) assert 'forecast' in deserialized assert (bool('observation' in deserialized) != bool('aggregate' in deserialized)) assert deserialized['reference_forecast'] is None assert deserialized['uncertainty'] is None assert deserialized['forecast_type'] == 'forecast'
def test_object_pair_serialization(inp): dumped = schema.ReportObjectPair().dumps(inp) out = json.loads(dumped) assert out == inp
def test_object_pair_with_ref(inp, user): deserialized = schema.ReportObjectPair().loads(inp) assert deserialized['forecast'] == uuid.UUID("11c20780-76ae-4b11-bef1-7a75bdc784e3") # noqa assert deserialized['observation'] == uuid.UUID("123e4567-e89b-12d3-a456-426655440000") # noqa assert deserialized['reference_forecast'] == uuid.UUID("11c20780-76ae-4b11-bef1-7a75bdc784e3") # noqa
def test_object_pair_test_validation(inp): with pytest.raises(marshmallow.exceptions.ValidationError): schema.ReportObjectPair().loads(inp)
def test_object_pair_with_invalid_forecast_type(forecast_type): pair_dict = base_pair_dict.copy() pair_dict.update({'forecast_type': forecast_type}) pair_json = json.dumps(pair_dict) with pytest.raises(marshmallow.exceptions.ValidationError): schema.ReportObjectPair().loads(pair_json)
def test_object_pair_with_invalid_uncertainty(uncertainty): pair_dict = base_pair_dict.copy() pair_dict.update({'uncertainty': uncertainty}) pair_json = json.dumps(pair_dict) with pytest.raises(marshmallow.exceptions.ValidationError): schema.ReportObjectPair().loads(pair_json)
def test_object_pair_with_uncertainty(uncertainty, exp_type, user): pair_dict = base_pair_dict.copy() pair_dict.update({'uncertainty': uncertainty}) pair_json = json.dumps(pair_dict) deserialized = schema.ReportObjectPair().loads(pair_json) assert isinstance(deserialized['uncertainty'], exp_type)