Bug 10653

Summary: UT : C4::RotatingCollections.pm needs unit tests.
Product: Koha Reporter: kenza <kenza.zaki>
Component: Test SuiteAssignee: kenza <kenza.zaki>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: bgkriegel, chrish, gmcharlt, kenza.zaki, srdjan, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on: 10642    
Bug Blocks:    
Attachments: Bug 10653: C4::RotatingCollections.pm needs unit tests
Bug 10653: C4::RotatingCollections.pm needs unit tests
Bug 10653: C4::RotatingCollections.pm needs unit tests
Bug 10642 : Inappropriate uses of $sth->finish() in C4::RotatingCollections.pm
Bug 10653: C4::RotatingCollections.pm needs unit tests
Bug 10653: C4::RotatingCollections.pm needs unit tests
Bug 10653: C4::RotatingCollections.pm needs unit tests

Description kenza 2013-07-29 07:45:19 UTC

    
Comment 1 kenza 2013-07-30 07:52:26 UTC Comment hidden (obsolete)
Comment 2 kenza 2013-07-30 11:45:43 UTC Comment hidden (obsolete)
Comment 3 Srdjan Jankovic 2013-07-31 02:15:41 UTC
t/db_dependent/RotatingCollections.t .. 1/41 DBD::mysql::db do failed: Cannot delete or update a parent row: a foreign key constraint fails (`koha`.`issues`, CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON UPDATE CASCADE) at t/db_dependent/RotatingCollections.t line 41.
DBD::mysql::db do failed: Cannot delete or update a parent row: a foreign key constraint fails (`koha`.`issues`, CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON UPDATE CASCADE) at t/db_dependent/RotatingCollections.t line 41.

Is my db out of sync?
Comment 4 kenza 2013-07-31 08:07:57 UTC
(In reply to Srdjan Jankovic from comment #3)
> t/db_dependent/RotatingCollections.t .. 1/41 DBD::mysql::db do failed:
> Cannot delete or update a parent row: a foreign key constraint fails
> (`koha`.`issues`, CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`)
> REFERENCES `borrowers` (`borrowernumber`) ON UPDATE CASCADE) at
> t/db_dependent/RotatingCollections.t line 41.
> DBD::mysql::db do failed: Cannot delete or update a parent row: a foreign
> key constraint fails (`koha`.`issues`, CONSTRAINT `issues_ibfk_1` FOREIGN
> KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON UPDATE
> CASCADE) at t/db_dependent/RotatingCollections.t line 41.
> 
> Is my db out of sync?

I just try and indeed if i just do prove t/db_dependent/RotatingCollections.t , i have the same errors. But if i'm in root or if i do sudo prove t/db_dependent/RotatingCollections.t, it works! I really don't understand why. I'll try to fix this problem...
Comment 5 kenza 2013-08-05 08:36:15 UTC Comment hidden (obsolete)
Comment 6 kenza 2013-08-05 08:45:33 UTC
(In reply to kenza from comment #5)
> Created attachment 20106 [details] [review] [review]
> Bug 10653: C4::RotatingCollections.pm needs unit tests
> 
> The tests are wrap in a database transaction.
> 
> Test plan:
> prove t/db_dependent/RotatingCollections.t
> t/db_dependent/RotatingCollections.t .. 1/41 attempting to use non-existent
> class sorting routine
> Use of uninitialized value $cn_class in concatenation (.) or string at
> C4/ClassSortRoutine.pm line 118.
> Use of uninitialized value $cn_item in concatenation (.) or string at
> C4/ClassSortRoutine.pm line 118.
> Use of uninitialized value $cn_class in concatenation (.) or string at
> C4/ClassSortRoutine.pm line 118.
> Use of uninitialized value $cn_item in concatenation (.) or string at
> C4/ClassSortRoutine.pm line 118.
> t/db_dependent/RotatingCollections.t .. ok
> All tests successful.
> Files=1, Tests=41,  2 wallclock secs ( 0.04 usr  0.02 sys +  0.99 cusr  0.08
> csys =  1.13 CPU)
> Result: PASS

I add the deletion of 'categories' ,'branches' and 'branchcategories'. It should work but it still not:
if i do :
prove t/db_dependent/RotatingCollections.t 

t/db_dependent/RotatingCollections.t .. 1/41 DBD::mysql::db do failed: Cannot delete or update a parent row: a foreign key constraint fails (`koha`.`borrowers`, CONSTRAINT `borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)) at t/db_dependent/RotatingCollections.t line 41.
DBD::mysql::db do failed: Cannot delete or update a parent row: a foreign key constraint fails (`koha`.`borrowers`, CONSTRAINT `borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)) at t/db_dependent/RotatingCollections.t line 41.
# Looks like you planned 41 tests but ran 2.
# Looks like your test exited with 255 just after 2.
t/db_dependent/RotatingCollections.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 39/41 subtests 

Test Summary Report
-------------------
t/db_dependent/RotatingCollections.t (Wstat: 65280 Tests: 2 Failed: 0)
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 41 tests but ran 2.
Files=1, Tests=2,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.34 cusr  0.02 csys =  0.38 CPU)
Result: FAIL


But if i do:
 sudo prove t/db_dependent/RotatingCollections.t 
t/db_dependent/RotatingCollections.t .. 1/41 attempting to use non-existent class sorting routine 
Use of uninitialized value $cn_class in concatenation (.) or string at C4/ClassSortRoutine.pm line 118.
Use of uninitialized value $cn_item in concatenation (.) or string at C4/ClassSortRoutine.pm line 118.
Use of uninitialized value $cn_class in concatenation (.) or string at C4/ClassSortRoutine.pm line 118.
Use of uninitialized value $cn_item in concatenation (.) or string at C4/ClassSortRoutine.pm line 118.
t/db_dependent/RotatingCollections.t .. ok     
All tests successful.
Files=1, Tests=41,  1 wallclock secs ( 0.02 usr  0.00 sys +  0.37 cusr  0.00 csys =  0.39 CPU)
Result: PASS

I really don't understand ! So if someone has an idea which can help me...
Comment 7 Srdjan Jankovic 2013-08-06 05:13:43 UTC
That's because you have DELETE FROM branches.
You can try placing DELETE FROM borrowers before branches, but then you'll have problems with issues. And if you add DELETE FROM issues it will take forever to do that.
I think that deleting from base tables is a bad idea. Unlike deleting from specific purpose tables, eg issuingrules, which is ok.
I can see that test have progressed in the past couple of years, so this may not be relevant, but what I used to do is either:
a) create my own data
b) use random existing data, ie SELECT * FROM branches WHERE some_condition ORDER BY random, and take the top one; some_condition is eg has borrowers etc.
Comment 8 kenza 2013-08-08 09:00:49 UTC Comment hidden (obsolete)
Comment 9 kenza 2013-08-08 09:22:53 UTC Comment hidden (obsolete)
Comment 10 Chris Cormack 2013-08-08 23:13:39 UTC Comment hidden (obsolete)
Comment 11 Kyle M Hall 2013-08-16 15:58:51 UTC
Created attachment 20424 [details] [review]
Bug 10653: C4::RotatingCollections.pm needs unit tests

The tests are wrap in a database transaction.

Test plan:
prove t/db_dependent/RotatingCollections.t
t/db_dependent/RotatingCollections.t .. ok
All tests successful.
Files=1, Tests=41, 20 wallclock secs ( 0.02 usr  0.01 sys +  0.41 cusr  0.02 csys =  0.46 CPU)
Result: PASS

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 12 Galen Charlton 2013-08-16 16:10:48 UTC
Pushed to master along with a follow-up.  Thanks, Kenza!
Comment 13 Tomás Cohen Arazi 2013-09-11 17:56:22 UTC
This patch has been pushed to 3.12.x, will be in 3.12.5.

Thanks Kenza!
Comment 14 Bernardo Gonzalez Kriegel 2013-09-14 22:38:30 UTC
Pushed to 3.10.x, will be in 3.10.11
Comment 15 Chris Hall 2013-10-21 19:32:27 UTC
Pushed to 3.8.x, will be in 3.8.19.