Skip to content

Commit

Permalink
cli: add tests for message filter settings interface
Browse files Browse the repository at this point in the history
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
  • Loading branch information
epilys committed Sep 1, 2024
1 parent f2163dd commit 07c8a68
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 93 deletions.
37 changes: 17 additions & 20 deletions mailpot-cli/tests/basic_interfaces.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
/*
* meli - email module
*
* Copyright 2019 Manos Pitsidianakis
*
* This file is part of meli.
*
* meli is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* meli is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
//
// This file is part of mailpot
//
// Copyright 2020 - Manos Pitsidianakis
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![deny(dead_code)]

Expand Down
155 changes: 155 additions & 0 deletions mailpot-cli/tests/message_filter_settings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
//
// This file is part of mailpot
//
// Copyright 2020 - Manos Pitsidianakis
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use assert_cmd::assert::OutputAssertExt;
use mailpot::{Configuration, Connection, SendMail};
use mailpot_tests::*;
use predicates::prelude::*;
use tempfile::TempDir;

#[test]
fn test_message_filter_settings_command() {
use assert_cmd::Command;

let tmp_dir = TempDir::new().unwrap();

let conf_path = tmp_dir.path().join("conf.toml");
let db_path = tmp_dir.path().join("mpot.db");
std::fs::copy("../mailpot-tests/for_testing.db", &db_path).unwrap();
let mut perms = std::fs::metadata(&db_path).unwrap().permissions();
#[allow(clippy::permissions_set_readonly_false)]
perms.set_readonly(false);
std::fs::set_permissions(&db_path, perms).unwrap();

let config = Configuration {
send_mail: SendMail::ShellCommand("/usr/bin/false".to_string()),
db_path,
data_path: tmp_dir.path().to_path_buf(),
administrators: vec![],
};
let db = Connection::open_or_create_db(config.clone())
.unwrap()
.trusted();
let list = db.lists().unwrap().remove(0);

let config_str = config.to_toml();

std::fs::write(&conf_path, config_str.as_bytes()).unwrap();

println!("Test print-message-filter-settings --show-available");
let mut cmd = Command::cargo_bin("mpot").unwrap();
let output = cmd
.arg("-vv")
.arg("-c")
.arg(&conf_path)
.arg("list")
.arg(&list.id)
.arg("print-message-filter-settings")
.arg("--show-available")
.output()
.unwrap()
.assert();
output.code(0).stderr(predicates::str::is_empty()).stdout(
predicate::eq("AddSubjectTagPrefixSettings\nArchivedAtLinkSettings\nMimeRejectSettings")
.trim()
.normalize(),
);

println!("Testing that inserting settings works…");
let mut cmd = Command::cargo_bin("mpot").unwrap();
let output = cmd
.arg("-vv")
.arg("-c")
.arg(&conf_path)
.arg("list")
.arg(&list.id)
.arg("set-message-filter-setting")
.arg("--name")
.arg("ArchivedAtLinkSettings")
.arg("--value")
.arg(
serde_json::to_string_pretty(&serde_json::json!({
"template": "https://www.example.com/{{msg_id}}.html",
"preserve_carets": false
}))
.unwrap(),
)
.output()
.unwrap()
.assert();
output.code(0).stderr(predicates::str::is_empty()).stdout(
predicate::eq("Successfully updated ArchivedAtLinkSettings value for list foobar chat.")
.trim()
.normalize(),
);

println!("Test print-message-filter-settings returns values");
let mut cmd = Command::cargo_bin("mpot").unwrap();
let output = cmd
.arg("-vv")
.arg("-c")
.arg(&conf_path)
.arg("list")
.arg(&list.id)
.arg("print-message-filter-settings")
.output()
.unwrap()
.assert();
output.code(0).stderr(predicates::str::is_empty()).stdout(
predicate::eq("ArchivedAtLinkSettings: {\"preserve_carets\":false,\"template\":\"https://www.example.com/{{msg_id}}.html\"}")
.trim()
.normalize(),
);

println!("Test print-message-filter-settings returns filtered values");
let mut cmd = Command::cargo_bin("mpot").unwrap();
let output = cmd
.arg("-vv")
.arg("-c")
.arg(&conf_path)
.arg("list")
.arg(&list.id)
.arg("print-message-filter-settings")
.arg("--filter")
.arg("archived")
.output()
.unwrap()
.assert();
output.code(0).stderr(predicates::str::is_empty()).stdout(
predicate::eq("ArchivedAtLinkSettings: {\"preserve_carets\":false,\"template\":\"https://www.example.com/{{msg_id}}.html\"}")
.trim()
.normalize(),
);
let mut cmd = Command::cargo_bin("mpot").unwrap();
let output = cmd
.arg("-vv")
.arg("-c")
.arg(&conf_path)
.arg("list")
.arg(&list.id)
.arg("print-message-filter-settings")
.arg("--filter")
.arg("aadfa")
.output()
.unwrap()
.assert();
output
.code(0)
.stderr(predicates::str::is_empty())
.stdout(predicate::eq("").trim().normalize());
}
37 changes: 17 additions & 20 deletions mailpot-cli/tests/out_queue_flush.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
/*
* meli - email module
*
* Copyright 2019 Manos Pitsidianakis
*
* This file is part of meli.
*
* meli is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* meli is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
//
// This file is part of mailpot
//
// Copyright 2020 - Manos Pitsidianakis
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use assert_cmd::assert::OutputAssertExt;
use mailpot::{
Expand Down
6 changes: 3 additions & 3 deletions mailpot-web/src/templates/css.html
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,9 @@
border-top: none;
}
div.post-reply-link {
padding-inline-start: 1em;
padding-block-end: 1em;
display: inline-block;
padding-inline-start: 1em;
padding-block-end: 1em;
display: inline-block;
}
td.message-id,
span.message-id{
Expand Down
8 changes: 5 additions & 3 deletions mailpot/build/make_migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@
/// the schema file.
///
/// Returns the current `user_version` PRAGMA value.
pub fn make_migrations<M: AsRef<Path>, O: AsRef<Path>>(
pub fn make_migrations<M: AsRef<::std::path::Path>, O: AsRef<::std::path::Path>>(
migrations_path: M,
output_file: O,
schema_file: &mut Vec<u8>,
) -> i32 {
use std::io::Write;

let migrations_folder_path = migrations_path.as_ref();
let output_file_path = output_file.as_ref();

let mut paths = vec![];
let mut undo_paths = vec![];
for entry in read_dir(migrations_folder_path).unwrap() {
for entry in ::std::fs::read_dir(migrations_folder_path).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if path.is_dir() || path.extension().map(|os| os.to_str().unwrap()) != Some("sql") {
Expand All @@ -56,7 +58,7 @@ pub fn make_migrations<M: AsRef<Path>, O: AsRef<Path>>(

paths.sort();
undo_paths.sort();
let mut migr_rs = OpenOptions::new()
let mut migr_rs = ::std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
Expand Down
2 changes: 1 addition & 1 deletion mailpot/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn main() {
let mut file = std::fs::File::create("./src/schema.sql").unwrap();
file.write_all(&output.stdout).unwrap();
file.write_all(
&format!("\n\n-- Set current schema version.\n\nPRAGMA user_version = {user_version};\n")
format!("\n\n-- Set current schema version.\n\nPRAGMA user_version = {user_version};\n")
.as_bytes(),
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion mailpot/tests/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use std::fs::{File, OpenOptions};
use std::{fs::File, io::Write};

use mailpot::{Configuration, Connection, SendMail};
use mailpot_tests::init_stderr_logging;
Expand Down
Loading

0 comments on commit 07c8a68

Please sign in to comment.