Bug 19515 - Refactor REST API session mocking to reduce code duplication
Summary: Refactor REST API session mocking to reduce code duplication
Status: CLOSED WORKSFORME
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Bugs List
QA Contact:
URL:
Keywords:
Depends on: 14539 19512
Blocks:
  Show dependency treegraph
 
Reported: 2017-10-23 12:29 UTC by Olli-Antti Kivilahti
Modified: 2020-06-04 20:32 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 19515 - Refactor REST API session mocking to reduce ridiculous amounts of duplication (20.81 KB, patch)
2017-10-23 12:30 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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.