my
$sanction_file
;
my
$sanction_data
;
BEGIN {
set_fixed_time(1500);
$sanction_data
= Dump({
test1
=> {
updated
=>
time
,
content
=> [{
names
=> [
'ABCD'
],
}]}});
(
my
$fh
,
$sanction_file
) = tempfile();
print
$fh
$sanction_data
;
close
(
$fh
);
$ENV
{SANCTION_FILE} =
$sanction_file
;
}
is(get_sanction_file(),
$sanction_file
,
"sanction file is correct"
);
ok(is_sanctioned(
'ABCD'
),
"correct file content"
);
ok(!is_sanctioned(
'AAAA'
),
"correct file content"
);
my
$last_mtime
=
stat
(
$sanction_file
)->mtime;
path(
$sanction_file
)->spew(
'{}'
);
set_fixed_time(1500 + Data::Validate::Sanctions->IGNORE_OPERATION_INTERVAL);
my
$script
=
"$Bin/../bin/update_sanctions_csv"
;
my
$lib
=
"$Bin/../lib"
;
my
%args
= (
'-eu_url'
=>
"file://$Bin/../t/data/sample_eu.xml"
,
'-hmt_url'
=>
"file://$Bin/../t/data/sample_hmt.csv"
,
'-sanction_file'
=>
$sanction_file
//
''
);
is(
system
($^X,
"-I$lib"
,
$script
,
%args
), 0,
"download file successfully"
);
ok(
$last_mtime
<
stat
(
$sanction_file
)->mtime,
"mtime updated"
);
ok(!is_sanctioned(
'ABCD'
),
"correct file content"
);
$last_mtime
=
stat
(
$sanction_file
)->mtime;
ok(is_sanctioned(
'NEVEROV'
,
'Sergei Ivanovich'
, -253411200),
"correct file content"
);
path(
$sanction_file
)->spew(
$sanction_data
);
ok(
utime
(
$last_mtime
,
$last_mtime
,
$sanction_file
),
'change mtime to pretend the file not changed'
);
ok(is_sanctioned(
'NEVEROV'
,
'Sergei Ivanovich'
, -253411200),
"the module still use old data because it think the file is not changed"
);
ok(is_sanctioned(
'Sergei Ivanovich'
,
'NEVEROV'
, -253411200),
"Name matches regardless of order"
);
ok(is_sanctioned(
'Sergei Ivanovich1234~!@! '
,
'NEVEROV'
, -253411200),
"Name matches even if non-alphabets are present"
);
ok(is_sanctioned(
'Sergei Ivanovich1234~!@! '
,
'NEVEROV abcd'
, -253411200),
"Sanctioned when two words match"
);
ok(is_sanctioned(
'TestOneWord'
),
"Sanctioned when sanctioned individual has only one name (coming from t/data/sample_eu.xml)"
);
done_testing;