From 1df1a7b9ea4cd24235d344d495a874de40624612 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Wed, 31 Aug 2016 00:24:56 -0400 Subject: - Fixed API tests to work after login/email changes --- xt/lib/QA/RPC.pm | 11 ++++++++++- xt/lib/QA/Util.pm | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'xt/lib') diff --git a/xt/lib/QA/RPC.pm b/xt/lib/QA/RPC.pm index e2f1f7597..93414e231 100644 --- a/xt/lib/QA/RPC.pm +++ b/xt/lib/QA/RPC.pm @@ -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"); } diff --git a/xt/lib/QA/Util.pm b/xt/lib/QA/Util.pm index 90a6902e5..eb68a0b5b 100644 --- a/xt/lib/QA/Util.pm +++ b/xt/lib/QA/Util.pm @@ -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__ -- cgit v1.2.3-24-g4f1b