Get email and token from g+
[scpubgit/stemmaweb.git] / script / maketestdb.pl
CommitLineData
9a3fb143 1#!/usr/bin/env perl
2
3use strict;
4use warnings;
5use feature 'say';
6use Text::Tradition;
7use Text::Tradition::Directory;
8
9my $DBDIR = 'db';
10my $DBNAME = 'traditions.db';
11my $DBEXT = 'test';
bfaf51f3 12# Make the directory on the filesystem if necessary
13unless( -d $DBDIR ) {
14 mkdir $DBDIR
15 or die "Could not make database director $DBDIR";
16 say "Created directory for test database";
17}
18# Delete the old db if it exists
9a3fb143 19if( -f "$DBDIR/$DBNAME.$DBEXT" ) {
20 unlink( "$DBDIR/$DBNAME.$DBEXT" );
21}
22if( -l "$DBDIR/$DBNAME" ) {
23 unlink( "$DBDIR/$DBNAME" );
24} elsif( -e "$DBDIR/$DBNAME" ) {
25 unlink( "$DBDIR/$DBNAME.bak" ) if -f "$DBDIR/$DBNAME.bak";
26 rename( "$DBDIR/$DBNAME", "$DBDIR/$DBNAME.bak" )
27 or die "Could not rename existing $DBNAME";
28}
29# Set up the test directory
30symlink( "$DBNAME.$DBEXT", "$DBDIR/$DBNAME" ) or die "Could not set up testing db symlink";
31
32my $dir = Text::Tradition::Directory->new(
33 dsn => "dbi:SQLite:dbname=$DBDIR/$DBNAME",
34 extra_args => { create => 1 }
35 );
36my $scope = $dir->new_scope();
bfaf51f3 37say "Created test database";
9a3fb143 38
39# Create users
40my $user = $dir->add_user({ username => 'user@example.org', password => 'UserPass' });
41my $admin = $dir->add_user({ username => 'admin@example.org',
42 password => 'AdminPass', role => 'admin' });
85990daf 43my $openid_user = $dir->add_user({
44 username => 'https://www.google.com/accounts/o8/id?id=AItOawlFTlpuHGcI67tqahtw7xOod9VNWffB-Qg',
45 password => 'pass'
46 });
47die "Failed to create test users" unless $user && $admin && $openid_user;
9a3fb143 48say "Created users";
49
50my $t1 = Text::Tradition->new( input => 'Self', file => 't/data/besoin.xml' );
51die "Failed to create test tradition #1" unless $t1;
532cc23b 52$t1->add_stemma( dotfile => 't/data/besoin_stemweb.dot' );
9a3fb143 53$user->add_tradition( $t1 );
85990daf 54$openid_user->add_tradition($t1);
9a3fb143 55$dir->store( $user );
56say "Created test user tradition";
57
58my $t2 = Text::Tradition->new( input => 'Tabular', sep_char => ',',
59 file => 't/data/florilegium.csv' );
60$t2->add_stemma( dotfile => 't/data/florilegium.dot' );
61die "Failed to create test tradition #2" unless $t2;
62$t2->public( 1 );
63$dir->store( $t2 );
56e3972e 64my $t3 = Text::Tradition->new( input => 'Self', file => 't/data/john.xml' );
65$t3->public( 1 );
66$t3->name( 'John verse' );
67$dir->store( $t3 );
2d6431a4 68my $t4 = Text::Tradition->new( input => 'Self', file => 't/data/collatecorr.xml' );
69$t4->public( 1 );
70$user->add_tradition( $t4 );
71$dir->store( $t4 );
72$dir->store( $user );
73
56e3972e 74say "Created test public traditions";
9a3fb143 75