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
|
/*
* 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.
*/
extern crate fatcat;
extern crate fatcat_api_spec;
extern crate uuid;
extern crate iron;
use fatcat_api_spec::*;
use fatcat_api_spec::models::*;
mod helpers;
use helpers::{setup_client};
#[test]
fn test_api_rich_create() {
let (client, mut server) = setup_client();
let client = client.with_context(Context::new());
let admin_id = "aaaaaaaaaaaabkvkaaaaaaaaae".to_string();
let mut new_eg = Editgroup::new(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.id.unwrap(),
_ => unreachable!()
};
let mut new_container = ContainerEntity::new("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("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("derivative work".to_string());
new_release.release_type = Some("journal-article".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("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.releases = 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).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).wait().unwrap() {
GetFileResponse::FoundEntity(e) => e,
_ => unreachable!()
};
assert_eq!(fe.releases.unwrap()[0], release_id.clone());
// had a test for active_editgroup here, but that's soon-to-be-deprecated
server.close().unwrap()
}
|