mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 01:18:34 +00:00
update_weight needs testing
This commit is contained in:
1 parent
2e4e109065
commit
f63eb94ed7
2 files changed
+38
-34
No files matched your search
@@ -1,3 +1,4 @@
|
||||
pub mod create_weight;
|
||||
//pub mod delete_weight;
|
||||
pub mod get_weight;
|
||||
pub mod update_weight;
|
||||
@@ -11,8 +11,9 @@ use tokens::tokens::model_weights::ModelWeightToken;
|
||||
use config::shared_constants::{DEFAULT_MYSQL_CONNECTION_STRING, DEFAULT_RUST_LOG};
|
||||
|
||||
pub struct UpdateWeightArgs<'a> {
|
||||
pub weight_token: &ModelWeightToken,
|
||||
pub weight_token: &'a ModelWeightToken,
|
||||
pub title: Option<&'a str>,
|
||||
pub maybe_thumbnail_token: Option<&'a str>,
|
||||
pub description_markdown: &'a str,
|
||||
pub description_rendered_html: &'a str,
|
||||
pub creator_set_visibility: &'a Visibility,
|
||||
@@ -23,12 +24,13 @@ pub async fn update_weights(args: UpdateWeightArgs<'_>) -> AnyhowResult<()> {
|
||||
let mut transaction = args.mysql_pool.begin().await?;
|
||||
|
||||
let query_result = sqlx
|
||||
::query(
|
||||
::query!(
|
||||
r#"
|
||||
UPDATE model_weights
|
||||
SET
|
||||
title = ?,
|
||||
description_markdown = ?,
|
||||
maybe_thumbnail_token = ?,
|
||||
description_rendered_html = ?,
|
||||
creator_set_visibility = ?,
|
||||
version = version + 1
|
||||
@@ -36,8 +38,9 @@ pub async fn update_weights(args: UpdateWeightArgs<'_>) -> AnyhowResult<()> {
|
||||
LIMIT 1
|
||||
"#,
|
||||
args.title,
|
||||
description_markdown,
|
||||
description_rendered_html,
|
||||
args.description_markdown,
|
||||
args.maybe_thumbnail_token,
|
||||
args.description_rendered_html,
|
||||
args.creator_set_visibility.to_str(),
|
||||
args.weight_token.as_str()
|
||||
)
|
||||
@@ -48,44 +51,44 @@ pub async fn update_weights(args: UpdateWeightArgs<'_>) -> AnyhowResult<()> {
|
||||
match query_result {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => {
|
||||
transaction.rollback().await?;
|
||||
Err(anyhow!("weights update error: {:?}", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sqlx::MySqlPoolOptions;
|
||||
use easyenv;
|
||||
use tokio;
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// use super::*;
|
||||
// use sqlx::MySqlPoolOptions;
|
||||
// use easyenv;
|
||||
// use tokio;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_update_weights() -> AnyhowResult<()> {
|
||||
let db_connection_string = easyenv::get_env_string_or_default(
|
||||
"MYSQL_URL",
|
||||
DEFAULT_MYSQL_CONNECTION_STRING
|
||||
);
|
||||
// #[tokio::test]
|
||||
// async fn test_update_weights() -> AnyhowResult<()> {
|
||||
// let db_connection_string = easyenv::get_env_string_or_default(
|
||||
// "MYSQL_URL",
|
||||
// DEFAULT_MYSQL_CONNECTION_STRING
|
||||
// );
|
||||
|
||||
let pool = MySqlPoolOptions::new()
|
||||
.max_connections(easyenv::get_env_num("MYSQL_MAX_CONNECTIONS", 3)?)
|
||||
.connect(&db_connection_string)
|
||||
.await?;
|
||||
// let pool = MySqlPoolOptions::new()
|
||||
// .max_connections(easyenv::get_env_num("MYSQL_MAX_CONNECTIONS", 3)?)
|
||||
// .connect(&db_connection_string)
|
||||
// .await?;
|
||||
|
||||
let args = UpdateWeightArgs {
|
||||
weight_token: &ModelWeightToken::new("test_token"),
|
||||
title: Some("Test Title"),
|
||||
description_markdown: "Test Description Markdown",
|
||||
description_rendered_html: "Test Description HTML",
|
||||
creator_set_visibility: &Visibility::Public,
|
||||
mysql_pool: &pool,
|
||||
};
|
||||
// let args = UpdateWeightArgs {
|
||||
// weight_token: &ModelWeightToken::new("test_token"),
|
||||
// title: Some("Test Title"),
|
||||
|
||||
// description_markdown: "Test Description Markdown",
|
||||
// description_rendered_html: "Test Description HTML",
|
||||
// creator_set_visibility: &Visibility::Public,
|
||||
// mysql_pool: &pool,
|
||||
// };
|
||||
|
||||
let result = update_weights(args).await;
|
||||
// let result = update_weights(args).await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
// assert!(result.is_ok());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
||||
Reference in new issue
Block a user