mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-12 21:15:53 +00:00
Dont fetch community outbox/moderators during tests
This commit is contained in:
parent
795ad7a65d
commit
5504efa4a6
4 changed files with 25 additions and 11 deletions
|
@ -33,9 +33,9 @@
|
||||||
"url": "https://lemmy.ml/pictrs/image/waqyZwLAy4.webp"
|
"url": "https://lemmy.ml/pictrs/image/waqyZwLAy4.webp"
|
||||||
},
|
},
|
||||||
"sensitive": false,
|
"sensitive": false,
|
||||||
"moderators": "https://lemmy.ml/c/announcements/moderators",
|
"moderators": "https://lemmy.ml/c/announcements/not_moderators",
|
||||||
"inbox": "https://lemmy.ml/c/announcements/inbox",
|
"inbox": "https://lemmy.ml/c/announcements/inbox",
|
||||||
"outbox": "https://lemmy.ml/c/announcements/outbox",
|
"outbox": "https://lemmy.ml/c/announcements/not_outbox",
|
||||||
"followers": "https://lemmy.ml/c/announcements/followers",
|
"followers": "https://lemmy.ml/c/announcements/followers",
|
||||||
"endpoints": {
|
"endpoints": {
|
||||||
"sharedInbox": "https://lemmy.ml/inbox"
|
"sharedInbox": "https://lemmy.ml/inbox"
|
||||||
|
|
|
@ -36,6 +36,7 @@ use lemmy_utils::{
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
@ -263,11 +264,19 @@ impl FromApub for ApubCommunity {
|
||||||
) -> Result<ApubCommunity, LemmyError> {
|
) -> Result<ApubCommunity, LemmyError> {
|
||||||
let form = Group::from_apub_to_form(group, expected_domain, &context.settings()).await?;
|
let form = Group::from_apub_to_form(group, expected_domain, &context.settings()).await?;
|
||||||
|
|
||||||
|
// Fetching mods and outbox is not necessary for Lemmy to work, so ignore errors. Besides,
|
||||||
|
// we need to ignore these errors so that tests can work entirely offline.
|
||||||
let community = blocking(context.pool(), move |conn| Community::upsert(conn, &form)).await??;
|
let community = blocking(context.pool(), move |conn| Community::upsert(conn, &form)).await??;
|
||||||
update_community_mods(group, &community, context, request_counter).await?;
|
update_community_mods(group, &community, context, request_counter)
|
||||||
|
.await
|
||||||
|
.map_err(|e| debug!("{}", e))
|
||||||
|
.ok();
|
||||||
|
|
||||||
// TODO: doing this unconditionally might cause infinite loop for some reason
|
// TODO: doing this unconditionally might cause infinite loop for some reason
|
||||||
fetch_community_outbox(context, &group.outbox, request_counter).await?;
|
fetch_community_outbox(context, &group.outbox, request_counter)
|
||||||
|
.await
|
||||||
|
.map_err(|e| debug!("{}", e))
|
||||||
|
.ok();
|
||||||
|
|
||||||
Ok(community.into())
|
Ok(community.into())
|
||||||
}
|
}
|
||||||
|
@ -326,9 +335,7 @@ mod tests {
|
||||||
assert!(community.public_key.is_some());
|
assert!(community.public_key.is_some());
|
||||||
assert!(!community.local);
|
assert!(!community.local);
|
||||||
assert_eq!(community.description.as_ref().unwrap().len(), 126);
|
assert_eq!(community.description.as_ref().unwrap().len(), 126);
|
||||||
// TODO: its fetching the outbox, mod collection, and probably users from the outbox. due to
|
// this makes two requests to the (intentionally) broken outbox/moderators collections
|
||||||
// caching and other things, this may change over multiple runs, so we cant assert it.
|
assert_eq!(request_counter, 2);
|
||||||
// find a way to avoid any network requests
|
|
||||||
//assert_eq!(request_counter, 4);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,12 +291,16 @@ mod tests {
|
||||||
async fn test_fetch_lemmy_post() {
|
async fn test_fetch_lemmy_post() {
|
||||||
let context = init_context();
|
let context = init_context();
|
||||||
let url = Url::parse("https://lemmy.ml/post/55143").unwrap();
|
let url = Url::parse("https://lemmy.ml/post/55143").unwrap();
|
||||||
let mut request_counter = -20;
|
|
||||||
let community_json = file_to_json_object("assets/lemmy-community.json");
|
let community_json = file_to_json_object("assets/lemmy-community.json");
|
||||||
ApubCommunity::from_apub(&community_json, &context, &url, &mut request_counter)
|
ApubCommunity::from_apub(&community_json, &context, &url, &mut 0)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let person_json = file_to_json_object("assets/lemmy-person.json");
|
||||||
|
ApubPerson::from_apub(&person_json, &context, &url, &mut 0)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let json = file_to_json_object("assets/lemmy-post.json");
|
let json = file_to_json_object("assets/lemmy-post.json");
|
||||||
|
let mut request_counter = 0;
|
||||||
let post = ApubPost::from_apub(&json, &context, &url, &mut request_counter)
|
let post = ApubPost::from_apub(&json, &context, &url, &mut request_counter)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -308,6 +312,6 @@ mod tests {
|
||||||
assert!(!post.locked);
|
assert!(!post.locked);
|
||||||
assert!(post.stickied);
|
assert!(post.stickied);
|
||||||
// see comment in test_fetch_lemmy_community() about this
|
// see comment in test_fetch_lemmy_community() about this
|
||||||
//assert_eq!(request_counter, 5);
|
assert_eq!(request_counter, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@ curl -H "Accept: application/activity+json" https://lemmy.ml/u/nutomic | jq \
|
||||||
> crates/apub/assets/lemmy-person.json
|
> crates/apub/assets/lemmy-person.json
|
||||||
curl -H "Accept: application/activity+json" https://lemmy.ml/c/announcements | jq \
|
curl -H "Accept: application/activity+json" https://lemmy.ml/c/announcements | jq \
|
||||||
> crates/apub/assets/lemmy-community.json
|
> crates/apub/assets/lemmy-community.json
|
||||||
|
# replace these collection links so that tests dont make any actual http requests
|
||||||
|
sed -i 's/https:\/\/lemmy.ml\/c\/announcements\/outbox/https:\\/\\/lemmy.ml\\/c\\/announcements\\/not_outbox/g' crates/apub/assets/lemmy-community.json
|
||||||
|
sed -i 's/https:\/\/lemmy.ml\/c\/announcements\/moderators/https:\\/\\/lemmy.ml\\/c\\/announcements\\/not_moderators/g' crates/apub/assets/lemmy-community.json
|
||||||
curl -H "Accept: application/activity+json" https://lemmy.ml/post/55143 | jq \
|
curl -H "Accept: application/activity+json" https://lemmy.ml/post/55143 | jq \
|
||||||
> crates/apub/assets/lemmy-post.json
|
> crates/apub/assets/lemmy-post.json
|
||||||
curl -H "Accept: application/activity+json" https://queer.hacktivis.me/users/lanodan | jq \
|
curl -H "Accept: application/activity+json" https://queer.hacktivis.me/users/lanodan | jq \
|
||||||
|
|
Loading…
Reference in a new issue