examples: move csv-test
* test validity of a given policy number * cli program will match via hashmap * hashmap is constructed from a csv file Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
../../../advotrackerd/data/POLLFNR_WOECHENTLICH.txt
|
|
||||||
1
advotracker/examples/csv-test/data/POLLFNR_WOECHENTLICH.txt
Symbolic link
1
advotracker/examples/csv-test/data/POLLFNR_WOECHENTLICH.txt
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../data/POLLFNR_WOECHENTLICH.txt
|
||||||
@@ -9,9 +9,12 @@ use chrono::{Local, DateTime};
|
|||||||
use locales::t;
|
use locales::t;
|
||||||
//use serde::{Deserialize, Serialize};
|
//use serde::{Deserialize, Serialize};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::env;
|
use std::{
|
||||||
use std::{error::Error, process};
|
collections::HashMap,
|
||||||
use std::collections::HashMap;
|
env,
|
||||||
|
{error::Error, process},
|
||||||
|
//path::{Path, PathBuf},
|
||||||
|
};
|
||||||
use tracing::{debug, trace, Level};
|
use tracing::{debug, trace, Level};
|
||||||
|
|
||||||
use advotracker::data::structures::{PolicyCode, PolicyList, PolicyDataList, PolicyData};
|
use advotracker::data::structures::{PolicyCode, PolicyList, PolicyDataList, PolicyData};
|
||||||
@@ -49,14 +52,6 @@ fn export(p: &mut String, lang: &String) -> Result<u64, Box<dyn Error>> {
|
|||||||
// Note: slash syntax also works on Windows!
|
// Note: slash syntax also works on Windows!
|
||||||
let path = Path::new(p);
|
let path = Path::new(p);
|
||||||
|
|
||||||
// only create files with a '.txt' extensions
|
|
||||||
//let extension = path.extension();
|
|
||||||
// match extension {
|
|
||||||
// //Some(String) => println!("file extension ok!"),
|
|
||||||
// //_ => extension = OsStr::new("txt")
|
|
||||||
// _ => println!("got file extension {:?}", extension)
|
|
||||||
// };
|
|
||||||
|
|
||||||
// open the file descriptor
|
// open the file descriptor
|
||||||
let mut file = File::create(path)?;
|
let mut file = File::create(path)?;
|
||||||
trace!(target: "csv-export", extension = ?path.extension(), file = ?file);
|
trace!(target: "csv-export", extension = ?path.extension(), file = ?file);
|
||||||
@@ -103,10 +98,6 @@ fn import(p: &mut String, data_list: &mut PolicyDataList,
|
|||||||
|
|
||||||
// must be a readable file
|
// must be a readable file
|
||||||
trace!(target: "csv-test", path = ?path);
|
trace!(target: "csv-test", path = ?path);
|
||||||
let valid = path.is_file();
|
|
||||||
println!("is_file: {}", valid);
|
|
||||||
|
|
||||||
//if let Some(res) = valid
|
|
||||||
assert_eq!(path.is_file(), true);
|
assert_eq!(path.is_file(), true);
|
||||||
|
|
||||||
// only accept files with '.txt' extensions
|
// only accept files with '.txt' extensions
|
||||||
@@ -333,8 +324,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
state = t!("state.started", lang);
|
state = t!("state.started", lang);
|
||||||
trace!(target: "csv-test", process = ?res, state = ?state);
|
trace!(target: "csv-test", process = ?res, state = ?state);
|
||||||
|
|
||||||
// importing policy code elements from csv-file
|
// create policy structures
|
||||||
let policy_list = PolicyList::new("Allianz Versicherungsnummen-List");
|
let policy_list = PolicyList::new("Allianz Versicherungsnummen-Liste");
|
||||||
println!("Policy List {:?} ", policy_list.name);
|
println!("Policy List {:?} ", policy_list.name);
|
||||||
|
|
||||||
let mut policy_data = PolicyDataList::new("Allianz-Import 20200628");
|
let mut policy_data = PolicyDataList::new("Allianz-Import 20200628");
|
||||||
@@ -355,9 +346,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test if policy_number is_valid
|
// test if policy_number is_valid
|
||||||
let test_policy_number = v.get::<i32>("test_policy_number").unwrap() as u64;
|
// type conversion (viperus String -> u64)
|
||||||
|
let test_policy_number = v.get::<String>("test_policy_number").unwrap().parse::<u64>().unwrap();
|
||||||
trace!(target: "csv-test", test_policy_number = ?test_policy_number);
|
trace!(target: "csv-test", test_policy_number = ?test_policy_number);
|
||||||
//let policy_number : u64 = 1999999999;
|
|
||||||
//match is_valid(&policy_number, &policy_data, &mut policy_numbers, &lang) {
|
//match is_valid(&policy_number, &policy_data, &mut policy_numbers, &lang) {
|
||||||
// Ok(true) => {
|
// Ok(true) => {
|
||||||
// use Hashmap method 'get' to check if we have the given key
|
// use Hashmap method 'get' to check if we have the given key
|
||||||
@@ -394,3 +385,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_policy_number() {
|
||||||
|
// Takes a reference and returns Option<&V>
|
||||||
|
let my_policy_numbers : [u64; 2] = [1511111111, 9999999993];
|
||||||
|
assert_eq!(my_policy_numbers, [1511111111, 9999999993]);
|
||||||
|
|
||||||
|
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
||||||
|
let mut csv_import_path = String::from("data/POLLFNR_TEST.txt");
|
||||||
|
|
||||||
|
let mut policy_data = PolicyDataList::new("PolicyDataList");
|
||||||
|
let mut policy_numbers : HashMap<u64, PolicyCode> = HashMap::new();
|
||||||
|
let lang = "en".to_string();
|
||||||
|
|
||||||
|
println!("import with Path: {:?} PolicyData: {:?} PolicyNumbers: {:?}, Lang: {:?}",
|
||||||
|
csv_import_path, policy_data, policy_numbers, lang);
|
||||||
|
let count = import(&mut csv_import_path, &mut policy_data,
|
||||||
|
&mut policy_numbers, &lang);
|
||||||
|
|
||||||
|
assert_eq!(count.unwrap(), 15498);
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ pub fn parse_args(v: &mut Viperus) -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
v.add_default("config_file", String::from("csv_import.ron"));
|
v.add_default("config_file", String::from("csv_import.ron"));
|
||||||
v.add_default("import_file", String::from("POLLFNR_WOECHENTLICH.txt"));
|
v.add_default("import_file", String::from("POLLFNR_WOECHENTLICH.txt"));
|
||||||
v.add_default("export_file", String::from(""));
|
v.add_default("export_file", String::from(""));
|
||||||
v.add_default("test_policy_number", 123456789);
|
v.add_default("test_policy_number", String::from("9999999992"));
|
||||||
v.add_default("to_email_address_file", String::from("Allianz RA-Hotline <smr-rahotline@allianz.de>"));
|
v.add_default("to_email_address_file", String::from("Allianz RA-Hotline <smr-rahotline@allianz.de>"));
|
||||||
v.add_default("from_email_address_file", String::from("Allianz-Hotline RA-Hiedemann <azhotline@hiedemann.de>"));
|
v.add_default("from_email_address_file", String::from("Allianz-Hotline RA-Hiedemann <azhotline@hiedemann.de>"));
|
||||||
//v.add_default("username", String::from("nctalkbot"));
|
//v.add_default("username", String::from("nctalkbot"));
|
||||||
@@ -188,7 +188,7 @@ SMR Unerledigt: 089 92529 60222")
|
|||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"test_policy_number: {:?}",
|
"test_policy_number: {:?}",
|
||||||
v.get::<i32>("test_policy_number").unwrap_or_default()
|
v.get::<String>("test_policy_number").unwrap_or_default()
|
||||||
);
|
);
|
||||||
// println!(
|
// println!(
|
||||||
// "username: {:?}",
|
// "username: {:?}",
|
||||||
|
|||||||
Reference in New Issue
Block a user