Annotation of loncom/metadata_database/lonmetadata_test.pl, revision 1.4
1.1 matthew 1: #!/usr/bin/perl -w
2: # The LearningOnline Network with CAPA
3: #
1.4 ! matthew 4: # $Id: lonmetadata_test.pl,v 1.3 2004/01/12 21:56:32 matthew Exp $
1.1 matthew 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ######################################################################
29: use strict;
30:
31: use DBI;
32: use LONCAPA::lonmetadata();
1.2 matthew 33: use Test::Simple tests => 4;
1.1 matthew 34:
1.3 matthew 35: ##
36: ## Note: The root password to my MySQL server is shown below.
37: ## Access is only allowed from localhost so it should be okay.
38: ## Now if you will excuse me I have to change the password on my luggage.
39: ##
40: my $supersecretpassword = '123'; # shhhh
1.1 matthew 41:
42: ok(&create_test_db(),'database creation');
43: ok(&test_creation(),'table creation');
1.2 matthew 44: ok(&test_named_creation(),'named table creation');
1.1 matthew 45: ok(&test_inserts(),'insert test');
46:
47: exit;
48:
49: #####################################################################
50: #####################################################################
51: ##
52: ## Tests live down below
53: ##
54: #####################################################################
55: #####################################################################
56: sub create_test_db {
1.2 matthew 57: my $dbh = DBI->connect("DBI:mysql:test","root",$supersecretpassword,
1.1 matthew 58: { RaiseError =>0,PrintError=>0});
59: if (! defined($dbh)) {
60: return 0;
61: }
62: my $request = 'DROP DATABASE IF EXISTS lonmetatest';
63: $dbh->do($request);
64: $request = 'CREATE DATABASE lonmetatest';
65: $dbh->do($request);
66: if ($dbh->err) {
67: return 0;
68: } else {
69: return 1;
70: }
71: $dbh->disconnect();
72: }
73:
74: sub test_creation {
1.2 matthew 75: my $dbh = DBI->connect("DBI:mysql:lonmetatest","root",$supersecretpassword,
1.1 matthew 76: { RaiseError =>0,PrintError=>0});
77: my $request = &LONCAPA::lonmetadata::create_metadata_storage();
78: $dbh->do($request);
79: if ($dbh->err) {
80: $dbh->disconnect();
81: return 0;
82: } else {
83: $dbh->disconnect();
84: return 1;
85: }
86: }
87:
1.2 matthew 88: sub test_named_creation {
89: my $request =
90: &LONCAPA::lonmetadata::create_metadata_storage('nonmetadata');
91: my $dbh = DBI->connect("DBI:mysql:lonmetatest","root",$supersecretpassword,
92: { RaiseError =>0,PrintError=>0});
93: $dbh->do($request); # Create the table, only return 0 if we cannot.
94: if ($dbh->err) {
95: $dbh->disconnect();
96: return 0;
97: }
98: $dbh->do('DROP TABLE nonmetadata'); # This will generate an error if the
99: # table does not exist
100: if ($dbh->err) {
101: $dbh->disconnect();
102: return 0;
103: } else {
104: $dbh->disconnect();
105: return 1;
106: }
107: }
108:
1.1 matthew 109: sub test_inserts {
1.4 ! matthew 110: my $tablename = 'metadatatest';
1.2 matthew 111: my $dbh = DBI->connect("DBI:mysql:lonmetatest","root",$supersecretpassword,
1.1 matthew 112: { RaiseError =>0,PrintError=>0});
113: my @TestRecords = (
114: { url => 'm/b/h/test1' },
115: { title => 'test document 1',
116: author => 'matthew',
117: subject => 'subject 1',
118: url => 'm/b/h/test2',
119: keywords => 'key word',
120: version => '1.4',
121: notes => 'note note note',
122: abstract => 'probably',
123: mime => 'none',
124: language => 'english',
125: creationdate =>'',
126: lastrevisiondate =>'',
127: owner => 'hallmat3',
128: copyright => 'default',
129: dependencies => undef,
130: modifyinguser => 'hallmat3',
131: authorspace => 'hallmat3',
132: lowestgradelevel =>'1',
133: highestgradelevel => 16,
134: standards => 'Delaware Required Instruction Program',
135: count => '2544444',
136: course => '4',
137: course_list => 'course 1, course 2, course 3, course 4',
138: goto => '1',
139: goto_list =>'m/b/h/test1',
140: comefrom => '0',
141: comefrom_list =>'',
142: sequsage => '1',
143: sequsage_list =>'mbhtest.sequence',
144: stdno => '0',
145: stdno_list => '',
146: avetries => '0.0',
147: avetries_list =>'',
148: difficulty =>'',
149: difficulty_list => '',
150: clear => '5',
151: technical => '4',
152: correct => '3',
153: helpful => '2',
154: depth => '5',
155: hostname =>'6',
156: },
157: );
1.4 ! matthew 158: # Create the table
! 159: my $request = &LONCAPA::lonmetadata::create_metadata_storage($tablename);
! 160: $dbh->do($request);
! 161: if ($dbh->err) {
! 162: $dbh->disconnect();
! 163: warn "Unable to create table for test";
! 164: return 0;
! 165: } else {
! 166: $dbh->disconnect();
! 167: return 1;
! 168: }
! 169: # Store the sample records
1.1 matthew 170: foreach my $data (@TestRecords) {
1.4 ! matthew 171: my ($count,$error) = &LONCAPA::lonmetadata::store_metadata($dbh,
! 172: $tablename,
! 173: $data);
1.1 matthew 174: if (! $count) {
175: warn $error;
176: return 0;
177: }
178: }
179: return 1;
180: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>