Bug 19515

Summary: Refactor REST API session mocking to reduce code duplication
Product: Koha Reporter: Olli-Antti Kivilahti <olli-antti.kivilahti>
Component: REST APIAssignee: Bugs List <koha-bugs>
Status: CLOSED WORKSFORME QA Contact:
Severity: enhancement    
Priority: P5 - low CC: m.de.rooy, tomascohen
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19512
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 14539, 19512    
Bug Blocks:    
Attachments: Bug 19515 - Refactor REST API session mocking to reduce ridiculous amounts of duplication

Description Olli-Antti Kivilahti 2017-10-23 12:29:20 UTC
The amount of duplication in REST API tests is beyond anything.

I must be hallucinating.

This adds a t::lib::Mocks::mock_session() which mocks a session reverting to defaults, and checks CGI::Session->flush for errors.
Comment 1 Olli-Antti Kivilahti 2017-10-23 12:30:33 UTC
Created attachment 68390 [details] [review]
Bug 19515 - Refactor REST API session mocking to reduce ridiculous amounts of duplication

The amount of duplication in REST API tests is beyond anything.

I must be hallucinating.

This adds a t::lib::Mocks::mock_session() which mocks a session reverting to
defaults, and checks CGI::Session->flush for errors.
Comment 2 Olli-Antti Kivilahti 2017-10-23 12:32:05 UTC
Please, stop this bad dream.
Comment 3 Marcel de Rooy 2017-10-23 13:26:33 UTC
Nice title
Comment 4 Olli-Antti Kivilahti 2017-10-23 16:33:20 UTC
(In reply to Marcel de Rooy from comment #3)
> Nice title
Comment 5 Tomás Cohen Arazi (tcohen) 2017-10-25 18:54:03 UTC
Hi Olli, good innitiative. Just some remarks:
- You patch covers several endpoints not currently in master, so it won't apply.
- It is way too much to make it dependent on the castToObject stuff, just a personal opinion: you can just my $patron = $builder->build_object({class=>'Koha::Patrons'}); to get a sample patron. This is already in master...
- You are missing something that's important for testing: we need to be able to assign the patron specific permissions, something in the lines of:
my $flags = ( $args->{authorized} ) ? 2**$args->{authorized} : 0;
Comment 6 Tomás Cohen Arazi (tcohen) 2017-10-25 19:03:45 UTC
> - You are missing something that's important for testing: we need to be able
> to assign the patron specific permissions, something in the lines of:
> my $flags = ( $args->{authorized} ) ? 2**$args->{authorized} : 0;

About this, this has been wrong in all submitted tests. I've implemented it correctly in bug 7317.
Comment 7 Tomás Cohen Arazi (tcohen) 2019-06-19 17:58:14 UTC
We have implemented Basic authentication, and it got really simple to test the API without this much trouble.