|
Lines 42-83
my $sushi_counter_5_response_TR_J1 = read_file($sushi_response_file_TR_J1);
Link Here
|
| 42 |
my $sushi_counter_report_TR_J1 = |
42 |
my $sushi_counter_report_TR_J1 = |
| 43 |
Koha::ERM::EUsage::SushiCounter->new( { response => decode_json($sushi_counter_5_response_TR_J1) } ); |
43 |
Koha::ERM::EUsage::SushiCounter->new( { response => decode_json($sushi_counter_5_response_TR_J1) } ); |
| 44 |
|
44 |
|
| 45 |
my $usage_data_provider_module = Test::MockModule->new('Koha::ERM::EUsage::UsageDataProvider'); |
45 |
my $ua = Test::MockModule->new('LWP::UserAgent'); |
| 46 |
|
46 |
$ua->mock( |
| 47 |
# Mock harvest_sushi to have data coming from TR_J1.json act as a SUSHI response |
47 |
'simple_request', |
| 48 |
$usage_data_provider_module->mock( |
|
|
| 49 |
'harvest_sushi', |
| 50 |
sub { |
48 |
sub { |
| 51 |
my ( $self, $args ) = @_; |
49 |
my $response = Test::MockObject->new(); |
| 52 |
|
|
|
| 53 |
# Set class wide vars |
| 54 |
$self->{report_type} = $args->{report_type}; |
| 55 |
$self->{begin_date} = $args->{begin_date}; |
| 56 |
$self->{end_date} = $args->{end_date}; |
| 57 |
my $response = $sushi_counter_5_response_TR_J1; |
| 58 |
|
| 59 |
my $decoded_response = decode_json($response); |
| 60 |
|
| 61 |
return if $self->_sushi_errors($decoded_response); |
| 62 |
|
| 63 |
# Parse the SUSHI response |
| 64 |
my $sushi_counter = Koha::ERM::EUsage::SushiCounter->new( { response => $decoded_response } ); |
| 65 |
my $counter_file = $sushi_counter->get_COUNTER_from_SUSHI; |
| 66 |
|
50 |
|
| 67 |
return if $self->_counter_file_size_too_large($counter_file); |
51 |
$response->mock( |
| 68 |
|
52 |
'code', |
| 69 |
$self->counter_files( |
53 |
sub { |
| 70 |
[ |
54 |
return 200; |
| 71 |
{ |
55 |
} |
| 72 |
usage_data_provider_id => $self->erm_usage_data_provider_id, |
56 |
); |
| 73 |
file_content => $counter_file, |
57 |
$response->mock( |
| 74 |
date_uploaded => POSIX::strftime( "%Y%m%d%H%M%S", localtime ), |
58 |
'is_error', |
| 75 |
|
59 |
sub { |
| 76 |
#TODO: add ".csv" to end of filename here |
60 |
return 0; |
| 77 |
filename => $self->name . "_" . $self->{report_type}, |
61 |
} |
| 78 |
} |
62 |
); |
| 79 |
] |
63 |
$response->mock( |
|
|
64 |
'is_redirect', |
| 65 |
sub { |
| 66 |
return 0; |
| 67 |
} |
| 68 |
); |
| 69 |
$response->mock( |
| 70 |
'decoded_content', |
| 71 |
sub { |
| 72 |
return $sushi_counter_5_response_TR_J1; |
| 73 |
} |
| 80 |
); |
74 |
); |
|
|
75 |
$response->{_rc} = 200; |
| 76 |
return $response; |
| 81 |
} |
77 |
} |
| 82 |
); |
78 |
); |
| 83 |
|
79 |
|
| 84 |
- |
|
|