summaryrefslogtreecommitdiffstats
path: root/python/tests/api_editgroups.py
blob: d82c9233b2b711dcde3e867c966340ce44613dd0 (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

import json
import pytest
import datetime
from copy import copy

from fatcat_openapi_client import *
from fatcat_openapi_client.rest import ApiException
from fixtures import *


def test_editgroup_submit(api):
    # 1. check that edit group can be submitted/unsubmitted, and shows up in reviewable appropriately
    # 2. accepted edits don't show up as reviewable and can't be submitted

    c1 = CreatorEntity(display_name="test updates")
    eg = quick_eg(api)
    c1 = api.get_creator(api.create_creator(eg.editgroup_id, c1).ident)

    eg2 = api.get_editgroup(eg.editgroup_id)
    assert not eg2.submitted
    assert not eg2.changelog_index

    reviewable = api.get_editgroups_reviewable(limit=100)
    assert eg.editgroup_id not in [v.editgroup_id for v in reviewable]
    wip = api.get_editor_editgroups(eg.editor_id, limit=100)
    assert eg.editgroup_id in [v.editgroup_id for v in wip]

    api.update_editgroup(eg.editgroup_id, eg2, submit=True)
    eg3 = api.get_editgroup(eg.editgroup_id)
    assert eg3.submitted
    reviewable = api.get_editgroups_reviewable(limit=100)
    assert eg.editgroup_id in [v.editgroup_id for v in reviewable]

    api.update_editgroup(eg.editgroup_id, eg2, submit=False)
    eg3 = api.get_editgroup(eg.editgroup_id)
    assert not eg3.submitted
    reviewable = api.get_editgroups_reviewable(limit=100)
    assert eg.editgroup_id not in [v.editgroup_id for v in reviewable]

    # put back in reviewable
    api.update_editgroup(eg.editgroup_id, eg2, submit=True)
    reviewable = api.get_editgroups_reviewable(limit=100)
    assert eg.editgroup_id in [v.editgroup_id for v in reviewable]

    # shouldn't be reviewable if accepted
    api.accept_editgroup(eg.editgroup_id)
    reviewable = api.get_editgroups_reviewable(limit=100)
    assert eg.editgroup_id not in [v.editgroup_id for v in reviewable]
    eg3 = api.get_editgroup(eg.editgroup_id)
    #print(eg3)
    assert eg3.submitted
    assert eg3.changelog_index

    with pytest.raises(fatcat_openapi_client.rest.ApiException):
        api.update_editgroup(eg.editgroup_id, eg3, submit=True)
    with pytest.raises(fatcat_openapi_client.rest.ApiException):
        eg3.description = "something"
        api.update_editgroup(eg.editgroup_id, eg3)


def test_editgroup_ordering(api):

    eg1 = quick_eg(api)
    eg2 = quick_eg(api)
    api.update_editgroup(
        eg1.editgroup_id,
        Editgroup(editgroup_id=eg1.editgroup_id, description="FAIL"),
        submit=True)
    api.update_editgroup(
        eg2.editgroup_id,
        Editgroup(editgroup_id=eg2.editgroup_id, description="FAIL"),
        submit=True)

    r1 = api.get_editgroups_reviewable()
    #print(r1)
    assert not r1[0].description
    assert not r1[1].description
    assert r1[0].submitted >= r1[1].submitted

    # should be no editgroups "in the future" (since now + 1sec)
    r1 = api.get_editgroups_reviewable(since=(datetime.datetime.utcnow() + datetime.timedelta(seconds=1)).isoformat()+"Z")
    assert not r1

    r1 = api.get_editgroups_reviewable(since=(datetime.datetime.utcnow() - datetime.timedelta(seconds=5)).isoformat()+"Z")
    assert r1[0].submitted <= r1[1].submitted


def test_editgroup_auto_batch(api):

    c1 = CreatorEntity(display_name="test auto_batch")
    c2 = CreatorEntity(display_name="test another auto_batch")

    eg1 = api.create_creator_auto_batch(CreatorAutoBatch(
        editgroup=Editgroup(),
        entity_list=[c1, c2]))

    assert eg1.changelog_index
    assert len(eg1.edits.creators) == 2


def test_batch_params(api):

    eg = quick_eg(api)
    c1 = CreatorEntity(display_name="test auto_batch")
    c2 = CreatorEntity(display_name="test another auto_batch")

    desc = "test description"
    extra = dict(a=75, q="thing")
    eg1 = api.create_creator_auto_batch(CreatorAutoBatch(
        editgroup=Editgroup(
            description=desc,
            extra=extra),
        entity_list=[c1, c2]))

    assert eg1.description == desc
    assert eg1.extra == extra