aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests/api_releases.py
blob: 73ce375706d0d909dd2962d473d09d71a454e084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

import json
import pytest
import datetime
from copy import copy

from fatcat_client import *
from fatcat_client.rest import ApiException
from fixtures import *


def test_release(api):

    eg = quick_eg(api)

    # all the fields!
    r1 = ReleaseEntity(
        title="some title",
        original_title="оригинальное название",
        release_type="post-weblog",
        release_status="submitted",
        release_date=datetime.datetime.utcnow().date(),
        release_year=2015,
        doi="10.5555/12345678",
        pmid="12345",
        pmcid="PMC4321",
        wikidata_qid="Q1234",
        isbn13="978-3-16-148410-0",
        core_id="187348",
        arxiv_id="aslkdjfh",
        jstor_id="8328424",
        volume="84",
        issue="XII",
        pages="4-99",
        publisher="some publisher",
        language="en",
        license_slug="CC-0",
        extra=dict(a=1, b=2),
        contribs=[],
        refs=[],
        abstracts=[
            ReleaseEntityAbstracts(
                content="this is some abstract",
                mimetype="text/plain",
                lang="en"),
            ReleaseEntityAbstracts(
                content="this is some other abstract",
                mimetype="text/plain",
                lang="de"),
        ],
    )

    r1edit = api.create_release(r1, editgroup_id=eg.editgroup_id)
    api.accept_editgroup(eg.editgroup_id)
    r2 = api.get_release(r1edit.ident)

    # get revision
    r2_rev = api.get_release_revision(r1edit.revision)
    assert r1edit.revision == r2_rev.revision
    assert r2.revision == r2_rev.revision
    assert r2.title == r2_rev.title

    # check that fields match
    assert r1.title == r2.title
    assert r1.original_title == r2.original_title
    assert r1.release_type == r2.release_type
    assert r1.release_date == r2.release_date
    assert r1.release_year == r2.release_year
    assert r1.doi == r2.doi
    assert r1.pmid == r2.pmid
    assert r1.pmcid == r2.pmcid
    assert r1.wikidata_qid == r2.wikidata_qid
    assert r1.isbn13 == r2.isbn13
    assert r1.core_id == r2.core_id
    assert r1.arxiv_id == r2.arxiv_id
    assert r1.jstor_id == r2.jstor_id
    assert r1.volume == r2.volume
    assert r1.issue == r2.issue
    assert r1.pages == r2.pages
    assert r1.publisher == r2.publisher
    assert r1.language == r2.language
    assert r1.license_slug == r2.license_slug
    assert r1.extra == r2.extra

    for i in range(len(r1.abstracts)):
        r1.abstracts[i].content == r2.abstracts[i].content
        r1.abstracts[i].mimetype == r2.abstracts[i].mimetype
        r1.abstracts[i].lang == r2.abstracts[i].lang
    for i in range(len(r1.contribs)):
        r1.contribs[i] == r2.contribs[i]
    for i in range(len(r1.refs)):
        r1.refs[i] == r2.refs[i]

    # expansion
    # TODO: via work
    # lookup
    # TODO: via all; but need to generate random identifiers

    # get redirects (none)
    assert api.get_release_redirects(r2.ident) == []
    
    # delete
    eg = quick_eg(api)
    api.delete_release(r2.ident, editgroup_id=eg.editgroup_id)
    api.accept_editgroup(eg.editgroup_id)
    r2 = api.get_release(r2.ident)
    assert r2.state == "deleted"

def test_release_examples(api):

    api.lookup_release(pmid='54321')
    api.lookup_release(isbn13='978-3-16-148410-0')

    r1 = api.get_release('aaaaaaaaaaaaarceaaaaaaaaai')
    assert r1.title.startswith("A bigger example")
    assert len(r1.refs) == 5
    assert r1.contribs[14].role == "editor"
    assert r1.abstracts[0].mimetype == "application/xml+jats"

    api.get_release_files(r1.ident)
    api.get_release_filesets(r1.ident)
    api.get_release_webcaptures(r1.ident)

def test_empty_fields(api):

    eg = quick_eg(api)

    r1 = ReleaseEntity(title="something", contribs=[ReleaseContrib(raw_name="somebody")])
    r1edit = api.create_release(r1, editgroup_id=eg.editgroup_id)

    with pytest.raises(fatcat_client.rest.ApiException):
        r2 = ReleaseEntity(title="")
        api.create_release(r2, editgroup_id=eg.editgroup_id)
    with pytest.raises(fatcat_client.rest.ApiException):
        r2 = ReleaseEntity(title="something", contribs=[ReleaseContrib(raw_name="")])
        api.create_release(r2, editgroup_id=eg.editgroup_id)

def test_controlled_vocab(api):

    eg = quick_eg(api)

    r1 = ReleaseEntity(title="something", release_type="journal-thingie")
    with pytest.raises(fatcat_client.rest.ApiException):
        api.create_release(r1, editgroup_id=eg.editgroup_id)
    r1.release_type = "article"
    api.create_release(r1, editgroup_id=eg.editgroup_id)

    r2 = ReleaseEntity(title="something elase", release_status="pre-print")
    with pytest.raises(fatcat_client.rest.ApiException):
        api.create_release(r2, editgroup_id=eg.editgroup_id)
    r2.release_status = "published"
    api.create_release(r2, editgroup_id=eg.editgroup_id)