diff options
Diffstat (limited to 'rust/tests/test_old_python_tests.rs')
-rw-r--r-- | rust/tests/test_old_python_tests.rs | 141 |
1 files changed, 96 insertions, 45 deletions
diff --git a/rust/tests/test_old_python_tests.rs b/rust/tests/test_old_python_tests.rs index 91a5a655..6f212e71 100644 --- a/rust/tests/test_old_python_tests.rs +++ b/rust/tests/test_old_python_tests.rs @@ -6,18 +6,17 @@ extern crate fatcat; extern crate fatcat_api_spec; -extern crate uuid; extern crate iron; +extern crate uuid; -use fatcat_api_spec::*; use fatcat_api_spec::models::*; +use fatcat_api_spec::*; mod helpers; -use helpers::{setup_client}; +use helpers::setup_client; #[test] fn test_api_rich_create() { - let (client, mut server) = setup_client(); let client = client.with_context(Context::new()); @@ -28,34 +27,43 @@ fn test_api_rich_create() { let resp = client.create_editgroup(new_eg).wait().unwrap(); let editgroup_id = match resp { CreateEditgroupResponse::SuccessfullyCreated(eg) => eg.id.unwrap(), - _ => unreachable!() + _ => 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 resp = client + .create_container(new_container, Some(editgroup_id.clone())) + .wait() + .unwrap(); let container_id = match resp { CreateContainerResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => 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 resp = client + .create_creator(new_creator, Some(editgroup_id.clone())) + .wait() + .unwrap(); let creator_id = match resp { CreateCreatorResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => 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 resp = client + .create_work(new_work, Some(editgroup_id.clone())) + .wait() + .unwrap(); let work_id = match resp { CreateWorkResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; // this stub work will be referenced @@ -70,10 +78,13 @@ fn test_api_rich_create() { 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 resp = client + .create_release(new_release, Some(editgroup_id.clone())) + .wait() + .unwrap(); let stub_release_id = match resp { CreateReleaseResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; let mut new_release = ReleaseEntity::new("dummy work".to_string()); @@ -89,10 +100,13 @@ fn test_api_rich_create() { 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 resp = client + .create_release(new_release, Some(editgroup_id.clone())) + .wait() + .unwrap(); let release_id = match resp { CreateReleaseResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; let mut new_file = FileEntity::new(); @@ -100,7 +114,10 @@ fn test_api_rich_create() { 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 resp = client + .create_file(new_file, Some(editgroup_id.clone())) + .wait() + .unwrap(); let file_id = match resp { CreateFileResponse::CreatedEntity(ee) => ee.ident, _ => { @@ -112,104 +129,138 @@ fn test_api_rich_create() { let resp = client.get_changelog(Some(1)).wait().unwrap(); let last_change_id = match resp { GetChangelogResponse::Success(list) => list[0].index, - _ => unreachable!() + _ => unreachable!(), }; - match client.accept_editgroup(editgroup_id.clone()).wait().unwrap() { + match client + .accept_editgroup(editgroup_id.clone()) + .wait() + .unwrap() + { AcceptEditgroupResponse::MergedSuccessfully(_) => (), - _ => unreachable!() + _ => 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!() + 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!() + _ => unreachable!(), }; - assert_eq!(re.contribs.clone().unwrap()[0].clone().creator_id.unwrap(), creator_id); + 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); + 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!() + _ => 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() } #[test] fn test_merge_works() { - let (client, mut server) = setup_client(); let client = client.with_context(Context::new()); let admin_id = "aaaaaaaaaaaabkvkaaaaaaaaae".to_string(); - let resp = client.create_editgroup(Editgroup::new(admin_id)).wait().unwrap(); + let resp = client + .create_editgroup(Editgroup::new(admin_id)) + .wait() + .unwrap(); let editgroup_id = match resp { CreateEditgroupResponse::SuccessfullyCreated(eg) => eg.id.unwrap(), - _ => unreachable!() + _ => 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 resp = client + .create_work(WorkEntity::new(), Some(editgroup_id.clone())) + .wait() + .unwrap(); let work_a_id = match resp { CreateWorkResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; let mut new_release = ReleaseEntity::new("some release".to_string()); new_release.release_type = Some("journal-article".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 resp = client + .create_release(new_release, Some(editgroup_id.clone())) + .wait() + .unwrap(); let _release_a1_id = match resp { CreateReleaseResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; - let resp = client.create_work(WorkEntity::new(), Some(editgroup_id.clone())).wait().unwrap(); + 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!() + _ => unreachable!(), }; let mut new_release = ReleaseEntity::new("some release".to_string()); new_release.release_type = Some("journal-article".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 resp = client + .create_release(new_release, Some(editgroup_id.clone())) + .wait() + .unwrap(); let _release_b1_id = match resp { CreateReleaseResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; let mut new_release = ReleaseEntity::new("some release".to_string()); new_release.release_type = Some("journal-article".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 resp = client + .create_release(new_release, Some(editgroup_id.clone())) + .wait() + .unwrap(); let _release_b2_id = match resp { CreateReleaseResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; - match client.accept_editgroup(editgroup_id.clone()).wait().unwrap() { + match client + .accept_editgroup(editgroup_id.clone()) + .wait() + .unwrap() + { AcceptEditgroupResponse::MergedSuccessfully(_) => (), - _ => unreachable!() + _ => unreachable!(), }; -/* TODO: + /* TODO: // merge works client.merge_works(work_a_id, work_b_id) */ @@ -217,11 +268,11 @@ fn test_merge_works() { // check results let work_a = match client.get_work(work_a_id.clone(), None).wait().unwrap() { GetWorkResponse::FoundEntity(e) => e, - _ => unreachable!() + _ => unreachable!(), }; let _work_b = match client.get_work(work_b_id.clone(), None).wait().unwrap() { GetWorkResponse::FoundEntity(e) => e, - _ => unreachable!() + _ => unreachable!(), }; // TODO: assert_eq!(work_a.revision.unwrap(), work_b.revision.unwrap()); assert_eq!(work_a.redirect, None); |