3 |
use strict; |
use strict; |
4 |
use blib; |
use blib; |
5 |
|
|
6 |
use Test::More tests => 36; |
use Test::More tests => 40; |
7 |
|
|
8 |
BEGIN { |
BEGIN { |
9 |
use_ok('Nos'); |
use_ok('Nos'); |
12 |
use_ok('Cwd'); |
use_ok('Cwd'); |
13 |
}; |
}; |
14 |
|
|
15 |
|
use Data::Dump qw/dump/; |
16 |
|
|
17 |
|
my $debug = 0; |
18 |
my $list_name = 'SOAP test'; |
my $list_name = 'SOAP test'; |
19 |
|
|
20 |
|
$debug = 1 if (@ARGV); |
21 |
|
|
22 |
my $aliases = Cwd::abs_path($0); |
my $aliases = Cwd::abs_path($0); |
23 |
$aliases =~ s#/[^/]*$#/#; |
$aliases =~ s#/[^/]*$#/#; |
24 |
$aliases .= 'aliases'; |
$aliases .= 'aliases'; |
28 |
ok(my $nos = new Nos::SOAP( |
ok(my $nos = new Nos::SOAP( |
29 |
'dsn' => 'dbi:Pg:dbname=notices', |
'dsn' => 'dbi:Pg:dbname=notices', |
30 |
'aliases' => $aliases, |
'aliases' => $aliases, |
31 |
), "new"); |
), "new Nos::SOAP"); |
32 |
|
|
33 |
ok(my $daemon = new SOAP::Transport::HTTP::Daemon(LocalAddr => 'localhost')->dispatch_to('Nos::SOAP'), "SOAP daemon"); |
ok(my $daemon = new SOAP::Transport::HTTP::Daemon(LocalAddr => 'localhost')->dispatch_to('Nos::SOAP'), "SOAP daemon"); |
34 |
|
|
54 |
->uri('http://localhost/Nos/SOAP/') |
->uri('http://localhost/Nos/SOAP/') |
55 |
->proxy($daemon->url); |
->proxy($daemon->url); |
56 |
|
|
57 |
# NewList |
$soap->on_debug(sub{print "## ", join("\n## ",@_), "\n";}) if ($debug); |
58 |
|
|
59 |
|
# CreateList |
60 |
|
|
61 |
ok(my $list_id = $soap->NewList({ |
ok(my $list_id = $soap->CreateList({ |
62 |
list => $list_name, |
list => $list_name, |
63 |
from => 'SOAP list', |
from => 'SOAP list', |
64 |
email => 'soap-test@example.com', |
email => 'soap-test@example.com', |
65 |
})->result, "NewList named"); |
})->result, "CreateList named"); |
66 |
|
|
67 |
ok(my $list_id2 = $soap->NewList( |
ok(my $list_id2 = $soap->CreateList( |
68 |
$list_name, |
$list_name, |
69 |
'SOAP test list', |
'SOAP test list', |
70 |
'soap-test@example.com', |
'soap-test@example.com', |
71 |
)->result, "NewList positional"); |
)->result, "CreateList positional"); |
72 |
|
|
73 |
cmp_ok($list_id, '==', $list_id2, "list_id $list_id"); |
cmp_ok($list_id, '==', $list_id2, "list_id $list_id"); |
74 |
|
|
140 |
|
|
141 |
cmp_ok($#{$arr}, '==', 1, "member count ok"); |
cmp_ok($#{$arr}, '==', 1, "member count ok"); |
142 |
|
|
143 |
cmp_ok($arr->[0]->{'full_name'}, '==', 'Dobrica Pavlinusic', "full_name"); |
diag "arr = ", dump($arr) if ($debug); |
144 |
cmp_ok($arr->[0]->{'email'}, '==', 'dpavlin@rot13.org', "email"); |
cmp_ok($arr->[0]->{'name'}, 'eq', 'Dobrica Pavlinusic', "name"); |
145 |
|
cmp_ok($arr->[0]->{'email'}, 'eq', 'dpavlin@rot13.org', "email"); |
146 |
|
|
147 |
cmp_ok($arr->[1]->{'email'}, '==', 'nobody@example.com', "email"); |
cmp_ok($arr->[1]->{'email'}, 'eq', 'nobody@example.com', "email"); |
148 |
|
|
149 |
# DeleteMember |
# DeleteMember |
150 |
|
|
160 |
|
|
161 |
cmp_ok($#{$arr}, '==', 0, "member deleted"); |
cmp_ok($#{$arr}, '==', 0, "member deleted"); |
162 |
|
|
163 |
# DeleteList |
# DropList |
164 |
|
|
165 |
ok($soap->DeleteList({ |
ok($soap->DropList({ |
166 |
list => $list_name, |
list => $list_name, |
167 |
})->result, "DeleteList named"); |
})->result, "DropList named"); |
168 |
|
|
169 |
ok(my $has_members = $soap->ListMembers({ |
ok(my $has_members = $soap->ListMembers({ |
170 |
list => $list_name, |
list => $list_name, |
172 |
|
|
173 |
cmp_ok($#{$has_members}, '==', -1, "ok, no members"); |
cmp_ok($#{$has_members}, '==', -1, "ok, no members"); |
174 |
|
|
175 |
ok($list_id = $soap->NewList({ |
ok($list_id = $soap->CreateList({ |
176 |
list => $list_name, |
list => $list_name, |
177 |
from => 'SOAP list', |
from => 'SOAP list', |
178 |
email => 'soap-test@example.com', |
email => 'soap-test@example.com', |
179 |
})->result, "NewList $list_name (recreated)"); |
})->result, "CreateList $list_name (recreated)"); |
180 |
|
|
181 |
ok($soap->DeleteList( |
ok($soap->DropList( |
182 |
$list_name, |
$list_name, |
183 |
)->result, "DeleteList positional"); |
)->result, "DropList positional"); |
184 |
|
|
185 |
ok($has_members = $soap->ListMembers({ |
ok($has_members = $soap->ListMembers({ |
186 |
list => $list_name, |
list => $list_name, |
188 |
|
|
189 |
cmp_ok($#{$has_members}, '==', -1, "ok, no members"); |
cmp_ok($#{$has_members}, '==', -1, "ok, no members"); |
190 |
|
|
191 |
|
diag "I should add e-mail send test!"; |
192 |
|
|
193 |
|
=for next_version |
194 |
|
|
195 |
|
ok(my $nos = new Nos( |
196 |
|
'dsn' => 'dbi:Pg:dbname=notices', |
197 |
|
'aliases' => $aliases, |
198 |
|
), "new NOS"); |
199 |
|
|
200 |
|
# or |
201 |
|
|
202 |
|
ok(my $sent = $nos->_nos_object->send_queued_messages( |
203 |
|
list => $list_name, |
204 |
|
driver => 'Test', |
205 |
|
sleep => 0, |
206 |
|
), "send_queued_messages for $list_name"); |
207 |
|
|
208 |
|
my @emails = Email::Send::Test->emails; |
209 |
|
|
210 |
|
diag "emails = ", dump( @emails ); |
211 |
|
|
212 |
|
=cut |
213 |
|
|
214 |
|
# replay to messages |
215 |
|
|
216 |
|
ok(my $received = $soap->MessagesReceived({ |
217 |
|
list => $list_name, |
218 |
|
})->result, "MessagesReceived for $list_name"); |
219 |
|
|
220 |
|
diag "received = ", dump($received) if ($debug); |
221 |
|
cmp_ok( scalar @$received, '==', 0, 'no messages' ); |
222 |
|
|
223 |
# kill server |
# kill server |
224 |
|
|
225 |
ok(kill('HUP' => $pid), "kill $pid"); |
ok(kill('HUP' => $pid), "kill $pid"); |