Delete objects from db at the end of each test

pleroma-federation2
Felix Ableitner 3 years ago
parent b4d06b7705
commit 64e984688a

@ -319,19 +319,29 @@ mod tests {
use assert_json_diff::assert_json_include;
use serial_test::serial;
async fn prepare_comment_test(url: &Url, context: &LemmyContext) {
async fn prepare_comment_test(
url: &Url,
context: &LemmyContext,
) -> (ApubPerson, ApubCommunity, ApubPost) {
let person_json = file_to_json_object("assets/lemmy-person.json");
ApubPerson::from_apub(&person_json, context, url, &mut 0)
let person = ApubPerson::from_apub(&person_json, context, url, &mut 0)
.await
.unwrap();
let community_json = file_to_json_object("assets/lemmy-community.json");
ApubCommunity::from_apub(&community_json, context, url, &mut 0)
let community = ApubCommunity::from_apub(&community_json, context, url, &mut 0)
.await
.unwrap();
let post_json = file_to_json_object("assets/lemmy-post.json");
ApubPost::from_apub(&post_json, context, url, &mut 0)
let post = ApubPost::from_apub(&post_json, context, url, &mut 0)
.await
.unwrap();
(person, community, post)
}
fn cleanup(data: (ApubPerson, ApubCommunity, ApubPost), context: &LemmyContext) {
Post::delete(&*context.pool().get().unwrap(), data.2.id).unwrap();
Community::delete(&*context.pool().get().unwrap(), data.1.id).unwrap();
Person::delete(&*context.pool().get().unwrap(), data.0.id).unwrap();
}
#[actix_rt::test]
@ -339,7 +349,7 @@ mod tests {
async fn test_fetch_lemmy_comment() {
let context = init_context();
let url = Url::parse("https://lemmy.ml/comment/38741").unwrap();
prepare_comment_test(&url, &context).await;
let data = prepare_comment_test(&url, &context).await;
let json = file_to_json_object("assets/lemmy-comment.json");
let mut request_counter = 0;
@ -354,6 +364,9 @@ mod tests {
let to_apub = comment.to_apub(context.pool()).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
Comment::delete(&*context.pool().get().unwrap(), comment.id).unwrap();
cleanup(data, &context);
}
#[actix_rt::test]
@ -361,7 +374,7 @@ mod tests {
async fn test_fetch_pleroma_comment() {
let context = init_context();
let url = Url::parse("https://lemmy.ml/comment/38741").unwrap();
prepare_comment_test(&url, &context).await;
let data = prepare_comment_test(&url, &context).await;
let pleroma_url =
Url::parse("https://queer.hacktivis.me/objects/8d4973f4-53de-49cd-8c27-df160e16a9c2")
@ -380,12 +393,15 @@ mod tests {
assert_eq!(comment.content.len(), 64);
assert!(!comment.local);
assert_eq!(request_counter, 0);
Comment::delete(&*context.pool().get().unwrap(), comment.id).unwrap();
cleanup(data, &context);
}
#[actix_rt::test]
#[serial]
async fn test_html_to_markdown_sanitize() {
let parsed = parse_html(&"<script></script><b>hello</b>");
let parsed = parse_html("<script></script><b>hello</b>");
assert_eq!(parsed, "**hello**");
}
}

@ -319,6 +319,7 @@ mod tests {
use super::*;
use crate::objects::tests::{file_to_json_object, init_context};
use assert_json_diff::assert_json_include;
use lemmy_db_schema::traits::Crud;
use serial_test::serial;
#[actix_rt::test]
@ -347,5 +348,7 @@ mod tests {
let to_apub = community.to_apub(context.pool()).await.unwrap();
assert_json_include!(actual: json_orig, expected: to_apub);
Community::delete(&*context.pool().get().unwrap(), community.id).unwrap();
}
}

@ -272,6 +272,7 @@ mod tests {
use super::*;
use crate::objects::tests::{file_to_json_object, init_context};
use assert_json_diff::assert_json_include;
use lemmy_db_schema::traits::Crud;
use serial_test::serial;
#[actix_rt::test]
@ -294,15 +295,18 @@ mod tests {
let to_apub = person.to_apub(context.pool()).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
DbPerson::delete(&*context.pool().get().unwrap(), person.id).unwrap();
}
#[actix_rt::test]
#[serial]
async fn test_fetch_pleroma_person() {
let context = init_context();
let json = file_to_json_object("assets/pleroma-person.json");
let url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
let mut request_counter = 0;
let person = ApubPerson::from_apub(&json, &init_context(), &url, &mut request_counter)
let person = ApubPerson::from_apub(&json, &context, &url, &mut request_counter)
.await
.unwrap();
@ -313,5 +317,7 @@ mod tests {
assert_eq!(request_counter, 0);
// TODO: pleroma uses summary for user profile, while we use content
//assert!(person.bio.is_some());
DbPerson::delete(&*context.pool().get().unwrap(), person.id).unwrap();
}
}

@ -294,11 +294,11 @@ mod tests {
let context = init_context();
let url = Url::parse("https://lemmy.ml/post/55143").unwrap();
let community_json = file_to_json_object("assets/lemmy-community.json");
ApubCommunity::from_apub(&community_json, &context, &url, &mut 0)
let community = 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)
let person = ApubPerson::from_apub(&person_json, &context, &url, &mut 0)
.await
.unwrap();
let json = file_to_json_object("assets/lemmy-post.json");
@ -317,5 +317,9 @@ mod tests {
let to_apub = post.to_apub(context.pool()).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
Post::delete(&*context.pool().get().unwrap(), post.id).unwrap();
Person::delete(&*context.pool().get().unwrap(), person.id).unwrap();
Community::delete(&*context.pool().get().unwrap(), community.id).unwrap();
}
}

@ -213,12 +213,12 @@ mod tests {
let context = init_context();
let url = Url::parse("https://lemmy.ml/private_message/1621").unwrap();
let lemmy_person = file_to_json_object("assets/lemmy-person.json");
ApubPerson::from_apub(&lemmy_person, &context, &url, &mut 0)
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_url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
ApubPerson::from_apub(&pleroma_person, &context, &pleroma_url, &mut 0)
let person2 = ApubPerson::from_apub(&pleroma_person, &context, &pleroma_url, &mut 0)
.await
.unwrap();
let json = file_to_json_object("assets/lemmy-private-message.json");
@ -233,5 +233,9 @@ mod tests {
let to_apub = pm.to_apub(context.pool()).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
PrivateMessage::delete(&*context.pool().get().unwrap(), pm.id).unwrap();
Person::delete(&*context.pool().get().unwrap(), person1.id).unwrap();
Person::delete(&*context.pool().get().unwrap(), person2.id).unwrap();
}
}

@ -33,6 +33,10 @@ impl Crud for PrivateMessage {
.set(private_message_form)
.get_result::<Self>(conn)
}
fn delete(conn: &PgConnection, pm_id: Self::IdType) -> Result<usize, Error> {
use crate::schema::private_message::dsl::*;
diesel::delete(private_message.find(pm_id)).execute(conn)
}
}
impl PrivateMessage {

Loading…
Cancel
Save