Skip to content

Commit

Permalink
made tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
saad-deriv committed Oct 22, 2024
1 parent fd68cfa commit 7b2f708
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 57 deletions.
9 changes: 4 additions & 5 deletions lib/Data/Validate/Sanctions/Fetcher.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use XML::Fast;
use XML::Simple;
use Locale::Country;


use constant MAX_REDIRECTS => 3;
# VERSION

Expand Down Expand Up @@ -84,7 +83,7 @@ sub config {
url => $eu_url,
parser => \&_eu_xml,
},
'UNSC-Sanctions' => {
'UNSC-Sanctions' => {
description => 'UN: United Nations Security Council Consolidated List',
url => $args{unsc_url} || 'https://scsanctions.un.org/resources/xml/en/consolidated.xml',
parser => \&_unsc_xml,
Expand Down Expand Up @@ -454,8 +453,8 @@ sub _unsc_xml {

$entry{first_name} = $individual->{'FIRST_NAME'}[0];
$entry{second_name} = $individual->{'SECOND_NAME'}[0];
$entry{third_name} = $individual->{'THIRD_NAME'}[0] // '';
$entry{fourth_name} = $individual->{'FOURTH_NAME'}[0] // '';
$entry{third_name} = $individual->{'THIRD_NAME'}[0] // '';
$entry{fourth_name} = $individual->{'FOURTH_NAME'}[0] // '';
$entry{name_original_script} = $individual->{'NAME_ORIGINAL_SCRIPT'}[0] // '';

my @names = (
Expand Down Expand Up @@ -506,7 +505,7 @@ sub _unsc_xml {
place_of_birth => \@place_of_birth,
residence => \@residence,
nationality => \@nationality,
citizen => \@nationality, # no seprate field for citizenship in the XML
citizen => \@nationality, # no seprate field for citizenship in the XML
postal_code => \@postal_code,
national_id => \@national_id,
passport_no => \@passport_no,
Expand Down
78 changes: 32 additions & 46 deletions t/04_fetcher.t
Original file line number Diff line number Diff line change
Expand Up @@ -259,57 +259,43 @@ subtest 'OFAC Sanctions' => sub {

subtest 'UNSC Sanctions' => sub {
my $data = Data::Validate::Sanctions::Fetcher::run(%args);

my $source_name = 'UNSC-Sanctions';
ok $data->{$source_name}, 'Sanctions are loaded from the sample file';
is $data->{$source_name}{updated}, 1729123202, "Sanctions update date matches the content of sample file";
is scalar @{$data->{$source_name}{content}}, 7, "Number of names matches the content of the sample file";
is $data->{$source_name}{updated}, 1729123202, "Sanctions update date matches the content of sample file";
is scalar @{$data->{$source_name}{content}}, 7, "Number of names matches the content of the sample file";

is_deeply find_entry_by_name($data->{$source_name}, 'MOHAMMAD NAIM'),
{
'citizen' => [
'af'
],
'national_id' => [
[]
],
'place_of_birth' => [
'af'
],
'dob_year' => [
'1975'
],
'names' => [
'MOHAMMAD NAIM',
'BARICH',
'KHUDAIDAD',
"\x{645}\x{62d}\x{645}\x{62f} \x{646}\x{639}\x{64a}\x{645} \x{628}\x{631}\x{64a}\x{62e} \x{62e}\x{62f}\x{627}\x{64a}\x{62f}\x{627}\x{62f}",
'Mullah Naeem Barech',
'Mullah Naeem Baraich',
'Mullah Naimullah',
'Mullah Naim Bareh',
'Mohammad Naim',
'Mullah Naim Barich',
'Mullah Naim Barech',
'Mullah Naim Barech Akhund',
'Mullah Naeem Baric',
'Naim Berich',
'Haji Gul Mohammed Naim Barich',
'Gul Mohammad',
'Haji Ghul Mohammad',
'Spen Zrae',
'Gul Mohammad Kamran',
'Mawlawi Gul Mohammad'
],
'passport_no' => [
[]
],
'postal_code' => [
'63000'
],
'nationality' => [
'af'
]
'citizen' => ['af'],
'national_id' => [[]],
'place_of_birth' => ['af'],
'dob_year' => ['1975'],
'names' => [
'MOHAMMAD NAIM',
'BARICH',
'KHUDAIDAD',
"\x{645}\x{62d}\x{645}\x{62f} \x{646}\x{639}\x{64a}\x{645} \x{628}\x{631}\x{64a}\x{62e} \x{62e}\x{62f}\x{627}\x{64a}\x{62f}\x{627}\x{62f}",
'Mullah Naeem Barech',
'Mullah Naeem Baraich',
'Mullah Naimullah',
'Mullah Naim Bareh',
'Mohammad Naim',
'Mullah Naim Barich',
'Mullah Naim Barech',
'Mullah Naim Barech Akhund',
'Mullah Naeem Baric',
'Naim Berich',
'Haji Gul Mohammed Naim Barich',
'Gul Mohammad',
'Haji Ghul Mohammad',
'Spen Zrae',
'Gul Mohammad Kamran',
'Mawlawi Gul Mohammad'
],
'passport_no' => [[]],
'postal_code' => ['63000'],
'nationality' => ['af']
},
'Alias names as saved in a single entry';
};
Expand Down
10 changes: 5 additions & 5 deletions t/05_sanctions_redis.t
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ subtest 'Update Data' => sub {

# rewrite to redis if update (publish) time is changed
set_fixed_time(1600);
$mock_data->{'EU-Sanctions'}->{updated} = 91;
$mock_data->{'EU-Sanctions'}->{updated} = 91;
$mock_data->{'UNSC-Sanctions'}->{updated} = 91;
$validator->update_data();
$expected->{'EU-Sanctions'}->{updated} = 91;
$expected->{'EU-Sanctions'}->{updated} = 91;
$expected->{'UNSC-Sanctions'}->{updated} = 91;
$expected->{$_}->{verified} = 1600 for keys %$expected;
$expected->{$_}->{verified} = 1600 for keys %$expected;
is_deeply $validator->data, $expected, 'Data is loaded with new update time';
check_redis_content('EU-Sanctions', $mock_data->{'EU-Sanctions'}, 1600, 'Redis content changed by increased update time');
is $index_call_counter, 2, 'index called after update';
Expand Down Expand Up @@ -241,7 +241,7 @@ subtest 'Update Data' => sub {
]
},
};
$expected->{'EU-Sanctions'} = clone($mock_data->{'EU-Sanctions'});
$expected->{'EU-Sanctions'} = clone($mock_data->{'EU-Sanctions'});
$expected->{'UNSC-Sanctions'} = clone($mock_data->{'UNSC-Sanctions'});
set_fixed_time(1700);
$validator->update_data();
Expand Down Expand Up @@ -313,7 +313,7 @@ subtest 'load data' => sub {
content => [],
verified => 0,
updated => 0,
error => ''
error => ''
}};
is_deeply $validator->data, $expected, 'Sanction lists are loaded with default values when redis is empty';
is $validator->last_updated, 0, 'Updated date is zero';
Expand Down
2 changes: 1 addition & 1 deletion xt/20_update.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use File::Temp qw(tempfile);
use FindBin qw($Bin);
use File::stat;
use Path::Tiny;
use YAML::XS qw(Dump);
use YAML::XS qw(Dump);
use Test::MockTime qw(set_fixed_time);

my $sanction_file;
Expand Down

0 comments on commit 7b2f708

Please sign in to comment.