]> git.donarmstrong.com Git - debbugs.git/blob - t/21_database.t
include function in instalsql for bin ver/src pkg linking
[debbugs.git] / t / 21_database.t
1 # -*- mode: cperl;-*-
2
3 use Test::More;
4
5 use warnings;
6 use strict;
7
8 use IO::File;
9 use File::Temp qw(tempdir);
10 use Cwd qw(getcwd);
11 use Debbugs::MIME qw(create_mime_message);
12 use File::Basename qw(dirname basename);
13 use Test::WWW::Mechanize;
14 use HTTP::Status qw(RC_NOT_MODIFIED);
15 # The test functions are placed here to make things easier
16 use lib qw(t/lib);
17 use DebbugsTest qw(:all);
18
19 our $tests_run = 0;
20
21 my %config = create_debbugs_configuration();
22
23
24 # create 4 bugs
25 for (1..4) {
26     send_message(to=>'submit@bugs.something',
27                  headers => [To   => 'submit@bugs.something',
28                              From => 'foo@bugs.something',
29                              Subject => 'Submitting a bug '.$_,
30                             ],
31                  run_processall => 0,
32                  body => <<EOF) or fail('Unable to send message');
33 Package: foo
34 Severity: normal
35
36 This is a silly bug $_
37 EOF
38
39 }
40 send_message(to => 'control@bugs.something',
41              headers => [To   => 'control@bugs.something',
42                          From => 'foo@bugs.something',
43                          Subject => "Munging bugs with blocks",
44                         ],
45              body => <<'EOF') or fail 'message to control@bugs.something failed';
46 block 1 by 2
47 block 3 by 1
48 block 4 by 1
49 thanks
50 EOF
51
52
53 ## create the database
54 my $pgsql = create_postgresql_database();
55 update_postgresql_database($pgsql);
56
57 BEGIN{
58     use_ok('Debbugs::DB')
59 }
60 $tests_run++;
61
62 my $s;
63
64 ok($s = Debbugs::DB->connect($pgsql->dsn),
65    "Able to connect to database");
66 $tests_run++;
67
68 ok($s->resultset('Bug')->search({id => 1})->single->subject eq
69    'Submitting a bug 1',
70    "Correct bug title");
71 $tests_run++;
72
73 my @blocking_bugs =
74     map {$_->{blocks}}
75     $s->resultset('Bug')->search({id => 1})->single->
76     bug_blocks_bugs(undef,
77                    {columns => [qw(blocks)],
78                     result_class=>'DBIx::Class::ResultClass::HashRefInflator',
79                    })->all;
80 $tests_run++;
81 is_deeply([sort @blocking_bugs],
82           [3,4],"Blocking bugs of 1 inserted correctly");
83
84 done_testing($tests_run);