Annotation of loncom/metadata_database/lonmetadata_test.pl, revision 1.3
1.1 matthew 1: #!/usr/bin/perl -w
2: # The LearningOnline Network with CAPA
3: #
1.3 ! matthew 4: # $Id: lonmetadata_test.pl,v 1.2 2004/01/12 21:48:38 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.2 matthew 110: my $dbh = DBI->connect("DBI:mysql:lonmetatest","root",$supersecretpassword,
1.1 matthew 111: { RaiseError =>0,PrintError=>0});
112: my @TestRecords = (
113: { url => 'm/b/h/test1' },
114: { title => 'test document 1',
115: author => 'matthew',
116: subject => 'subject 1',
117: url => 'm/b/h/test2',
118: keywords => 'key word',
119: version => '1.4',
120: notes => 'note note note',
121: abstract => 'probably',
122: mime => 'none',
123: language => 'english',
124: creationdate =>'',
125: lastrevisiondate =>'',
126: owner => 'hallmat3',
127: copyright => 'default',
128: dependencies => undef,
129: modifyinguser => 'hallmat3',
130: authorspace => 'hallmat3',
131: lowestgradelevel =>'1',
132: highestgradelevel => 16,
133: standards => 'Delaware Required Instruction Program',
134: count => '2544444',
135: course => '4',
136: course_list => 'course 1, course 2, course 3, course 4',
137: goto => '1',
138: goto_list =>'m/b/h/test1',
139: comefrom => '0',
140: comefrom_list =>'',
141: sequsage => '1',
142: sequsage_list =>'mbhtest.sequence',
143: stdno => '0',
144: stdno_list => '',
145: avetries => '0.0',
146: avetries_list =>'',
147: difficulty =>'',
148: difficulty_list => '',
149: clear => '5',
150: technical => '4',
151: correct => '3',
152: helpful => '2',
153: depth => '5',
154: hostname =>'6',
155: },
156: );
157: foreach my $data (@TestRecords) {
158: my ($count,$error) = &LONCAPA::lonmetadata::store_metadata($dbh,$data);
159: if (! $count) {
160: warn $error;
161: return 0;
162: }
163: }
164: return 1;
165: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>