Bug 10653 - UT : C4::RotatingCollections.pm needs unit tests.
Summary: UT : C4::RotatingCollections.pm needs unit tests.
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Test Suite (show other bugs)
Version: master
Hardware: All All
: P5 - low normal (vote)
Assignee: kenza
QA Contact: Testopia
URL:
Keywords:
Depends on: 10642
Blocks:
  Show dependency treegraph
 
Reported: 2013-07-29 07:45 UTC by kenza
Modified: 2014-12-07 20:02 UTC (History)
6 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Who signed the patch off:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 10653: C4::RotatingCollections.pm needs unit tests (10.36 KB, patch)
2013-07-30 07:52 UTC, kenza
Details | Diff | Splinter Review
Bug 10653: C4::RotatingCollections.pm needs unit tests (10.35 KB, patch)
2013-07-30 11:45 UTC, kenza
Details | Diff | Splinter Review
Bug 10653: C4::RotatingCollections.pm needs unit tests (10.43 KB, patch)
2013-08-05 08:36 UTC, kenza
Details | Diff | Splinter Review
Bug 10642 : Inappropriate uses of $sth->finish() in C4::RotatingCollections.pm (4.39 KB, text/plain)
2013-08-08 09:00 UTC, kenza
Details
Bug 10653: C4::RotatingCollections.pm needs unit tests (9.97 KB, patch)
2013-08-08 09:22 UTC, kenza
Details | Diff | Splinter Review
Bug 10653: C4::RotatingCollections.pm needs unit tests (10.02 KB, patch)
2013-08-08 23:13 UTC, Chris Cormack
Details | Diff | Splinter Review
Bug 10653: C4::RotatingCollections.pm needs unit tests (10.09 KB, patch)
2013-08-16 15:58 UTC, Kyle M Hall
Details | Diff | Splinter Review

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