[LON-CAPA-cvs] cvs: loncom /metadata_database lonmetadata_test.pl

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 12 Jan 2004 21:33:19 -0000


matthew		Mon Jan 12 16:33:19 2004 EDT

  Added files:                 
    /loncom/metadata_database	lonmetadata_test.pl 
  Log:
  Test suite for lonmetadata.pm.  Currently sets up and tests database creation
  (needed for other tests), metadata table creation, and metadata storage.
  
  

Index: loncom/metadata_database/lonmetadata_test.pl
+++ loncom/metadata_database/lonmetadata_test.pl
#!/usr/bin/perl -w
# The LearningOnline Network with CAPA
#
# $Id: lonmetadata_test.pl,v 1.1 2004/01/12 21:33:19 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
######################################################################
use strict;

use DBI;
use LONCAPA::lonmetadata();
use Test::Simple tests => 3;


ok(&create_test_db(),'database creation');
ok(&test_creation(),'table creation');
ok(&test_inserts(),'insert test');

exit;

#####################################################################
#####################################################################
##
##  Tests live down below
##
#####################################################################
#####################################################################
sub create_test_db {
    my $dbh = DBI->connect("DBI:mysql:test","root","123",
                           { RaiseError =>0,PrintError=>0});
    if (! defined($dbh)) {
        return 0;
    }
    my $request = 'DROP DATABASE IF EXISTS lonmetatest';
    $dbh->do($request);
    $request = 'CREATE DATABASE lonmetatest';
    $dbh->do($request);
    if ($dbh->err) {
        return 0;
    } else {
        return 1;
    }
    $dbh->disconnect();
}

sub test_creation {
    my $dbh = DBI->connect("DBI:mysql:lonmetatest","root","123",
                           { RaiseError =>0,PrintError=>0});
    my $request = &LONCAPA::lonmetadata::create_metadata_storage();
    $dbh->do($request);
    if ($dbh->err) {
        $dbh->disconnect();
        return 0;
    } else {
        $dbh->disconnect();
        return 1;
    }
}

sub test_inserts {
    my $dbh = DBI->connect("DBI:mysql:lonmetatest","root","123",
                           { RaiseError =>0,PrintError=>0});
    my @TestRecords = (
                      { url => 'm/b/h/test1' },
                      { title => 'test document 1',
                        author => 'matthew',
                        subject => 'subject 1',
                        url => 'm/b/h/test2',
                        keywords => 'key word',
                        version => '1.4',
                        notes => 'note note note',
                        abstract => 'probably',
                        mime => 'none',
                        language => 'english',
                        creationdate =>'',
                        lastrevisiondate =>'',
                        owner => 'hallmat3',
                        copyright => 'default',
                        dependencies => undef,
                        modifyinguser => 'hallmat3',
                        authorspace => 'hallmat3',
                        lowestgradelevel =>'1',
                        highestgradelevel => 16,
                        standards => 'Delaware Required Instruction Program',
                        count => '2544444',
                        course => '4',
                        course_list => 'course 1, course 2, course 3, course 4',
                        goto => '1',
                        goto_list =>'m/b/h/test1',
                        comefrom => '0',
                        comefrom_list =>'',
                        sequsage => '1',
                        sequsage_list =>'mbhtest.sequence',
                        stdno => '0',
                        stdno_list => '',
                        avetries => '0.0',
                        avetries_list =>'',
                        difficulty =>'',
                        difficulty_list => '',
                        clear => '5',
                        technical => '4',
                        correct => '3',
                        helpful => '2',
                        depth => '5',
                        hostname =>'6',
                    },
                      );
    foreach my $data (@TestRecords) {
        my ($count,$error) = &LONCAPA::lonmetadata::store_metadata($dbh,$data);
        if (! $count) {
            warn $error;
            return 0;
        }
    }
    return 1;
}