Commit 1df1a7b9 authored by David Lawrence's avatar David Lawrence

- Fixed API tests to work after login/email changes

parent 3a903b41
......@@ -236,7 +236,9 @@ sub bz_run_tests {
}
sub bz_test_bug {
my ($self, $fields, $bug, $expect, $t, $creation_time) = @_;
my ($self, $fields, $bug, $orig_expect, $t, $creation_time) = @_;
my $expect = dclone($orig_expect);
foreach my $field (sort @$fields) {
# "description" is used by Bug.create but comments are not returned
......@@ -253,6 +255,12 @@ sub bz_test_bug {
next;
}
foreach my $field (qw(assigned_to creator qa_contact)) {
if (!$t->{user}) {
$expect->{$field} = email_filter($expect->{$field});
}
}
if ($field =~ /^is_/) {
ok(defined $bug->{$field}, $self->TYPE . ": $field is not null");
is($bug->{$field} ? 1 : 0, $expect->{$field} ? 1 : 0,
......@@ -260,6 +268,7 @@ sub bz_test_bug {
}
elsif ($field eq 'cc') {
foreach my $cc_item (@{ $expect->{cc} || [] }) {
$cc_item = email_filter($cc_item) if !$t->{user};
ok(grep($_ eq $cc_item, @{ $bug->{cc} }),
$self->TYPE . ": $field contains $cc_item");
}
......
......@@ -18,6 +18,7 @@ use lib "$RealBin/../../lib", "$RealBin/../../../local/lib/perl5";
use autodie;
use Data::Dumper;
use Email::Address;
use Test::More;
use parent qw(Exporter);
......@@ -25,6 +26,7 @@ use parent qw(Exporter);
trim
url_quote
random_string
email_filter
log_in
logout
......@@ -367,6 +369,18 @@ sub set_parameters {
}
}
sub email_filter {
my ($toencode) = @_;
my @emails = Email::Address->parse($toencode);
if (scalar @emails) {
my @hosts = map { quotemeta($_->host) } @emails;
my $hosts_re = join('|', @hosts);
$toencode =~ s/\@(?:$hosts_re)//g;
return $toencode;
}
return $toencode;
}
1;
__END__
......@@ -141,8 +141,8 @@ sub post_success {
"content_type is correct");
cmp_ok($attachment->{file_name}, '=~', qr/^\w+\.pl$/,
"filename is in the expected format");
is($attachment->{creator}, $config->{QA_Selenium_TEST_user_login},
"creator is the correct user");
is($attachment->{creator}, ($t->{user} ? $config->{QA_Selenium_TEST_user_login} : email_filter($config->{QA_Selenium_TEST_user_login})),
"creator is the correct user");
my $data = $attachment->{data};
$data = decode_base64($data) if $rpc->isa('QA::RPC::JSONRPC');
is($data, $content, 'data is correct');
......
......@@ -47,6 +47,7 @@ sub test_comments {
is($comment->{text}, $expected_text, "comment has the correct text");
my $priv_login = $rpc->bz_config->{PRIVATE_BUG_USER . '_user_login'};
$priv_login = $t->{user} ? $priv_login : email_filter($priv_login);
is($comment->{creator}, $priv_login, "comment creator is correct");
my $creation_day;
......
......@@ -137,8 +137,8 @@ sub post_success {
'Admin correctly gets all user fields');
}
elsif ($user) {
ok(exists $item->{email} && exists $item->{can_login},
'Logged-in user correctly gets email and can_login');
ok(exists $item->{can_login},
'Logged-in user correctly gets can_login');
ok(!exists $item->{email_enabled}
&& !exists $item->{login_denied_text},
"Non-admin user doesn't get email_enabled and login_denied_text");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment