summaryrefslogtreecommitdiffstats
path: root/python/tests/transform_toml.py
blob: 56bf32a1476aab1de8e88b129b268446a03e6842 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import json

from fatcat_openapi_client import ReleaseEntity
from fixtures import api
from import_crossref import crossref_importer

from fatcat_tools.transforms import entity_from_toml, entity_to_toml


def test_basic_toml(crossref_importer):
    with open("tests/files/crossref-works.single.json", "r") as f:
        # not a single line
        raw = json.loads(f.read())
        r = crossref_importer.parse_record(raw)
    r.state = "active"
    toml_str = entity_to_toml(r)
    r2 = entity_from_toml(toml_str, ReleaseEntity)
    assert r == r2

    toml_str = entity_to_toml(r, pop_fields=["ident", "revision", "blah", "extra"])
    r3 = entity_from_toml(toml_str, ReleaseEntity)
    assert r != r3