def test_set_schema_adds_a_schema_from_the_eng_data_type(): schema = load_schema('hep') subschema = schema['properties']['$schema'] data = {} extra_data = {} obj = MockObj(data, extra_data) eng = MockEng(data_type='hep') assert set_schema(obj, eng) is None expected = 'http://localhost:5000/schemas/records/hep.json' result = obj.data assert validate(result['$schema'], subschema) is None assert expected == result['$schema']
def test_set_schema_does_nothing_when_the_schema_url_is_already_full(): schema = load_schema('hep') subschema = schema['properties']['$schema'] data = {'$schema': 'http://localhost:5000/schemas/records/hep.json'} extra_data = {} assert validate(data['$schema'], subschema) is None obj = MockObj(data, extra_data) eng = MockEng() assert set_schema(obj, eng) is None expected = 'http://localhost:5000/schemas/records/hep.json' result = obj.data assert validate(result['$schema'], subschema) is None assert expected == result['$schema']
def test_set_schema_builds_a_full_url_for_the_schema(): schema = load_schema('hep') subschema = schema['properties']['$schema'] data = {'$schema': 'hep.json'} extra_data = {} # XXX: this violates the usual workflow invariant (valid in, valid out), # but we can't really do otherwise, as inspire-dojson does not know the # actual SERVER_NAME. with pytest.raises(ValidationError): validate(data['$schema'], subschema) obj = MockObj(data, extra_data) eng = MockEng() assert set_schema(obj, eng) is None expected = 'http://localhost:5000/schemas/records/hep.json' result = obj.data assert validate(result['$schema'], subschema) is None assert expected == result['$schema']