aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests/web_editing.py
blob: fb8b3f936b8786a726be1f7b7780d8dff2e04ea2 (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259

from fixtures import *


def test_web_release_create_accept(app_admin, api):

    eg = quick_eg(api)

    rv = app_admin.get('/editgroup/{}'.format(eg.editgroup_id))
    assert rv.status_code == 200
    assert b'Release Edits (0)' in rv.data

    # bogus/bad submit
    rv = app_admin.post('/release/create',
        data={
            'editgroup_id': eg.editgroup_id,
            'release_type': 'badmojo',
            'release_stage': 'published',
            'title': 'something bogus',
        },
        follow_redirects=True)
    assert rv.status_code == 400
    # Does not insert bad choices into drop-down
    #assert b'badmojo' in rv.data
    assert b'Not a valid choice' in rv.data

    # bad wikidata QID
    rv = app_admin.post('/release/create',
        data={
            'editgroup_id': eg.editgroup_id,
            'release_type': 'article-journal',
            'release_stage': 'published',
            'title': 'something bogus',
            'wikidata_qid': '884',
        },
        follow_redirects=True)
    assert rv.status_code == 400

    # ok/valid submit
    rv = app_admin.post('/release/create',
        data={
            'editgroup_id': eg.editgroup_id,
            'release_type': 'article-journal',
            'release_stage': 'published',
            'title': 'something bogus',
            'doi': '10.1234/999999',
        },
        follow_redirects=True)
    assert rv.status_code == 200
    assert b'10.1234/999999' in rv.data

    rv = app_admin.get('/editgroup/{}'.format(eg.editgroup_id))
    assert rv.status_code == 200
    assert b'Release Edits (1)' in rv.data

    rv = app_admin.post('/editgroup/{}/submit'.format(eg.editgroup_id),
        follow_redirects=True,
    )
    assert rv.status_code == 200
    rv = app_admin.get('/editgroup/{}'.format(eg.editgroup_id))
    assert rv.status_code == 200
    assert b'Submitted' in rv.data
    assert b'None!' in rv.data

    rv = app_admin.post('/editgroup/{}/unsubmit'.format(eg.editgroup_id),
        follow_redirects=True,
    )
    assert rv.status_code == 200
    rv = app_admin.get('/editgroup/{}'.format(eg.editgroup_id))
    assert rv.status_code == 200

    rv = app_admin.post('/editgroup/{}/annotation'.format(eg.editgroup_id),
        data={
            'comment_markdown': "This is an **example** of markdown in a test annotation",
        },
        follow_redirects=True,
    )
    assert rv.status_code == 200
    rv = app_admin.get('/editgroup/{}'.format(eg.editgroup_id))
    assert rv.status_code == 200
    assert b'<p>This is an <strong>example</strong> of markdown in a test annotation' in rv.data

    rv = app_admin.post('/editgroup/{}/accept'.format(eg.editgroup_id),
        follow_redirects=True,
    )
    assert rv.status_code == 200
    rv = app_admin.get('/editgroup/{}'.format(eg.editgroup_id))
    assert rv.status_code == 200
    assert b'Merged' in rv.data


def test_web_container_create(app_admin, api):

    eg = quick_eg(api)

    # bogus/bad submit
    rv = app_admin.post('/container/create',
        data={
            'editgroup_id': eg.editgroup_id,
        },
        follow_redirects=True)
    assert rv.status_code == 400

    # ok/valid submit
    rv = app_admin.post('/container/create',
        data={
            'editgroup_id': eg.editgroup_id,
            'name': 'blah blah journal blah',
        },
        follow_redirects=True)
    assert rv.status_code == 200


def test_web_file_create(app_admin, api):

    eg = quick_eg(api)

    # bogus/bad submit
    rv = app_admin.post('/file/create',
        data={
            'editgroup_id': eg.editgroup_id,
        },
        follow_redirects=True)
    assert rv.status_code == 400

    # ok/valid submit
    rv = app_admin.post('/file/create',
        data={
            'editgroup_id': eg.editgroup_id,
            'size': '12345',
            'sha1': '45be56a396c4d03faaa41e055170c23534dec736',
        },
        follow_redirects=True)
    assert rv.status_code == 200

    # upper-case SHA-1
    rv = app_admin.post('/file/create',
        data={
            'editgroup_id': eg.editgroup_id,
            'size': '12345',
            'sha1': '45BE56A396C4D03FAAA41E055170C23534DEC736',
        },
        follow_redirects=True)
    assert rv.status_code == 200

def test_web_file_toml_create(app_admin, api):

    eg = quick_eg(api)

    # bogus/bad submit
    rv = app_admin.post('/file/create/toml',
        data={
            'editgroup_id': eg.editgroup_id,
        },
        follow_redirects=True)
    assert rv.status_code == 400

    # ok/valid submit
    rv = app_admin.post('/file/create/toml',
        data={
            'editgroup_id': eg.editgroup_id,
            'toml': """
size = 12345
sha1 = "45be56a396c4d03faaa41e055170c23534dec736"
            """,
        },
        follow_redirects=True)
    assert rv.status_code == 200

    # upper-case SHA-1
    rv = app_admin.post('/file/create/toml',
        data={
            'editgroup_id': eg.editgroup_id,
            'toml': """
size = 12345
sha1 = "45BE56A396C4D03FAAA41E055170C23534DEC736"
            """,
        },
        follow_redirects=True)
    assert rv.status_code == 400

def test_web_file_delete(app_admin, api):

    eg = quick_eg(api)

    rv = app_admin.get('/file/aaaaaaaaaaaaamztaaaaaaaaam/delete')
    assert rv.status_code == 200

    rv = app_admin.post('/file/aaaaaaaaaaaaamztaaaaaaaaam/delete',
        data={
            'editgroup_id': eg.editgroup_id,
        },
        follow_redirects=True)
    assert rv.status_code == 200
    # NOTE: did not *accept* the deletion edit

DUMMY_DEMO_ENTITIES = {
    'container': 'aaaaaaaaaaaaaeiraaaaaaaaam',
    'creator': 'aaaaaaaaaaaaaircaaaaaaaaaq',
    'file': 'aaaaaaaaaaaaamztaaaaaaaaam',
    'fileset': 'aaaaaaaaaaaaaztgaaaaaaaaai',
    'webcapture': 'aaaaaaaaaaaaa53xaaaaaaaaai',
    'release': 'aaaaaaaaaaaaarceaaaaaaaaai',
    'work': 'aaaaaaaaaaaaavkvaaaaaaaaai',
}

def test_web_edit_get(app_admin):

    # these are all existing entities
    for entity_type in ['release', 'file', 'container']:
        rv = app_admin.get(f'/{entity_type}/{DUMMY_DEMO_ENTITIES[entity_type]}/edit')
        assert rv.status_code == 200
        if entity_type == 'release':
            assert b'A bigger example' in rv.data
        elif entity_type == 'file':
            assert b'ffc1005680cb620eec4c913437dfabbf311b535cfe16cbaeb2faec1f92afc362' in rv.data
        elif entity_type == 'container':
            assert b'1549-1277' in rv.data

        rv = app_admin.get(f'/{entity_type}/{DUMMY_DEMO_ENTITIES[entity_type]}/edit/toml')
        assert rv.status_code == 200
        if entity_type == 'release':
            assert b'A bigger example' in rv.data
        elif entity_type == 'file':
            assert b'ffc1005680cb620eec4c913437dfabbf311b535cfe16cbaeb2faec1f92afc362' in rv.data
        elif entity_type == 'container':
            assert b'1549-1277' in rv.data

    # TOML-only endpoints
    for entity_type in ['creator', 'fileset', 'webcapture', 'work']:
        rv = app_admin.get(f'/{entity_type}/{DUMMY_DEMO_ENTITIES[entity_type]}/edit')
        assert rv.status_code == 302

        rv = app_admin.get(f'/{entity_type}/{DUMMY_DEMO_ENTITIES[entity_type]}/edit/toml')
        assert rv.status_code == 200


def test_web_create_get(app_admin):

    for entity_type in ['release', 'file', 'container']:
        rv = app_admin.get(f'/{entity_type}/create')
        assert rv.status_code == 200

        rv = app_admin.get(f'/{entity_type}/create/toml')
        assert rv.status_code == 200

    # these are TOML only
    for entity_type in ['creator', 'fileset', 'webcapture', 'work']:
        rv = app_admin.get(f'/{entity_type}/create')
        assert rv.status_code == 302

        rv = app_admin.get(f'/{entity_type}/create/toml')
        assert rv.status_code == 200

def test_web_edit_delete(app_admin):

    for entity_type in DUMMY_DEMO_ENTITIES.keys():
        rv = app_admin.get(f'/{entity_type}/{DUMMY_DEMO_ENTITIES[entity_type]}/delete')
        assert rv.status_code == 200