Fix tests with testdata

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/13/head
trivernis 3 years ago
parent ed2c8f9e0a
commit 7ef1ec6c59
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,4 +1,6 @@
use super::super::common;
use crate::common;
use crate::common::create_testdata;
use crate::common::test_data::get_test_hashes;
#[tokio::test]
async fn it_adds_files() {
@ -20,23 +22,26 @@ async fn it_adds_binary_files() {
#[tokio::test]
async fn it_deletes_files() {
let client = common::get_client();
client.delete_files(vec![]).await.unwrap();
client.delete_files(get_test_hashes()).await.unwrap();
}
#[tokio::test]
async fn it_undeletes_files() {
let client = common::get_client();
client.undelete_files(vec![]).await.unwrap();
create_testdata(&client).await;
client.undelete_files(get_test_hashes()).await.unwrap();
}
#[tokio::test]
async fn it_archives_files() {
let client = common::get_client();
client.archive_files(vec![]).await.unwrap();
create_testdata(&client).await;
client.archive_files(get_test_hashes()).await.unwrap();
}
#[tokio::test]
async fn it_unarchives_files() {
let client = common::get_client();
client.unarchive_files(vec![]).await.unwrap();
create_testdata(&client).await;
client.unarchive_files(get_test_hashes()).await.unwrap();
}

@ -1,4 +1,5 @@
use super::super::common;
use crate::common::test_data::EMPTY_HASH;
use hydrus_api::api_core::adding_tags::{AddTagsRequestBuilder, TagAction};
use hydrus_api::api_core::common::ServiceIdentifier;
@ -22,7 +23,7 @@ async fn it_adds_tags() {
#![allow(deprecated)]
let client = common::get_client();
let request = AddTagsRequestBuilder::default()
.add_hash("0000000000000000000000000000000000000000000000000000000000000000") // valid hash, I hope no files are affected
.add_hash(EMPTY_HASH) // valid hash, I hope no files are affected
.add_tags(
ServiceIdentifier::name("my tags"),
vec!["beach".into(), "summer".into()],

@ -1,14 +1,12 @@
use super::super::common;
use crate::common::test_data::{get_test_hashes, get_test_urls, TEST_URL_1};
use hydrus_api::api_core::adding_urls::{AddUrlRequestBuilder, URL_TYPE_POST};
use hydrus_api::api_core::common::ServiceIdentifier;
#[tokio::test]
async fn it_returns_files_for_an_url() {
let client = common::get_client();
let response = client
.get_url_files("https://www.pixiv.net/member_illust.php?illust_id=83406361&mode=medium")
.await
.unwrap();
let response = client.get_url_files(TEST_URL_1).await.unwrap();
assert!(response.normalised_url.len() > 0);
}
@ -16,10 +14,7 @@ async fn it_returns_files_for_an_url() {
#[tokio::test]
async fn it_returns_url_information() {
let client = common::get_client();
let info = client
.get_url_info("https://www.pixiv.net/member_illust.php?illust_id=83406361&mode=medium")
.await
.unwrap();
let info = client.get_url_info(TEST_URL_1).await.unwrap();
assert!(info.normalised_url.len() > 0);
assert_eq!(info.url_type, URL_TYPE_POST);
}
@ -29,7 +24,7 @@ async fn it_adds_urls() {
#![allow(deprecated)]
let client = common::get_client();
let request = AddUrlRequestBuilder::default()
.url("https://www.pixiv.net/member_illust.php?illust_id=83406361&mode=medium")
.url(TEST_URL_1)
.add_tags(
ServiceIdentifier::name("my tags"),
vec!["ark mage".to_string(), "grinning".to_string()],
@ -44,14 +39,9 @@ async fn it_adds_urls() {
#[tokio::test]
async fn it_associates_urls() {
let client = common::get_client();
common::create_testdata(&client).await;
client
.associate_urls(
vec![
"https://www.pixiv.net/member_illust.php?illust_id=83406361&mode=medium"
.to_string(),
],
vec!["0000000000000000000000000000000000000000000000000000000000000000".to_string()],
)
.associate_urls(get_test_urls(), get_test_hashes())
.await
.unwrap();
}
@ -59,14 +49,9 @@ async fn it_associates_urls() {
#[tokio::test]
async fn it_disassociates_urls() {
let client = common::get_client();
common::create_testdata(&client).await;
client
.disassociate_urls(
vec![
"https://www.pixiv.net/member_illust.php?illust_id=83406361&mode=medium"
.to_string(),
],
vec!["0000000000000000000000000000000000000000000000000000000000000000".to_string()],
)
.disassociate_urls(get_test_urls(), get_test_hashes())
.await
.unwrap();
}

@ -1,8 +1,11 @@
use hydrus_api::api_core::adding_urls::AddUrlRequestBuilder;
use hydrus_api::api_core::client::Client;
use hydrus_api::Hydrus;
use std::env;
use std::sync::{Arc, Mutex, MutexGuard};
use std::time::Duration;
use test_data::TEST_URLS;
pub mod test_data;
pub fn setup() {
lazy_static::lazy_static! { static ref SETUP_DONE: Arc<Mutex<bool>> = Arc::new(Mutex::new(false)); }
@ -30,3 +33,12 @@ pub fn get_hydrus() -> Hydrus {
Hydrus::new(client)
}
pub async fn create_testdata(client: &Client) {
for url in TEST_URLS {
client
.add_url(AddUrlRequestBuilder::default().url(url).build())
.await
.unwrap();
}
}

@ -0,0 +1,17 @@
pub const TEST_HASH_1: &str = "277a138cd1ee79fc1fdb2869c321b848d4861e45b82184487139ef66dd40b62d";
pub const TEST_HASH_2: &str = "9641a590e66d9f2e5137b6bcba07fdf6cec3ffaa54de2565c3afcc2125ad1160";
pub const EMPTY_HASH: &str = "0000000000000000000000000000000000000000000000000000000000000000";
pub const TEST_HASHES: &[&str] = &[TEST_HASH_1, TEST_HASH_2];
pub const TEST_URL_1: &str =
"https://www.pixiv.net/member_illust.php?illust_id=83406361&mode=medium";
pub const TEST_URL_2: &str = "https://yande.re/post/show/923576";
pub const TEST_URLS: &[&str] = &[TEST_URL_1, TEST_URL_2];
pub fn get_test_hashes() -> Vec<String> {
TEST_HASHES.iter().map(|h| String::from(*h)).collect()
}
pub fn get_test_urls() -> Vec<String> {
TEST_URLS.iter().map(|u| String::from(*u)).collect()
}
Loading…
Cancel
Save