]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/live_t/06-bib_rec_fetch_update.t
LP#1796945 Reporter cloning and creation fixes
[working/Evergreen.git] / Open-ILS / src / perlmods / live_t / 06-bib_rec_fetch_update.t
1 #!perl
2
3 use Test::More tests => 6;
4
5 diag("Fetches and updates a bib records MARC data");
6
7 use strict; use warnings;
8
9 use MARC::Record;                                                              
10 use MARC::Field;
11 use MARC::File::XML (BinaryEncoding => 'UTF-8');
12 use OpenILS::Utils::TestUtils;
13 use OpenILS::Utils::Normalize qw/clean_marc/;
14 my $script = OpenILS::Utils::TestUtils->new();
15
16 my $test_record = 1;
17 my $test_title = 'La canzone italiana del Novecento :';
18 my $test_note = "Live Test Note";
19
20 # we need auth to access protected APIs
21 $script->authenticate({
22     username => 'admin',
23     password => 'demo123',
24     type => 'staff'});
25
26 my $authtoken = $script->authtoken;
27 ok($authtoken, 'Have an authtoken');
28  
29 my $ses = $script->session('open-ils.cstore');
30 my $req = $ses->request(
31     'open-ils.cstore.direct.biblio.record_entry.retrieve', 
32     $test_record);
33
34 my $bre;
35 if (my $resp = $req->recv) {
36     if ($bre = $resp->content) {
37         is(
38             ref $bre,
39             'Fieldmapper::biblio::record_entry',
40             'open-ils.cstore.direct.biblio.record_entry.retrieve '.
41                 'returned a bre object'
42         );
43     }
44 }
45
46 my $marc = MARC::Record->new_from_xml($bre->marc);
47 is(
48     $marc->subfield('245', 'a'),
49     $test_title,
50     'subfield(245, a) returned expected value'
51 );
52
53 my $field = MARC::Field->new('999','','','a' => $test_note);
54 $marc->append_fields($field);
55
56 is(
57     $marc->subfield('999', 'a'),
58     $test_note, 
59     'subfield(999, a) has correct note'
60 );
61
62 $req = $script->session('open-ils.cat')->request(
63     'open-ils.cat.biblio.record.xml.update',
64     $authtoken, $bre->id, clean_marc($marc->as_xml));
65
66 if (my $resp = $req->recv) {
67     if ($bre = $resp->content) {
68         is(
69             ref $bre,
70             'Fieldmapper::biblio::record_entry',
71             'open-ils.cat.biblio.record.xml.update returned a bre object'
72         );
73
74         my $marc = MARC::Record->new_from_xml($bre->marc);
75         
76         is(
77             $marc->subfield('999', 'a'),
78             $test_note, 
79             'Updated MARC subfield(999, a) has correct note'
80         );
81     }
82 }
83