aboutsummaryrefslogtreecommitdiffstats
path: root/rust/tests/test_old_python_tests.rs
blob: 0676a60424b10ef4083dd9e11fa8ff80b762edd8 (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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
 * This file contains some old python tests that have been ported to Rust. The exersize the "edit
 * lifecycle" as well as creation of a "rich" release entity (linked to all other entity types) in
 * a single editgroup.
 */

use fatcat_api_spec::models::*;
use fatcat_api_spec::*;

mod helpers;

// Disabled due to hang
//#[test]
#[allow(dead_code)]
fn test_api_rich_create() {
    let (client, context, mut server) = helpers::setup_client();
    let client = client.with_context(context);

    let admin_id = "aaaaaaaaaaaabkvkaaaaaaaaae".to_string();

    let mut new_eg = Editgroup::new();
    new_eg.editor_id = Some(admin_id);
    new_eg.description = Some("a unit test edit".to_string());
    let resp = client.create_editgroup(new_eg).wait().unwrap();
    let editgroup_id = match resp {
        CreateEditgroupResponse::SuccessfullyCreated(eg) => eg.editgroup_id.unwrap(),
        _ => unreachable!(),
    };

    let mut new_container = ContainerEntity::new();
    new_container.name = Some("schmournal".to_string());
    new_container.publisher = Some("society of authors".to_string());
    new_container.issnl = Some("2222-3333".to_string());
    // extra=dict(a=2, i="zing"))),
    let resp = client
        .create_container(new_container, Some(editgroup_id.clone()))
        .wait()
        .unwrap();
    let container_id = match resp {
        CreateContainerResponse::CreatedEntity(ee) => ee.ident,
        _ => unreachable!(),
    };

    let mut new_creator = CreatorEntity::new();
    new_creator.display_name = Some("anon y. mouse".to_string());
    new_creator.orcid = Some("0000-0002-1825-0097".to_string());
    // extra=dict(a=2, i="zing"))),
    let resp = client
        .create_creator(new_creator, Some(editgroup_id.clone()))
        .wait()
        .unwrap();
    let creator_id = match resp {
        CreateCreatorResponse::CreatedEntity(ee) => ee.ident,
        _ => unreachable!(),
    };

    let new_work = WorkEntity::new();
    // extra=dict(a=2, i="zing"))),
    let resp = client
        .create_work(new_work, Some(editgroup_id.clone()))
        .wait()
        .unwrap();
    let work_id = match resp {
        CreateWorkResponse::CreatedEntity(ee) => ee.ident,
        _ => unreachable!(),
    };

    // this stub work will be referenced
    let mut new_release = ReleaseEntity::new();
    new_release.title = Some("derivative work".to_string());
    new_release.release_type = Some("article-journal".to_string());
    new_release.work_id = Some(work_id.clone());
    let mut contrib = ReleaseContrib::new();
    contrib.creator_id = Some(creator_id.clone());
    new_release.contribs = Some(vec![contrib]);
    new_release.doi = Some("10.1234/58".to_string());
    let mut rref = ReleaseRef::new();
    rref.title = Some("some other work".to_string());
    new_release.refs = Some(vec![rref]);
    // extra=dict(a=2, i="zing"))),
    let resp = client
        .create_release(new_release, Some(editgroup_id.clone()))
        .wait()
        .unwrap();
    let stub_release_id = match resp {
        CreateReleaseResponse::CreatedEntity(ee) => ee.ident,
        _ => unreachable!(),
    };

    let mut new_release = ReleaseEntity::new();
    new_release.title = Some("dummy work".to_string());
    new_release.release_type = Some("book".to_string());
    new_release.work_id = Some(work_id.clone());
    new_release.container_id = Some(container_id.clone());
    let mut contrib = ReleaseContrib::new();
    contrib.creator_id = Some(creator_id.clone());
    new_release.contribs = Some(vec![contrib]);
    new_release.doi = Some("10.1234/5678".to_string());
    let mut rref = ReleaseRef::new();
    rref.title = Some("some paper".to_string());
    rref.target_release_id = Some(stub_release_id.clone());
    new_release.refs = Some(vec![rref]);
    // extra=dict(f=7, b="loopy"))),
    let resp = client
        .create_release(new_release, Some(editgroup_id.clone()))
        .wait()
        .unwrap();
    let release_id = match resp {
        CreateReleaseResponse::CreatedEntity(ee) => ee.ident,
        _ => unreachable!(),
    };

    let mut new_file = FileEntity::new();
    new_file.sha1 = Some("7d97e98f8af710c7e7fe703abc8f639e0ee507c4".to_string());
    new_file.size = Some(1234);
    new_file.release_ids = Some(vec![release_id.clone()]);
    // extra=dict(f=4, b="zing"))),
    let resp = client
        .create_file(new_file, Some(editgroup_id.clone()))
        .wait()
        .unwrap();
    let file_id = match resp {
        CreateFileResponse::CreatedEntity(ee) => ee.ident,
        _ => {
            println!("{:?}", resp);
            unreachable!()
        }
    };

    let resp = client.get_changelog(Some(1)).wait().unwrap();
    let last_change_id = match resp {
        GetChangelogResponse::Success(list) => list[0].index,
        _ => unreachable!(),
    };

    match client
        .accept_editgroup(editgroup_id.clone())
        .wait()
        .unwrap()
    {
        AcceptEditgroupResponse::MergedSuccessfully(_) => (),
        _ => unreachable!(),
    };

    let resp = client.get_changelog(Some(1)).wait().unwrap();
    match resp {
        GetChangelogResponse::Success(list) => assert_eq!(list[0].index, last_change_id + 1),
        _ => unreachable!(),
    };

    // test that foreign key relations worked
    let re = match client
        .get_release(release_id.clone(), None, None)
        .wait()
        .unwrap()
    {
        GetReleaseResponse::FoundEntity(e) => e,
        _ => unreachable!(),
    };
    assert_eq!(
        re.contribs.clone().unwrap()[0].clone().creator_id.unwrap(),
        creator_id
    );
    assert_eq!(re.work_id.unwrap(), work_id);
    assert_eq!(
        re.contribs.unwrap()[0].clone().creator_id.unwrap(),
        creator_id
    );
    assert_eq!(
        re.refs.unwrap()[0].clone().target_release_id.unwrap(),
        stub_release_id
    );

    let fe = match client.get_file(file_id, None, None).wait().unwrap() {
        GetFileResponse::FoundEntity(e) => e,
        _ => unreachable!(),
    };
    assert_eq!(fe.release_ids.unwrap()[0], release_id.clone());

    // had a test for active_editgroup here, but that's soon-to-be-deprecated

    server.close().unwrap()
}

/* Disabled because test framework/fixture is broken in Gitlab CI (getting a port error), not
 * because of any problem with this particular test... though this test isn't doing much right now
 * anyways.
 */
//#[test]
#[allow(dead_code)]
fn test_merge_works() {
    let (client, context, mut server) = helpers::setup_client();
    let client = client.with_context(context);

    let admin_id = "aaaaaaaaaaaabkvkaaaaaaaaae".to_string();

    let mut eg = Editgroup::new();
    eg.editor_id = Some(admin_id);
    let resp = client.create_editgroup(eg).wait().unwrap();
    let editgroup_id = match resp {
        CreateEditgroupResponse::SuccessfullyCreated(eg) => eg.editgroup_id.unwrap(),
        _ => unreachable!(),
    };

    // Create 2x works, each with releases; work_b has two releases

    let resp = client
        .create_work(WorkEntity::new(), Some(editgroup_id.clone()))
        .wait()
        .unwrap();
    let work_a_id = match resp {
        CreateWorkResponse::CreatedEntity(ee) => ee.ident,
        _ => unreachable!(),
    };
    let mut new_release = ReleaseEntity::new();
    new_release.title = Some("some release".to_string());
    new_release.release_type = Some("article-journal".to_string());
    new_release.work_id = Some(work_a_id.clone());
    new_release.doi = Some("10.1234/A1".to_string());
    let resp = client
        .create_release(new_release, Some(editgroup_id.clone()))
        .wait()
        .unwrap();
    let _release_a1_id = match resp {
        CreateReleaseResponse::CreatedEntity(ee) => ee.ident,
        _ => unreachable!(),
    };

    let resp = client
        .create_work(WorkEntity::new(), Some(editgroup_id.clone()))
        .wait()
        .unwrap();
    let work_b_id = match resp {
        CreateWorkResponse::CreatedEntity(ee) => ee.ident,
        _ => unreachable!(),
    };

    let mut new_release = ReleaseEntity::new();
    new_release.title = Some("some release".to_string());
    new_release.release_type = Some("article-journal".to_string());
    new_release.work_id = Some(work_b_id.clone());
    new_release.doi = Some("10.1234/B1".to_string());
    let resp = client
        .create_release(new_release, Some(editgroup_id.clone()))
        .wait()
        .unwrap();
    let _release_b1_id = match resp {
        CreateReleaseResponse::CreatedEntity(ee) => ee.ident,
        _ => unreachable!(),
    };

    let mut new_release = ReleaseEntity::new();
    new_release.title = Some("some release".to_string());
    new_release.release_type = Some("article-journal".to_string());
    new_release.work_id = Some(work_b_id.clone());
    new_release.doi = Some("10.1234/B2".to_string());
    let resp = client
        .create_release(new_release, Some(editgroup_id.clone()))
        .wait()
        .unwrap();
    let _release_b2_id = match resp {
        CreateReleaseResponse::CreatedEntity(ee) => ee.ident,
        _ => unreachable!(),
    };

    match client
        .accept_editgroup(editgroup_id.clone())
        .wait()
        .unwrap()
    {
        AcceptEditgroupResponse::MergedSuccessfully(_) => (),
        _ => unreachable!(),
    };

    /* TODO:
    // merge works
    client.merge_works(work_a_id, work_b_id)
    */
    // check results
    let work_a = match client
        .get_work(work_a_id.clone(), None, None)
        .wait()
        .unwrap()
    {
        GetWorkResponse::FoundEntity(e) => e,
        _ => unreachable!(),
    };
    let _work_b = match client
        .get_work(work_b_id.clone(), None, None)
        .wait()
        .unwrap()
    {
        GetWorkResponse::FoundEntity(e) => e,
        _ => unreachable!(),
    };
    // TODO: assert_eq!(work_a.revision.unwrap(), work_b.revision.unwrap());
    assert_eq!(work_a.redirect, None);
    // TODO: assert_eq!(work_b.redirect, Some(work_a_id));

    server.close().unwrap()
}