Esempio n. 1
0
def test_returns_display_date_if_start_and_end_date_present():
    schema = PositionSchemaV1()
    dump = {
        "institution": "CERN",
        "start_date": "2000",
        "end_date": "2015",
        "record": {
            "$ref": "http://localhost:5000/api/institutions/903138"
        },
    }

    position_schema = load_schema(
        "authors")["properties"]["positions"]["items"]
    assert validate(dump, position_schema) is None

    expected = {
        "institution": "CERN",
        "display_date": "2000-2015",
        "record": {
            "$ref": "http://localhost:5000/api/institutions/903138"
        },
    }

    result = schema.dumps(dump).data

    assert expected == orjson.loads(result)
Esempio n. 2
0
def test_returns_display_date_if_end_date_present():
    schema = PositionSchemaV1()
    dump = {"institution": "CERN", "end_date": "2000"}

    position_schema = load_schema(
        "authors")["properties"]["positions"]["items"]
    assert validate(dump, position_schema) is None

    expected = {"institution": "CERN", "display_date": "2000"}

    result = schema.dumps(dump).data

    assert expected == json.loads(result)
Esempio n. 3
0
def test_returns_display_date_if_only_current_set():
    schema = PositionSchemaV1()
    dump = {"institution": "CERN", "current": True}

    position_schema = load_schema(
        "authors")["properties"]["positions"]["items"]
    assert validate(dump, position_schema) is None

    expected = {
        "institution": "CERN",
        "current": True,
        "display_date": "present"
    }

    result = schema.dumps(dump).data

    assert expected == orjson.loads(result)
Esempio n. 4
0
def test_returns_display_date_rank_institution_and_current():
    schema = PositionSchemaV1()
    dump = {
        "institution": "CERN",
        "current": False,
        "end_date": "2000",
        "rank": "PHD"
    }

    position_schema = load_schema(
        "authors")["properties"]["positions"]["items"]
    assert validate(dump, position_schema) is None

    expected = {
        "institution": "CERN",
        "display_date": "2000",
        "rank": "PHD",
        "current": False,
    }

    result = schema.dumps(dump).data

    assert expected == orjson.loads(result)