Bug 39345: Add COUNTER 5.1 Tests

JSON data files extracted from sample responses at:
https://counter5.cambridge.org/r51/sushi-docs/#/

Additional docs referenced:
https://cop5.projectcounter.org/en/5.1/appendices/g-sample-counter-reports-and-standard-views.html

Run:
prove t/db_dependent/Koha/ERM/EUsage/*

Signed-off-by: Eric Phetteplace <phette23@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit db5f51e4ce)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Pedro Amorim 2025-08-12 12:46:00 +00:00 committed by Paul Derscheid
parent c5938b5ab2
commit 85464856d8
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
8 changed files with 1865 additions and 0 deletions

View File

@ -0,0 +1,133 @@
#!/usr/bin/perl
# This file is part of Koha
#
# Koha 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.
#
# Koha 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 Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
# use Test::NoWarnings;
use Test::More tests => 2;
use Koha::Database;
use Koha::ERM::EUsage::CounterFile;
use JSON qw( decode_json );
use File::Basename qw( dirname );
use File::Slurp;
use t::lib::Mocks;
use t::lib::TestBuilder;
use Test::MockModule;
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $sushi_response_file_TR_J1 = dirname(__FILE__) . "/../../../../data/erm/eusage/COUNTER_5.1/TR_J1.json";
my $sushi_counter_51_response_TR_J1 = read_file($sushi_response_file_TR_J1);
my $sushi_counter_report_TR_J1 =
Koha::ERM::EUsage::SushiCounter->new( { response => decode_json($sushi_counter_51_response_TR_J1) } );
subtest 'store' => sub {
plan tests => 3;
$schema->storage->txn_begin;
my $patron = Koha::Patrons->search()->last;
t::lib::Mocks::mock_userenv( { number => $patron->borrowernumber } ); # Is superlibrarian
my $usage_data_provider = $builder->build_object(
{ class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } );
$usage_data_provider->{report_type} = 'TR_J1';
my $now_time = POSIX::strftime( "%Y%m%d%H%M%S", localtime );
my $counter_file = Koha::ERM::EUsage::CounterFile->new(
{
usage_data_provider_id => $usage_data_provider->erm_usage_data_provider_id,
file_content => $sushi_counter_report_TR_J1->get_COUNTER_from_SUSHI,
date_uploaded => $now_time,
filename => $usage_data_provider->name . "_" . $usage_data_provider->{report_type},
}
)->store;
# UsageTitles are added on CounterFile->store
my $titles_rs = Koha::ERM::EUsage::UsageTitles->search(
{ usage_data_provider_id => $usage_data_provider->erm_usage_data_provider_id } );
# MonthlyUsages are added on CounterFile->store
my $mus_rs = Koha::ERM::EUsage::MonthlyUsages->search(
{ usage_data_provider_id => $usage_data_provider->erm_usage_data_provider_id } );
# YearlyUsages are added on CounterFile->store
my $yus_rs = Koha::ERM::EUsage::YearlyUsages->search(
{ usage_data_provider_id => $usage_data_provider->erm_usage_data_provider_id } );
is( $titles_rs->count, 2, '2 titles were added' );
is( $mus_rs->count, 10, '10 monthly usages were added' );
is( $yus_rs->count, 4, '4 yearly usages were added' );
$schema->storage->txn_rollback;
#TODO: Test yop
#TODO: acccess_type
};
subtest '_get_rows_from_COUNTER_file' => sub {
plan tests => 4;
$schema->storage->txn_begin;
my $usage_data_provider = $builder->build_object(
{ class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } );
$usage_data_provider->{report_type} = 'TR_J1';
my $now_time = POSIX::strftime( "%Y%m%d%H%M%S", localtime );
my $counter_file = $builder->build_object(
{
class => 'Koha::ERM::EUsage::CounterFiles',
value => {
usage_data_provider_id => $usage_data_provider->erm_usage_data_provider_id,
file_content => $sushi_counter_report_TR_J1->get_COUNTER_from_SUSHI,
date_uploaded => $now_time,
filename => $usage_data_provider->name . "_" . $usage_data_provider->{report_type},
}
}
);
my $counter_file_rows = $counter_file->_get_rows_from_COUNTER_file;
is( ref $counter_file_rows, 'ARRAY', '_get_rows_from_COUNTER_file returns array' );
is(
scalar @{$counter_file_rows}, 4,
'_get_rows_from_COUNTER_file returns correct number of rows'
);
is(
@{$counter_file_rows}[0]->{Title}, 'Education and Training',
'first and second report row is about the same title'
);
is(
@{$counter_file_rows}[1]->{Title}, 'Education and Training',
'first and second report row is about the same title'
);
$schema->storage->txn_rollback;
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,101 @@
{
"Report_Header": {
"Release": "5.1",
"Report_ID": "TR_B2",
"Report_Name": "Book Access Denied",
"Created": "2023-02-15T09:11:12Z",
"Created_By": "Sample Publisher",
"Institution_ID": {
"ISNI": [
"1234123412341234"
]
},
"Institution_Name": "Sample Institution",
"Registry_Record": "https://registry.projectcounter.org/platform/99999999-9999-9999-9999-999999999999",
"Report_Filters": {
"Metric_Type": [
"Limit_Exceeded",
"No_License"
],
"Begin_Date": "2022-01-01",
"End_Date": "2022-03-31",
"Data_Type": [
"Book",
"Reference_Work"
],
"Access_Method": [
"Regular"
]
}
},
"Report_Items": [
{
"Title": "Title 1",
"Publisher": "Sample Publisher",
"Publisher_ID": {
"ISNI": [
"4321432143214321"
]
},
"Platform": "Platform 1",
"Item_ID": {
"DOI": "10.9999/xxxxt01",
"Proprietary": "P1:T01",
"ISBN": "979-8-88888-888-8",
"URI": "https://doi.org/10.9999/xxxxt01"
},
"Attribute_Performance": [
{
"Data_Type": "Book",
"YOP": "2022",
"Performance": {
"Limit_Exceeded": {
"2022-01": 49,
"2022-02": 90,
"2022-03": 40
},
"No_License": {
"2022-01": 50,
"2022-02": 84,
"2022-03": 47
}
}
}
]
},
{
"Title": "Title 7",
"Publisher": "Sample Publisher",
"Publisher_ID": {
"ISNI": [
"4321432143214321"
]
},
"Platform": "Platform 1",
"Item_ID": {
"DOI": "10.9999/xxxxt07",
"Proprietary": "P1:T07",
"ISBN": "979-8-88888-888-9",
"URI": "https://doi.org/10.9999/xxxxt07"
},
"Attribute_Performance": [
{
"Data_Type": "Reference_Work",
"YOP": "2019",
"Performance": {
"Limit_Exceeded": {
"2022-01": 84,
"2022-02": 84,
"2022-03": 49
},
"No_License": {
"2022-01": 70,
"2022-02": 74,
"2022-03": 54
}
}
}
]
}
]
}

View File

@ -0,0 +1,147 @@
{
"Report_Header": {
"Release": "5.1",
"Report_ID": "TR_B3",
"Report_Name": "Book Usage by Access Type",
"Created": "2023-02-15T09:11:12Z",
"Created_By": "Sample Publisher",
"Institution_ID": {
"ISNI": [
"1234123412341234"
]
},
"Institution_Name": "Sample Institution",
"Registry_Record": "https://registry.projectcounter.org/platform/99999999-9999-9999-9999-999999999999",
"Report_Filters": {
"Metric_Type": [
"Total_Item_Investigations",
"Total_Item_Requests",
"Unique_Item_Investigations",
"Unique_Item_Requests",
"Unique_Title_Investigations",
"Unique_Title_Requests"
],
"Begin_Date": "2022-01-01",
"End_Date": "2022-03-31",
"Data_Type": [
"Book",
"Reference_Work"
],
"Access_Method": [
"Regular"
]
}
},
"Report_Items": [
{
"Title": "Title 1",
"Publisher": "Sample Publisher",
"Publisher_ID": {
"ISNI": [
"4321432143214321"
]
},
"Platform": "Platform 1",
"Item_ID": {
"DOI": "10.9999/xxxxt01",
"Proprietary": "P1:T01",
"ISBN": "979-8-88888-888-8",
"URI": "https://doi.org/10.9999/xxxxt01"
},
"Attribute_Performance": [
{
"Data_Type": "Book",
"YOP": "2022",
"Access_Type": "Controlled",
"Performance": {
"Total_Item_Investigations": {
"2022-01": 1104,
"2022-02": 1246,
"2022-03": 1329
},
"Total_Item_Requests": {
"2022-01": 662,
"2022-02": 748,
"2022-03": 797
},
"Unique_Item_Investigations": {
"2022-01": 828,
"2022-02": 935,
"2022-03": 997
},
"Unique_Item_Requests": {
"2022-01": 497,
"2022-02": 561,
"2022-03": 598
},
"Unique_Title_Investigations": {
"2022-01": 552,
"2022-02": 623,
"2022-03": 665
},
"Unique_Title_Requests": {
"2022-01": 414,
"2022-02": 467,
"2022-03": 499
}
}
}
]
},
{
"Title": "Title 7",
"Publisher": "Sample Publisher",
"Publisher_ID": {
"ISNI": [
"4321432143214321"
]
},
"Platform": "Platform 1",
"Item_ID": {
"DOI": "10.9999/xxxxt07",
"Proprietary": "P1:T07",
"ISBN": "979-8-88888-888-9",
"URI": "https://doi.org/10.9999/xxxxt07"
},
"Attribute_Performance": [
{
"Data_Type": "Reference_Work",
"YOP": "2019",
"Access_Type": "Controlled",
"Performance": {
"Total_Item_Investigations": {
"2022-01": 1645,
"2022-02": 1022,
"2022-03": 1106
},
"Total_Item_Requests": {
"2022-01": 987,
"2022-02": 613,
"2022-03": 664
},
"Unique_Item_Investigations": {
"2022-01": 1234,
"2022-02": 767,
"2022-03": 830
},
"Unique_Item_Requests": {
"2022-01": 740,
"2022-02": 460,
"2022-03": 498
},
"Unique_Title_Investigations": {
"2022-01": 301,
"2022-02": 283,
"2022-03": 217
},
"Unique_Title_Requests": {
"2022-01": 226,
"2022-02": 212,
"2022-03": 163
}
}
}
]
}
]
}

View File

@ -0,0 +1,104 @@
{
"Report_Header": {
"Release": "5.1",
"Report_ID": "TR_J1",
"Report_Name": "Journal Requests (Excluding OA_Gold)",
"Created": "2023-08-29T07:11:41Z",
"Created_By": "Test Systems Inc.",
"Institution_ID": {
"Proprietary": [
"TInsti:EALTEST001"
],
"ISNI": [
"0000000123456789"
]
},
"Institution_Name": "Test Institution",
"Registry_Record": "https://registry.projectcounter.org/platform/99999999-9999-9999-9999-999999999999",
"Report_Filters": {
"Metric_Type": [
"Total_Item_Requests",
"Unique_Item_Requests"
],
"Begin_Date": "2021-09-01",
"End_Date": "2022-09-30",
"Data_Type": [
"Journal"
],
"Access_Type": [
"Controlled"
],
"Access_Method": [
"Regular"
],
"Data_Type": [
"Journal"
]
}
},
"Report_Items": [
{
"Title": "Education and Training",
"Publisher": "Sample Publisher",
"Publisher_ID": {
"ISNI": [
"4321432143214321"
]
},
"Platform": "Platform 1",
"Item_ID": {
"DOI": "10.9999/xxxxt03",
"Proprietary": "P1:T03",
"Online_ISSN": "1234-4321",
"URI": "https://doi.org/10.9999/xxxxt03"
},
"Attribute_Performance": [
{
"Performance": {
"Total_Item_Requests": {
"2022-01": 526,
"2022-02": 866,
"2022-03": 852
},
"Unique_Item_Requests": {
"2022-01": 226,
"2022-02": 372,
"2022-03": 366
}
}
}
]
},
{
"Title": "Test Journal",
"Publisher": "Test Publisher",
"Publisher_ID": {
"ISNI": [
"0000000123456789"
]
},
"Platform": "Unit Test Library",
"Item_ID": {
"DOI": "10.1002/(ISSN)1111-2222",
"Proprietary": "TInsti:ABC1",
"Online_ISSN": "5555-6666",
"URI": "https://doi.org/10.9999/xxxxt03",
"Print_ISSN": "7777-8888"
},
"Attribute_Performance": [
{
"Performance": {
"Total_Item_Requests": {
"2022-01": 1,
"2022-06": 1
},
"Unique_Item_Requests": {
"2022-01": 1,
"2022-06": 1
}
}
}
]
}
]
}

View File

@ -0,0 +1,96 @@
{
"Report_Header": {
"Release": "5.1",
"Report_ID": "TR_J2",
"Report_Name": "Journal Access Denied",
"Created": "2023-02-15T09:11:12Z",
"Created_By": "Sample Publisher",
"Institution_ID": {
"ISNI": [
"1234123412341234"
]
},
"Institution_Name": "Sample Institution",
"Registry_Record": "https://registry.projectcounter.org/platform/99999999-9999-9999-9999-999999999999",
"Report_Filters": {
"Metric_Type": [
"Limit_Exceeded",
"No_License"
],
"Begin_Date": "2022-01-01",
"End_Date": "2022-03-31",
"Data_Type": [
"Journal"
],
"Access_Method": [
"Regular"
]
}
},
"Report_Items": [
{
"Title": "Title 3",
"Publisher": "Sample Publisher",
"Publisher_ID": {
"ISNI": [
"4321432143214321"
]
},
"Platform": "Platform 1",
"Item_ID": {
"DOI": "10.9999/xxxxt03",
"Proprietary": "P1:T03",
"Online_ISSN": "1234-4321",
"URI": "https://doi.org/10.9999/xxxxt03"
},
"Attribute_Performance": [
{
"Performance": {
"Limit_Exceeded": {
"2022-01": 174,
"2022-02": 176,
"2022-03": 90
},
"No_License": {
"2022-01": 96,
"2022-02": 160,
"2022-03": 74
}
}
}
]
},
{
"Title": "Another title",
"Publisher": "Another publisher",
"Publisher_ID": {
"ISNI": [
"4321432143214321"
]
},
"Platform": "Platform 1",
"Item_ID": {
"DOI": "10.9999/xxxxt03",
"Proprietary": "P1:T03",
"Online_ISSN": "1234-4321",
"URI": "https://doi.org/10.9999/xxxxt03"
},
"Attribute_Performance": [
{
"Performance": {
"Limit_Exceeded": {
"2022-01": 222,
"2022-02": 111,
"2022-03": 55
},
"No_License": {
"2022-01": 11,
"2022-02": 22,
"2022-03": 33
}
}
}
]
}
]
}

View File

@ -0,0 +1,170 @@
{
"Report_Header": {
"Release": "5.1",
"Report_ID": "TR_J3",
"Report_Name": "Journal Usage by Access Type",
"Created": "2023-02-15T09:11:12Z",
"Created_By": "Sample Publisher",
"Institution_ID": {
"ISNI": [
"1234123412341234"
]
},
"Institution_Name": "Sample Institution",
"Registry_Record": "https://registry.projectcounter.org/platform/99999999-9999-9999-9999-999999999999",
"Report_Filters": {
"Metric_Type": [
"Total_Item_Investigations",
"Total_Item_Requests",
"Unique_Item_Investigations",
"Unique_Item_Requests"
],
"Begin_Date": "2022-01-01",
"End_Date": "2022-03-31",
"Data_Type": [
"Journal"
],
"Access_Method": [
"Regular"
]
}
},
"Report_Items": [
{
"Title": "Title 3",
"Publisher": "Sample Publisher",
"Publisher_ID": {
"ISNI": [
"4321432143214321"
]
},
"Platform": "Platform 1",
"Item_ID": {
"DOI": "10.9999/xxxxt03",
"Proprietary": "P1:T03",
"Online_ISSN": "1234-4321",
"URI": "https://doi.org/10.9999/xxxxt03"
},
"Attribute_Performance": [
{
"Access_Type": "Controlled",
"Performance": {
"Total_Item_Investigations": {
"2022-01": 500,
"2022-02": 824,
"2022-03": 812
},
"Total_Item_Requests": {
"2022-01": 300,
"2022-02": 494,
"2022-03": 486
},
"Unique_Item_Investigations": {
"2022-01": 376,
"2022-02": 618,
"2022-03": 608
},
"Unique_Item_Requests": {
"2022-01": 226,
"2022-02": 372,
"2022-03": 366
}
}
},
{
"Access_Type": "Open",
"Performance": {
"Total_Item_Investigations": {
"2022-01": 1504,
"2022-02": 2476,
"2022-03": 2434
},
"Total_Item_Requests": {
"2022-01": 902,
"2022-02": 1486,
"2022-03": 1462
},
"Unique_Item_Investigations": {
"2022-01": 1128,
"2022-02": 1858,
"2022-03": 1826
},
"Unique_Item_Requests": {
"2022-01": 676,
"2022-02": 1114,
"2022-03": 1096
}
}
}
]
},
{
"Title": "Title 4",
"Publisher": "Sample Publisher",
"Publisher_ID": {
"ISNI": [
"4321432143214321"
]
},
"Platform": "Platform 1",
"Item_ID": {
"DOI": "10.9999",
"Proprietary": "P1:T03",
"Online_ISSN": "1234-4321",
"URI": "https://doi.org/10.9999"
},
"Attribute_Performance": [
{
"Access_Type": "Controlled",
"Performance": {
"Total_Item_Investigations": {
"2022-01": 3,
"2022-02": 4,
"2022-03": 9
},
"Total_Item_Requests": {
"2022-01": 55,
"2022-02": 44,
"2022-03": 33
},
"Unique_Item_Investigations": {
"2022-01": 88,
"2022-02": 55,
"2022-03": 77
},
"Unique_Item_Requests": {
"2022-01": 22,
"2022-02": 33,
"2022-03": 44
}
}
},
{
"Access_Type": "Open",
"Performance": {
"Total_Item_Investigations": {
"2022-01": 55,
"2022-02": 76,
"2022-03": 12
},
"Total_Item_Requests": {
"2022-01": 65,
"2022-02": 34,
"2022-03": 87
},
"Unique_Item_Investigations": {
"2022-01": 12,
"2022-02": 66,
"2022-03": 88
},
"Unique_Item_Requests": {
"2022-01": 45,
"2022-02": 23,
"2022-03": 76
}
}
}
]
}
]
}

View File

@ -0,0 +1,83 @@
{
"Report_Header": {
"Release": "5.1",
"Report_ID": "TR_J4",
"Report_Name": "Journal Requests by YOP (Controlled)",
"Created": "2023-02-15T09:11:12Z",
"Created_By": "Sample Publisher",
"Institution_ID": {
"ISNI": [
"1234123412341234"
]
},
"Institution_Name": "Sample Institution",
"Registry_Record": "https://registry.projectcounter.org/platform/99999999-9999-9999-9999-999999999999",
"Report_Filters": {
"Metric_Type": [
"Total_Item_Requests",
"Unique_Item_Requests"
],
"Begin_Date": "2022-01-01",
"End_Date": "2022-03-31",
"Data_Type": [
"Journal"
],
"Access_Type": [
"Controlled"
],
"Access_Method": [
"Regular"
]
}
},
"Report_Items": [
{
"Title": "Title 3",
"Publisher": "Sample Publisher",
"Publisher_ID": {
"ISNI": [
"4321432143214321"
]
},
"Platform": "Platform 1",
"Item_ID": {
"DOI": "10.9999/xxxxt03",
"Proprietary": "P1:T03",
"Online_ISSN": "1234-4321",
"URI": "https://doi.org/10.9999/xxxxt03"
},
"Attribute_Performance": [
{
"YOP": "2022",
"Performance": {
"Total_Item_Requests": {
"2022-01": 150,
"2022-02": 247,
"2022-03": 243
},
"Unique_Item_Requests": {
"2022-01": 113,
"2022-02": 186,
"2022-03": 183
}
}
},
{
"YOP": "2021",
"Performance": {
"Total_Item_Requests": {
"2022-01": 150,
"2022-02": 247,
"2022-03": 243
},
"Unique_Item_Requests": {
"2022-01": 113,
"2022-02": 186,
"2022-03": 183
}
}
}
]
}
]
}