mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 06:11:26 +00:00
Removing pointless TestUser.
This commit is contained in:
parent
fbd219a370
commit
caa8864c24
6 changed files with 49 additions and 87 deletions
|
@ -12,8 +12,6 @@ pub mod read_community;
|
||||||
pub mod read_person;
|
pub mod read_person;
|
||||||
pub mod resolve_object;
|
pub mod resolve_object;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
#[cfg(test)]
|
|
||||||
pub(crate) mod test;
|
|
||||||
pub mod user_settings_backup;
|
pub mod user_settings_backup;
|
||||||
|
|
||||||
/// Returns default listing type, depending if the query is for frontpage or community.
|
/// Returns default listing type, depending if the query is for frontpage or community.
|
||||||
|
|
|
@ -72,7 +72,7 @@ async fn convert_response(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::api::{resolve_object::resolve_object, test::TestUser};
|
use crate::api::resolve_object::resolve_object;
|
||||||
use actix_web::web::Query;
|
use actix_web::web::Query;
|
||||||
use lemmy_api_common::{context::LemmyContext, site::ResolveObject};
|
use lemmy_api_common::{context::LemmyContext, site::ResolveObject};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -85,6 +85,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
|
@ -95,14 +96,12 @@ mod tests {
|
||||||
let context = LemmyContext::init_test_context().await;
|
let context = LemmyContext::init_test_context().await;
|
||||||
let pool = &mut context.pool();
|
let pool = &mut context.pool();
|
||||||
|
|
||||||
let creator = TestUser::default().create(pool).await?;
|
let name = "test_local_user_name";
|
||||||
let regular_user = TestUser::default().create(pool).await?;
|
let bio = "test_local_user_bio";
|
||||||
let admin_user = TestUser {
|
|
||||||
admin: true,
|
let creator = LocalUserView::create_test_user(pool, name, bio, false).await?;
|
||||||
..Default::default()
|
let regular_user = LocalUserView::create_test_user(pool, name, bio, false).await?;
|
||||||
}
|
let admin_user = LocalUserView::create_test_user(pool, name, bio, true).await?;
|
||||||
.create(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let instance_id = creator.person.instance_id;
|
let instance_id = creator.person.instance_id;
|
||||||
let site_form = SiteInsertForm::new("test site".to_string(), instance_id);
|
let site_form = SiteInsertForm::new("test site".to_string(), instance_id);
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
use lemmy_db_schema::{
|
|
||||||
source::{
|
|
||||||
instance::Instance,
|
|
||||||
local_user::{LocalUser, LocalUserInsertForm},
|
|
||||||
person::{Person, PersonInsertForm},
|
|
||||||
},
|
|
||||||
traits::Crud,
|
|
||||||
utils::DbPool,
|
|
||||||
};
|
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
|
||||||
use lemmy_utils::error::LemmyResult;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct TestUser {
|
|
||||||
pub name: Option<&'static str>,
|
|
||||||
pub bio: Option<&'static str>,
|
|
||||||
pub admin: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TestUser {
|
|
||||||
pub async fn create(self, pool: &mut DbPool<'_>) -> LemmyResult<LocalUserView> {
|
|
||||||
let instance_id = Instance::read_or_create(pool, "example.com".to_string())
|
|
||||||
.await?
|
|
||||||
.id;
|
|
||||||
let name = self
|
|
||||||
.name
|
|
||||||
.map_or_else(|| uuid::Uuid::new_v4().to_string(), ToString::to_string);
|
|
||||||
|
|
||||||
let person_form = PersonInsertForm {
|
|
||||||
display_name: Some(name.clone()),
|
|
||||||
bio: self.bio.map(ToString::to_string),
|
|
||||||
..PersonInsertForm::test_form(instance_id, &name)
|
|
||||||
};
|
|
||||||
let person = Person::create(pool, &person_form).await?;
|
|
||||||
|
|
||||||
let user_form = match self.admin {
|
|
||||||
true => LocalUserInsertForm::test_form_admin(person.id),
|
|
||||||
false => LocalUserInsertForm::test_form(person.id),
|
|
||||||
};
|
|
||||||
let local_user = LocalUser::create(pool, &user_form, vec![]).await?;
|
|
||||||
|
|
||||||
Ok(LocalUserView::read(pool, local_user.id).await?)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -314,10 +314,7 @@ where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::indexing_slicing)]
|
#[expect(clippy::indexing_slicing)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
use crate::api::{
|
use crate::api::user_settings_backup::{export_settings, import_settings};
|
||||||
test::TestUser,
|
|
||||||
user_settings_backup::{export_settings, import_settings},
|
|
||||||
};
|
|
||||||
use actix_web::web::Json;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::context::LemmyContext;
|
use lemmy_api_common::context::LemmyContext;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -341,13 +338,7 @@ pub(crate) mod tests {
|
||||||
let context = LemmyContext::init_test_context().await;
|
let context = LemmyContext::init_test_context().await;
|
||||||
let pool = &mut context.pool();
|
let pool = &mut context.pool();
|
||||||
|
|
||||||
let export_user = TestUser {
|
let export_user = LocalUserView::create_test_user(pool, "hanna", "my bio", false).await?;
|
||||||
name: "hanna".into(),
|
|
||||||
bio: "my bio".into(),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
.create(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let community_form = CommunityInsertForm::new(
|
let community_form = CommunityInsertForm::new(
|
||||||
export_user.person.instance_id,
|
export_user.person.instance_id,
|
||||||
|
@ -365,12 +356,8 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
let backup = export_settings(export_user.clone(), context.reset_request_count()).await?;
|
let backup = export_settings(export_user.clone(), context.reset_request_count()).await?;
|
||||||
|
|
||||||
let import_user = TestUser {
|
let import_user =
|
||||||
name: "charles".into(),
|
LocalUserView::create_test_user(pool, "charles", "charles bio", false).await?;
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
.create(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
import_settings(backup, import_user.clone(), context.reset_request_count()).await?;
|
import_settings(backup, import_user.clone(), context.reset_request_count()).await?;
|
||||||
|
|
||||||
|
@ -400,12 +387,7 @@ pub(crate) mod tests {
|
||||||
let context = LemmyContext::init_test_context().await;
|
let context = LemmyContext::init_test_context().await;
|
||||||
let pool = &mut context.pool();
|
let pool = &mut context.pool();
|
||||||
|
|
||||||
let export_user = TestUser {
|
let export_user = LocalUserView::create_test_user(pool, "harry", "harry bio", false).await?;
|
||||||
bio: "my bio".into(),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
.create(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let mut backup = export_settings(export_user.clone(), context.reset_request_count()).await?;
|
let mut backup = export_settings(export_user.clone(), context.reset_request_count()).await?;
|
||||||
|
|
||||||
|
@ -420,7 +402,7 @@ pub(crate) mod tests {
|
||||||
backup.saved_comments.push("http://example4.com".parse()?);
|
backup.saved_comments.push("http://example4.com".parse()?);
|
||||||
}
|
}
|
||||||
|
|
||||||
let import_user = TestUser::default().create(pool).await?;
|
let import_user = LocalUserView::create_test_user(pool, "sally", "sally bio", false).await?;
|
||||||
|
|
||||||
let imported =
|
let imported =
|
||||||
import_settings(backup, import_user.clone(), context.reset_request_count()).await;
|
import_settings(backup, import_user.clone(), context.reset_request_count()).await;
|
||||||
|
@ -441,12 +423,7 @@ pub(crate) mod tests {
|
||||||
let context = LemmyContext::init_test_context().await;
|
let context = LemmyContext::init_test_context().await;
|
||||||
let pool = &mut context.pool();
|
let pool = &mut context.pool();
|
||||||
|
|
||||||
let import_user = TestUser {
|
let import_user = LocalUserView::create_test_user(pool, "larry", "larry bio", false).await?;
|
||||||
bio: "my bio".into(),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
.create(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let backup =
|
let backup =
|
||||||
serde_json::from_str("{\"bot_account\": true, \"settings\": {\"theme\": \"my_theme\"}}")?;
|
serde_json::from_str("{\"bot_account\": true, \"settings\": {\"theme\": \"my_theme\"}}")?;
|
||||||
|
|
|
@ -104,7 +104,6 @@ async fn format_actor_url(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::api::test::TestUser;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunityInsertForm},
|
community::{Community, CommunityInsertForm},
|
||||||
|
@ -112,6 +111,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
|
@ -130,7 +130,8 @@ mod tests {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let user = TestUser::default().create(&mut context.pool()).await?;
|
let user =
|
||||||
|
LocalUserView::create_test_user(&mut context.pool(), "garda", "garda bio", false).await?;
|
||||||
|
|
||||||
// insert a remote post which is already fetched
|
// insert a remote post which is already fetched
|
||||||
let post_form = PostInsertForm {
|
let post_form = PostInsertForm {
|
||||||
|
|
|
@ -5,6 +5,12 @@ use diesel_async::RunQueryDsl;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{LocalUserId, OAuthProviderId, PersonId},
|
newtypes::{LocalUserId, OAuthProviderId, PersonId},
|
||||||
schema::{local_user, local_user_vote_display_mode, oauth_account, person, person_aggregates},
|
schema::{local_user, local_user_vote_display_mode, oauth_account, person, person_aggregates},
|
||||||
|
source::{
|
||||||
|
instance::Instance,
|
||||||
|
local_user::{LocalUser, LocalUserInsertForm},
|
||||||
|
person::{Person, PersonInsertForm},
|
||||||
|
},
|
||||||
|
traits::Crud,
|
||||||
utils::{
|
utils::{
|
||||||
functions::{coalesce, lower},
|
functions::{coalesce, lower},
|
||||||
DbConn,
|
DbConn,
|
||||||
|
@ -134,6 +140,31 @@ impl LocalUserView {
|
||||||
pub async fn list_admins_with_emails(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
|
pub async fn list_admins_with_emails(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
|
||||||
queries().list(pool, ListMode::AdminsWithEmails).await
|
queries().list(pool, ListMode::AdminsWithEmails).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn create_test_user(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
name: &str,
|
||||||
|
bio: &str,
|
||||||
|
admin: bool,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
let instance_id = Instance::read_or_create(pool, "example.com".to_string())
|
||||||
|
.await?
|
||||||
|
.id;
|
||||||
|
let person_form = PersonInsertForm {
|
||||||
|
display_name: Some(name.to_owned()),
|
||||||
|
bio: Some(bio.to_owned()),
|
||||||
|
..PersonInsertForm::test_form(instance_id, name)
|
||||||
|
};
|
||||||
|
let person = Person::create(pool, &person_form).await?;
|
||||||
|
|
||||||
|
let user_form = match admin {
|
||||||
|
true => LocalUserInsertForm::test_form_admin(person.id),
|
||||||
|
false => LocalUserInsertForm::test_form(person.id),
|
||||||
|
};
|
||||||
|
let local_user = LocalUser::create(pool, &user_form, vec![]).await?;
|
||||||
|
|
||||||
|
LocalUserView::read(pool, local_user.id).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromRequest for LocalUserView {
|
impl FromRequest for LocalUserView {
|
||||||
|
|
Loading…
Reference in a new issue