aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests/merge_containers.py
blob: a657522ec37be22d5008eab1781239dd0e659e2f (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
from fatcat_openapi_client import ContainerEntity
from fixtures import api

from fatcat_tools.mergers.containers import ContainerMerger


def test_choose_primary_container(api) -> None:

    release_counts = dict()
    redirects = dict()
    em = ContainerMerger(api=api)

    ce_stub = ContainerEntity(
        ident="pppppp5apzfhbbxxc7rgu2yw6m",
        name="dummy journal",
    )
    release_counts[ce_stub.ident] = 0
    redirects[ce_stub.ident] = []

    ce_partial = ContainerEntity(
        ident="eeeeeeeapzfhbbxxc7rgu2yw6m",
        name="dummy complete journal",
        publisher="some publisher",
        issnl="1234-5678",
        publication_status="active",
        extra=dict(asdf=123, ia=dict(asdf=True)),
    )
    release_counts[ce_partial.ident] = 0
    redirects[ce_partial.ident] = []

    ce_partial_redirects = ContainerEntity(
        ident="rrrrrrrrrrfhbbxxc7rgu2yw6m",
        name="dummy complete journal",
        publisher="some publisher",
        issnl="1234-5678",
        publication_status="active",
        extra=dict(asdf=123, ia=dict(asdf=True)),
    )
    release_counts[ce_partial_redirects.ident] = 0
    redirects[ce_partial_redirects.ident] = [
        "zzzzzzzzrrfhbbxxc7rgu2yw6m",
    ]

    ce_complete_zero = ContainerEntity(
        ident="oooooooapzfhbbxxc7rgu2yw6m",
        name="dummy complete journal",
        publisher="some publisher",
        issnl="1234-5678",
        publication_status="active",
        extra=dict(asdf=123, ia=dict(asdf=True)),
    )
    release_counts[ce_complete_zero.ident] = 0
    redirects[ce_complete_zero.ident] = []

    ce_complete_small = ContainerEntity(
        ident="cccccccapzfhbbxxc7rgu2yw6m",
        name="dummy complete journal",
        publisher="some publisher",
        issnl="1234-5678",
        publication_status="active",
        extra=dict(asdf=123, ia=dict(asdf=True)),
    )
    release_counts[ce_complete_small.ident] = 10
    redirects[ce_complete_small.ident] = []

    ce_complete_big = ContainerEntity(
        ident="ddddddddpzfhbbxxc7rgu2yw6m",
        name="dummy complete journal",
        publisher="some publisher",
        issnl="1234-5678",
        publication_status="active",
        extra=dict(asdf=123, ia=dict(asdf=True)),
    )
    release_counts[ce_complete_big.ident] = 9999999
    redirects[ce_complete_big.ident] = []

    assert (
        em.choose_primary_container([ce_stub, ce_partial], redirects, release_counts)
        == ce_partial.ident
    )
    assert (
        em.choose_primary_container(
            [ce_stub, ce_complete_zero, ce_partial], redirects, release_counts
        )
        == ce_complete_zero.ident
    )
    assert (
        em.choose_primary_container(
            [ce_stub, ce_partial_redirects, ce_complete_zero, ce_partial],
            redirects,
            release_counts,
        )
        == ce_partial_redirects.ident
    )
    assert (
        em.choose_primary_container(
            [ce_stub, ce_complete_zero, ce_complete_small, ce_partial],
            redirects,
            release_counts,
        )
        == ce_complete_small.ident
    )
    assert (
        em.choose_primary_container(
            [ce_stub, ce_complete_big, ce_complete_zero, ce_complete_small, ce_partial],
            redirects,
            release_counts,
        )
        == ce_complete_big.ident
    )
    assert (
        em.choose_primary_container(
            [ce_complete_small, ce_complete_big], redirects, release_counts
        )
        == ce_complete_big.ident
    )