mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-25 12:21:31 +00:00
Added apub test for post
This commit is contained in:
parent
366532c61a
commit
c2fa96a4ec
7 changed files with 92 additions and 13 deletions
|
@ -2,19 +2,19 @@
|
|||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
{
|
||||
"sensitive": "as:sensitive",
|
||||
"sc": "http://schema.org#",
|
||||
"matrixUserId": {
|
||||
"type": "sc:Text",
|
||||
"id": "as:alsoKnownAs"
|
||||
},
|
||||
"stickied": "as:stickied",
|
||||
"sensitive": "as:sensitive",
|
||||
"pt": "https://join-lemmy.org#",
|
||||
"comments_enabled": {
|
||||
"type": "sc:Boolean",
|
||||
"id": "pt:commentsEnabled"
|
||||
},
|
||||
"moderators": "as:moderators"
|
||||
"stickied": "as:stickied",
|
||||
"moderators": "as:moderators",
|
||||
"matrixUserId": {
|
||||
"type": "sc:Text",
|
||||
"id": "as:alsoKnownAs"
|
||||
}
|
||||
},
|
||||
"https://w3id.org/security/v1"
|
||||
],
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
{
|
||||
"sc": "http://schema.org#",
|
||||
"pt": "https://join-lemmy.org#",
|
||||
"stickied": "as:stickied",
|
||||
"comments_enabled": {
|
||||
"type": "sc:Boolean",
|
||||
"id": "pt:commentsEnabled"
|
||||
},
|
||||
"stickied": "as:stickied",
|
||||
"pt": "https://join-lemmy.org#",
|
||||
"sensitive": "as:sensitive",
|
||||
"moderators": "as:moderators",
|
||||
"sc": "http://schema.org#",
|
||||
"matrixUserId": {
|
||||
"type": "sc:Text",
|
||||
"id": "as:alsoKnownAs"
|
||||
|
|
41
crates/apub/assets/lemmy-post.json
Normal file
41
crates/apub/assets/lemmy-post.json
Normal file
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
{
|
||||
"matrixUserId": {
|
||||
"type": "sc:Text",
|
||||
"id": "as:alsoKnownAs"
|
||||
},
|
||||
"sc": "http://schema.org#",
|
||||
"comments_enabled": {
|
||||
"type": "sc:Boolean",
|
||||
"id": "pt:commentsEnabled"
|
||||
},
|
||||
"sensitive": "as:sensitive",
|
||||
"stickied": "as:stickied",
|
||||
"pt": "https://join-lemmy.org#",
|
||||
"moderators": "as:moderators"
|
||||
},
|
||||
"https://w3id.org/security/v1"
|
||||
],
|
||||
"type": "Page",
|
||||
"id": "https://lemmy.ml/post/70280",
|
||||
"attributedTo":
|
||||
"https://lemmy.ml/u/nutomic"
|
||||
,
|
||||
"to": [
|
||||
"https://lemmy.ml/c/meta",
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"name": "What is lemmy.ml?",
|
||||
"content": "<p>Recently there seems to be some of misunderstanding what the lemmy.ml instance is about, especially from newer users.</p>\n<p>Lemmy.ml has always been a niche site, and it will most likely stay this way. We don't have any intentions to turn it into a mainstream instance, or set a goal of getting as many users as possible. Our goal is simple: make an instance that people like to use. I would say that we have been successful in this, but obviously it is impossible to satisfy everyone.</p>\n<p>The reason for this is that @dessalines and I are paid to develop Lemmy, while donations from lemmy.ml users only make up a negligible part of our income. Besides, having more users would force us to spend more time moderating, and less time for development. Lemmy works quite differently from big tech sites like Reddit in this regard: while they get more money with each extra user through advertising, for us it is the opposite. So we would much rather have a smaller, non-toxic, and friendly userbase, than a large one.</p>\n<p>Part of the problem might be that lemmy.ml is described as "flagship instance", which can certainly be interpreted to mean "mainstream" or "general purpose". I struggle to come up with a better, more accurate description. If you can think of one, please comment here.</p>\n<p>If you dont like the way lemmy.ml works, thats okay. Federation exists exactly to solve that problem, let different groups have their own instances, with their own rules and political views. You can see the list of existing instances, and instructions for setting up a new one on <a href=\"https://join-lemmy.org/\">join-lemmy.org</a>.</p>\n<p>In particular, I would like to see someone (or a group of people) create a mainstream, or liberal instance. That should help to avoid further drama, and avoid attempts to turn lemmy.ml into something that it is not. @dessalines and I would certainly be willing to help with any technical problems that such an instance runs into, and include it on <a href=\"https://join-lemmy.org/\">join-lemmy.org</a> (just like any other instance that meets the code of conduct).</p>\n",
|
||||
"mediaType": "text/html",
|
||||
"source": {
|
||||
"content": "Recently there seems to be some of misunderstanding what the lemmy.ml instance is about, especially from newer users.\n\nLemmy.ml has always been a niche site, and it will most likely stay this way. We don't have any intentions to turn it into a mainstream instance, or set a goal of getting as many users as possible. Our goal is simple: make an instance that people like to use. I would say that we have been successful in this, but obviously it is impossible to satisfy everyone.\n\nThe reason for this is that @dessalines and I are paid to develop Lemmy, while donations from lemmy.ml users only make up a negligible part of our income. Besides, having more users would force us to spend more time moderating, and less time for development. Lemmy works quite differently from big tech sites like Reddit in this regard: while they get more money with each extra user through advertising, for us it is the opposite. So we would much rather have a smaller, non-toxic, and friendly userbase, than a large one.\n\nPart of the problem might be that lemmy.ml is described as \"flagship instance\", which can certainly be interpreted to mean \"mainstream\" or \"general purpose\". I struggle to come up with a better, more accurate description. If you can think of one, please comment here.\n\nIf you dont like the way lemmy.ml works, thats okay. Federation exists exactly to solve that problem, let different groups have their own instances, with their own rules and political views. You can see the list of existing instances, and instructions for setting up a new one on [join-lemmy.org](https://join-lemmy.org/).\n\nIn particular, I would like to see someone (or a group of people) create a mainstream, or liberal instance. That should help to avoid further drama, and avoid attempts to turn lemmy.ml into something that it is not. @dessalines and I would certainly be willing to help with any technical problems that such an instance runs into, and include it on [join-lemmy.org](https://join-lemmy.org/) (just like any other instance that meets the code of conduct).",
|
||||
"mediaType": "text/markdown"
|
||||
},
|
||||
"commentsEnabled": false,
|
||||
"sensitive": false,
|
||||
"stickied": true,
|
||||
"published": "2021-06-15T12:00:08.364559+00:00"
|
||||
}
|
|
@ -316,7 +316,8 @@ mod tests {
|
|||
async fn test_fetch_lemmy_community() {
|
||||
let json = file_to_json_object("assets/lemmy-community.json");
|
||||
let url = Url::parse("https://lemmy.ml/c/meta").unwrap();
|
||||
let community = ApubCommunity::from_apub(&json, &init_context(), &url, &mut 0)
|
||||
let mut request_counter = 0;
|
||||
let community = ApubCommunity::from_apub(&json, &init_context(), &url, &mut request_counter)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -325,5 +326,9 @@ mod tests {
|
|||
assert!(community.public_key.is_some());
|
||||
assert!(!community.local);
|
||||
assert_eq!(community.description.as_ref().unwrap().len(), 158);
|
||||
// TODO: its fetching the outbox, mod collection, and probably users from the outbox. due to
|
||||
// caching and other things, this may change over multiple runs, so we cant assert it.
|
||||
// find a way to avoid any network requests
|
||||
//assert_eq!(request_counter, 4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -278,7 +278,8 @@ mod tests {
|
|||
async fn test_fetch_lemmy_person() {
|
||||
let json = file_to_json_object("assets/lemmy-person.json");
|
||||
let url = Url::parse("https://lemmy.ml/u/nutomic").unwrap();
|
||||
let person = ApubPerson::from_apub(&json, &init_context(), &url, &mut 0)
|
||||
let mut request_counter = 0;
|
||||
let person = ApubPerson::from_apub(&json, &init_context(), &url, &mut request_counter)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -287,6 +288,7 @@ mod tests {
|
|||
assert!(person.public_key.is_some());
|
||||
assert!(!person.local);
|
||||
assert!(person.bio.is_some());
|
||||
assert_eq!(request_counter, 0);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
|
@ -294,7 +296,8 @@ mod tests {
|
|||
async fn test_fetch_pleroma_person() {
|
||||
let json = file_to_json_object("assets/pleroma-person.json");
|
||||
let url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
|
||||
let person = ApubPerson::from_apub(&json, &init_context(), &url, &mut 0)
|
||||
let mut request_counter = 0;
|
||||
let person = ApubPerson::from_apub(&json, &init_context(), &url, &mut request_counter)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -302,6 +305,7 @@ mod tests {
|
|||
assert_eq!(person.name, "lanodan");
|
||||
assert!(person.public_key.is_some());
|
||||
assert!(!person.local);
|
||||
assert_eq!(request_counter, 0);
|
||||
// TODO: pleroma uses summary for user profile, while we use content
|
||||
//assert!(person.bio.is_some());
|
||||
}
|
||||
|
|
|
@ -276,3 +276,30 @@ impl FromApub for ApubPost {
|
|||
Ok(post.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::objects::tests::{file_to_json_object, init_context};
|
||||
use serial_test::serial;
|
||||
|
||||
#[actix_rt::test]
|
||||
#[serial]
|
||||
async fn test_fetch_lemmy_post() {
|
||||
let json = file_to_json_object("assets/lemmy-post.json");
|
||||
let url = Url::parse("https://lemmy.ml/post/70280").unwrap();
|
||||
let mut request_counter = 0;
|
||||
let post = ApubPost::from_apub(&json, &init_context(), &url, &mut request_counter)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(post.ap_id.clone().into_inner(), url);
|
||||
assert_eq!(post.name, "What is lemmy.ml?");
|
||||
assert!(post.body.is_some());
|
||||
assert_eq!(post.body.as_ref().unwrap().len(), 2052);
|
||||
assert!(post.locked);
|
||||
assert!(post.stickied);
|
||||
// see comment in test_fetch_lemmy_community() about this
|
||||
//assert_eq!(request_counter, 5);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,5 +5,7 @@ curl -H "Accept: application/activity+json" https://lemmy.ml/u/nutomic | jq \
|
|||
> crates/apub/assets/lemmy-person.json
|
||||
curl -H "Accept: application/activity+json" https://lemmy.ml/c/meta | jq \
|
||||
> crates/apub/assets/lemmy-community.json
|
||||
curl -H "Accept: application/activity+json" https://lemmy.ml/post/70280 | jq \
|
||||
> crates/apub/assets/lemmy-post.json
|
||||
curl -H "Accept: application/activity+json" https://queer.hacktivis.me/users/lanodan | jq \
|
||||
> crates/apub/assets/pleroma-person.json
|
||||
|
|
Loading…
Reference in a new issue