Archive for December, 2008

Koha Test Cases

Sunday, December 28th, 2008 by Allen Reinmeyer

Since Andrew Moore has already done some great work on building up Koha’s test suite for C4 classes, I thought I’d talk about some of the ways that we as developers can add to his work.  I know in my recent development work, I have been trying to add tests where I can.

There’s a good overview on running the test suite, or specific test cases, on the Koha wiki.  What I’d like to talk about are a couple of reasons why we should be writing test cases whenever possible.

Adding more tests to our test suite can be beneficial in a number of ways.  As a new developer to Koha, writing test cases has really helped me understand what’s going on behind the scenes.  For me, writing the test case before I start working is the best way to figure out what the code is doing now, and also what it should be doing in the case of bug fixes, or what I want it to do in the case of adding new features.  That process, generally called Test Driven Developement, or TDD for short, can be awkward for many developers that have never done it before.  My main point though is not to get everyone drinking the TDD Kool-Aid, so the benefits of TDD can wait.  Though as someone that had to re-learn how to develop using TDD, I can attest to the changes one has to overcome. Test cases can be easily written both before and after code changes, so let’s get back to the topic at hand.

Another benefit of test cases is that it allows for a more rapid refactoring of the code base.  Even in my short time with LibLime and working on Koha, many of us on the Koha IRC or mailing lists have discussed ways to improve the code base, like converting to DBIx, mod_perl, or just adding warnings to classes. The more robust and complete our test cases become, the higher the confidence all of us can have in changing the code by running the test suite (or class) after we make changes.  Part of the problem in making these large-scale changes though, is the concern for what functionality we would break or alter.  Having test cases that validate behavior both before and after changes are made can be a huge benefit to successful deployment.

Of course, one of the problems in writing test cases is the fact that as a developer, often times you write as much (or more) in the test cases than you do in the actual code change itself!  While that is often true, most of the time this can be attributed to initial setup cost as once tests are written, they can be used over and over again.  An example is the work I am doing on enhancing the fines portion of Koha.  As I write test cases, I am also able to use the same test cases I wrote for the C4::Members class in another branch, making C4::Members work with DBIx::Class.  As these test cases get merged into the Koha public repository, others can also use these tests to validate still more changes to C4::Members.  So I spent some time initially doing more code than I planned, but in the long term, the benefits quickly repay the initial cost spent in code and time.

While it is often helpful to still test code changes through the browser, having test cases also allow us as developers to isolate problems faster. If you can verify that methods are inserting/updating records correctly via test cases, you save valuable time on support by then focusing on Javascript or HTML errors.  Code also tends to become more maintainable as ‘do-all’ methods get broken up into smaller methods that are easier to test.  In my past experience, while there can doubt as to the quality of the tests available, or concerns that existing test cases are not reliably structured, there can be no doubt that everyone agreed that the existence of tests provided a more stable end product. With the community’s help, hopefully we can all witness that first-hand here as well.

‡biblios.net collaborative sharing and editing of records

Monday, December 8th, 2008 by Chris Catalfo

LibLime is developing a new open platform for sharing bibliographic records as part of its forthcoming ‡biblios.net project (now in beta at http://beta.biblios.net). As part of this platform, LibLime is making available bibliographic records via several protocols: z39.50 and SRU for starters, eventually via a REST protocol and OAI-PMH.

LibLime is also allowing write access to the records via the protocol ‡biblios uses to interact with Koha. This api (documented more fully at the biblios.org site) looks like the following:

authenticate: POST username=x password=y. Receives: cookie for session use
bib_profile: GET. Receives: xml document describing marc21 fields in use by backend Koha server.
bib/xxx: GET: Retrieves a marcxml document at xxx bib number.
bib/xxx: POST: Saves posted marcxml document to server.
new_bib: POST: Saves marcxml document (new to database) to server.

In the coming weeks we will announce publicly available urls for these access services, so sharpen your pencils and get ready to collaboratively share and edit some records!

Koha event in Kansas on December 10

Wednesday, December 3rd, 2008 by Galen Charlton

From the news blog of the Northeast Kansas Library System:

The Northeast Kansas Library System is hosting a “Kansas Koha Interest Group Day” conference for libraries interested in the Koha open source integrated library system next Wednesday, December 10th at the NEKLS system office in Lawrence, Kansas. The conference is open to anyone interested in open source ILS systems, and Koha in particular.

More information here.

Git tip: [prefix] in commit messages

Tuesday, December 2nd, 2008 by Galen Charlton

When you use git format-patch and git send-email to format and mail a patch, the subject line of the email becomes

[PATCH] first line of commit message

Since patches go through a mailing list, mailman adds a prefix of its own:

[Koha-patches] [PATCH] first line of commit message

When the patch is applied, git am invokes git mailinfo to clean up the subject line, including whitespace, “Re:”, and any leading sets of text in square brackets. However, it can be a little too greedy.

If your original commit message starts with

[bug 1234] add automatic whale-saving,

the patch will reach me with the subject line

[Koha-patches] [PATCH] [bug 1234] add automatic whale-saving.

However, git am (as of 1.5.5, at any rate) will chomp it down to

add automatic whale-saving.

Oops! No bug number to immortalize your rescue of cetaceans via an ILS!

To avoid that, try bug 1234: ..., (bug 1234) ..., or if you really like square brackets, move it to the end: ... [bug 1234].