From: Felix Ableitner Date: Fri, 29 Oct 2021 14:54:19 +0000 (+0200) Subject: Move apub test files into tree structure X-Git-Url: http://these/git/%7B%27/docs/static/%7B%60%24%7BghostArchiveUrl%7D/search?a=commitdiff_plain;h=aaaf03977970103363c80e5534c79363dcab0821;p=lemmy.git Move apub test files into tree structure --- diff --git a/crates/apub/assets/lemmy-private-message.json b/crates/apub/assets/lemmy/objects/chat_message.json similarity index 100% rename from crates/apub/assets/lemmy-private-message.json rename to crates/apub/assets/lemmy/objects/chat_message.json diff --git a/crates/apub/assets/lemmy-community.json b/crates/apub/assets/lemmy/objects/group.json similarity index 100% rename from crates/apub/assets/lemmy-community.json rename to crates/apub/assets/lemmy/objects/group.json diff --git a/crates/apub/assets/lemmy-comment.json b/crates/apub/assets/lemmy/objects/note.json similarity index 100% rename from crates/apub/assets/lemmy-comment.json rename to crates/apub/assets/lemmy/objects/note.json diff --git a/crates/apub/assets/lemmy-post.json b/crates/apub/assets/lemmy/objects/page.json similarity index 100% rename from crates/apub/assets/lemmy-post.json rename to crates/apub/assets/lemmy/objects/page.json diff --git a/crates/apub/assets/lemmy-person.json b/crates/apub/assets/lemmy/objects/person.json similarity index 100% rename from crates/apub/assets/lemmy-person.json rename to crates/apub/assets/lemmy/objects/person.json diff --git a/crates/apub/assets/pleroma-create-comment.json b/crates/apub/assets/pleroma/activities/create-note.json similarity index 100% rename from crates/apub/assets/pleroma-create-comment.json rename to crates/apub/assets/pleroma/activities/create-note.json diff --git a/crates/apub/assets/pleroma-private-message.json b/crates/apub/assets/pleroma/objects/chat_message.json similarity index 100% rename from crates/apub/assets/pleroma-private-message.json rename to crates/apub/assets/pleroma/objects/chat_message.json diff --git a/crates/apub/assets/pleroma-comment.json b/crates/apub/assets/pleroma/objects/note.json similarity index 100% rename from crates/apub/assets/pleroma-comment.json rename to crates/apub/assets/pleroma/objects/note.json diff --git a/crates/apub/assets/pleroma-person.json b/crates/apub/assets/pleroma/objects/person.json similarity index 100% rename from crates/apub/assets/pleroma-person.json rename to crates/apub/assets/pleroma/objects/person.json diff --git a/crates/apub/src/activities/comment/create_or_update.rs b/crates/apub/src/activities/comment/create_or_update.rs index 335e1713..79259180 100644 --- a/crates/apub/src/activities/comment/create_or_update.rs +++ b/crates/apub/src/activities/comment/create_or_update.rs @@ -131,15 +131,13 @@ impl GetCommunity for CreateOrUpdateComment { #[cfg(test)] mod tests { - use serial_test::serial; - - use crate::objects::tests::file_to_json_object; - use super::*; + use crate::objects::tests::file_to_json_object; + use serial_test::serial; #[actix_rt::test] #[serial] async fn test_parse_pleroma_create_comment() { - let _: CreateOrUpdateComment = file_to_json_object("assets/pleroma-create-comment.json"); + file_to_json_object::("assets/pleroma/activities/create-note.json"); } } diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index cd491d87..736d1453 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -186,30 +186,29 @@ impl ApubObject for ApubComment { #[cfg(test)] pub(crate) mod tests { - use assert_json_diff::assert_json_include; - use serial_test::serial; - + use super::*; use crate::objects::{ community::ApubCommunity, + person::ApubPerson, + post::ApubPost, tests::{file_to_json_object, init_context}, }; - - use super::*; - use crate::objects::{person::ApubPerson, post::ApubPost}; + use assert_json_diff::assert_json_include; + use serial_test::serial; pub(crate) async fn prepare_comment_test( url: &Url, context: &LemmyContext, ) -> (ApubPerson, ApubCommunity, ApubPost) { - let person_json = file_to_json_object("assets/lemmy-person.json"); + let person_json = file_to_json_object("assets/lemmy/objects/person.json"); let person = ApubPerson::from_apub(&person_json, context, url, &mut 0) .await .unwrap(); - let community_json = file_to_json_object("assets/lemmy-community.json"); + let community_json = file_to_json_object("assets/lemmy/objects/group.json"); let community = ApubCommunity::from_apub(&community_json, context, url, &mut 0) .await .unwrap(); - let post_json = file_to_json_object("assets/lemmy-post.json"); + let post_json = file_to_json_object("assets/lemmy/objects/page.json"); let post = ApubPost::from_apub(&post_json, context, url, &mut 0) .await .unwrap(); @@ -229,7 +228,7 @@ pub(crate) mod tests { let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap(); let data = prepare_comment_test(&url, &context).await; - let json = file_to_json_object("assets/lemmy-comment.json"); + let json = file_to_json_object("assets/lemmy/objects/note.json"); let mut request_counter = 0; let comment = ApubComment::from_apub(&json, &context, &url, &mut request_counter) .await @@ -257,11 +256,11 @@ pub(crate) mod tests { let pleroma_url = Url::parse("https://queer.hacktivis.me/objects/8d4973f4-53de-49cd-8c27-df160e16a9c2") .unwrap(); - let person_json = file_to_json_object("assets/pleroma-person.json"); + let person_json = file_to_json_object("assets/pleroma/objects/person.json"); ApubPerson::from_apub(&person_json, &context, &pleroma_url, &mut 0) .await .unwrap(); - let json = file_to_json_object("assets/pleroma-comment.json"); + let json = file_to_json_object("assets/pleroma/objects/note.json"); let mut request_counter = 0; let comment = ApubComment::from_apub(&json, &context, &pleroma_url, &mut request_counter) .await diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 0a4c06a4..e1a37e8b 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -223,20 +223,17 @@ impl ApubCommunity { #[cfg(test)] mod tests { + use super::*; + use crate::objects::tests::{file_to_json_object, init_context}; use assert_json_diff::assert_json_include; - use serial_test::serial; - use lemmy_db_schema::traits::Crud; - - use crate::objects::tests::{file_to_json_object, init_context}; - - use super::*; + use serial_test::serial; #[actix_rt::test] #[serial] async fn test_parse_lemmy_community() { let context = init_context(); - let mut json: Group = file_to_json_object("assets/lemmy-community.json"); + let mut json: Group = file_to_json_object("assets/lemmy/objects/group.json"); let json_orig = json.clone(); // change these links so they dont fetch over the network json.moderators = Some(ObjectId::new( diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 1d914e32..9e487ed3 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -256,7 +256,7 @@ mod tests { #[serial] async fn test_parse_lemmy_person() { let context = init_context(); - let json = file_to_json_object("assets/lemmy-person.json"); + let json = file_to_json_object("assets/lemmy/objects/person.json"); let url = Url::parse("https://enterprise.lemmy.ml/u/picard").unwrap(); let mut request_counter = 0; let person = ApubPerson::from_apub(&json, &context, &url, &mut request_counter) @@ -280,7 +280,7 @@ mod tests { #[serial] async fn test_parse_pleroma_person() { let context = init_context(); - let json = file_to_json_object("assets/pleroma-person.json"); + let json = file_to_json_object("assets/pleroma/objects/person.json"); let url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap(); let mut request_counter = 0; let person = ApubPerson::from_apub(&json, &context, &url, &mut request_counter) diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 3ade8de0..e5a83297 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -206,15 +206,15 @@ mod tests { async fn test_parse_lemmy_post() { let context = init_context(); let url = Url::parse("https://enterprise.lemmy.ml/post/55143").unwrap(); - let community_json = file_to_json_object("assets/lemmy-community.json"); + let community_json = file_to_json_object("assets/lemmy/objects/group.json"); let community = ApubCommunity::from_apub(&community_json, &context, &url, &mut 0) .await .unwrap(); - let person_json = file_to_json_object("assets/lemmy-person.json"); + let person_json = file_to_json_object("assets/lemmy/objects/person.json"); let person = ApubPerson::from_apub(&person_json, &context, &url, &mut 0) .await .unwrap(); - let json = file_to_json_object("assets/lemmy-post.json"); + let json = file_to_json_object("assets/lemmy/objects/page.json"); let mut request_counter = 0; let post = ApubPost::from_apub(&json, &context, &url, &mut request_counter) .await diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index ee0aec95..678435ee 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -146,11 +146,11 @@ mod tests { use serial_test::serial; async fn prepare_comment_test(url: &Url, context: &LemmyContext) -> (ApubPerson, ApubPerson) { - let lemmy_person = file_to_json_object("assets/lemmy-person.json"); + let lemmy_person = file_to_json_object("assets/lemmy/objects/person.json"); let person1 = ApubPerson::from_apub(&lemmy_person, context, url, &mut 0) .await .unwrap(); - let pleroma_person = file_to_json_object("assets/pleroma-person.json"); + let pleroma_person = file_to_json_object("assets/pleroma/objects/person.json"); let pleroma_url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap(); let person2 = ApubPerson::from_apub(&pleroma_person, context, &pleroma_url, &mut 0) .await @@ -169,7 +169,7 @@ mod tests { let context = init_context(); let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap(); let data = prepare_comment_test(&url, &context).await; - let json = file_to_json_object("assets/lemmy-private-message.json"); + let json = file_to_json_object("assets/lemmy/objects/chat_message.json"); let mut request_counter = 0; let pm = ApubPrivateMessage::from_apub(&json, &context, &url, &mut request_counter) .await @@ -193,7 +193,7 @@ mod tests { let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap(); let data = prepare_comment_test(&url, &context).await; let pleroma_url = Url::parse("https://queer.hacktivis.me/objects/2").unwrap(); - let json = file_to_json_object("assets/pleroma-private-message.json"); + let json = file_to_json_object("assets/pleroma/objects/chat_message.json"); let mut request_counter = 0; let pm = ApubPrivateMessage::from_apub(&json, &context, &pleroma_url, &mut request_counter) .await