aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests/import_journal_metadata.py
blob: ff9dcb7a2e81b3da6260fbd154ee3b07992dfd38 (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
import pytest
from fixtures import *

from fatcat_tools.importers import JournalMetadataImporter, JsonLinePusher


@pytest.fixture(scope="function")
def journal_metadata_importer(api):
    yield JournalMetadataImporter(api)


# TODO: use API to check that entities actually created...
def test_journal_metadata_importer_batch(journal_metadata_importer):
    with open("tests/files/journal_metadata.sample.json", "r") as f:
        JsonLinePusher(journal_metadata_importer, f).run()


def test_journal_metadata_importer(journal_metadata_importer):
    last_index = journal_metadata_importer.api.get_changelog(limit=1)[0].index
    with open("tests/files/journal_metadata.sample.json", "r") as f:
        journal_metadata_importer.bezerk_mode = True
        counts = JsonLinePusher(journal_metadata_importer, f).run()
    assert counts["insert"] == 20
    assert counts["exists"] == 0
    assert counts["skip"] == 0

    # fetch most recent editgroup
    change = journal_metadata_importer.api.get_changelog_entry(index=last_index + 1)
    eg = change.editgroup
    assert eg.description
    assert "container" in eg.description.lower()
    assert eg.extra["git_rev"]
    assert "fatcat_tools.JournalMetadataImporter" in eg.extra["agent"]

    with open("tests/files/journal_metadata.sample.json", "r") as f:
        journal_metadata_importer.reset()
        journal_metadata_importer.bezerk_mode = False
        counts = JsonLinePusher(journal_metadata_importer, f).run()
    assert counts["insert"] == 0
    assert counts["exists"] == 20
    assert counts["skip"] == 0