]> git.donarmstrong.com Git - debbugs.git/blob - t/09_soap.t
abstract out create config in tests
[debbugs.git] / t / 09_soap.t
1 # -*- mode: cperl;-*-
2
3
4 use Test::More tests => 4;
5
6 use warnings;
7 use strict;
8
9 use IO::File;
10 use File::Temp qw(tempdir);
11 use Cwd qw(getcwd);
12 use Debbugs::MIME qw(create_mime_message);
13 use File::Basename qw(dirname basename);
14 use Test::WWW::Mechanize;
15 # The test functions are placed here to make things easier
16 use lib qw(t/lib);
17 use DebbugsTest qw(:configuration);
18 use Cwd;
19
20 my %config;
21 eval {
22      %config = create_debbugs_configuration();
23 };
24 if ($@) {
25      BAIL_OUT($@);
26 }
27
28 # create a bug
29 send_message(to=>'submit@bugs.something',
30              headers => [To   => 'submit@bugs.something',
31                          From => 'foo@bugs.something',
32                          Subject => 'Submitting a bug',
33                         ],
34              body => <<EOF) or fail('Unable to send message');
35 Package: foo
36 Severity: normal
37
38 This is a silly bug
39 EOF
40
41
42 # test the soap server
43
44 my $port = 11343;
45
46 # We'd like to use soap.cgi here instead of testing the module
47 # directly, but I can't quite get it to work with
48 # HTTP::Server::Simple.
49 use_ok('Debbugs::SOAP');
50 use_ok('Debbugs::SOAP::Server');
51
52 our $child_pid = undef;
53
54 END{
55      if (defined $child_pid) {
56           my $temp_exit = $?;
57           kill(15,$child_pid);
58           waitpid(-1,0);
59           $? = $temp_exit;
60      }
61 }
62
63 my $pid = fork;
64 die "Unable to fork child" if not defined $pid;
65 if ($pid) {
66      $child_pid = $pid;
67      # Wait for two seconds to let the child start
68      sleep 2;
69 }
70 else {
71      # UGH.
72      eval q(
73      use Debbugs::SOAP::Server;
74      @Debbugs::SOAP::Server::ISA = qw(SOAP::Transport::HTTP::Daemon);
75      our $warnings = '';
76      eval {
77        # Ignore stupid warning because elements (hashes) can't start with
78        # numbers
79        local $SIG{__WARN__} = sub {$warnings .= $_[0] unless $_[0] =~ /Cannot encode unnamed element/};
80        Debbugs::SOAP::Server
81                ->new(LocalAddr => 'localhost', LocalPort => $port)
82                     ->dispatch_to('/','Debbugs::SOAP')
83                          ->handle;
84       };
85       die $@ if $@;
86       warn $warnings if length $warnings;
87
88      );
89 }
90
91 use SOAP::Lite;
92 my $soap = SOAP::Lite->uri('Debbugs/SOAP')->proxy('http://localhost:'.$port.'/');
93 #ok($soap->get_soap_version->result == 1,'Version set and got correctly');
94 my $bugs_result = $soap->get_bugs(package => 'foo');
95 my $bugs = $bugs_result->result;
96 use Data::Dumper;
97 #print STDERR Dumper($bugs_result);
98 ok(@{$bugs} == 1 && $bugs->[0] == 1, 'get_bugs returns bug number 1') or fail(Dumper($bugs));
99 my $status_result = $soap->get_status(1);
100 #print STDERR Dumper($status_result);
101 my $status = $status_result->result;
102 ok($status->{1}{package} eq 'foo','get_status thinks that bug 1 belongs in foo') or fail(Dumper($status));
103
104 # Test the usertags at some point