From 174bfc9c02dea87b42a2c86c6ac350f1973732a5 Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Mon, 23 Apr 2018 07:55:12 +0200 Subject: [PATCH] TT#35516 Apply simplest filter logic for subscribersregistrations Untill new requirements will be defined Change-Id: Id0d1f2ade21d0bd8c0759077577685f4c45fdf9a --- .../Panel/Utils/RedisLocationResultSet.pm | 55 ++++++++----------- t/api-rest/api-subscriberregistrations.t | 5 +- t/lib/Test/Collection.pm | 10 +++- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/NGCP/Panel/Utils/RedisLocationResultSet.pm b/lib/NGCP/Panel/Utils/RedisLocationResultSet.pm index 6de383aced..75413700b0 100644 --- a/lib/NGCP/Panel/Utils/RedisLocationResultSet.pm +++ b/lib/NGCP/Panel/Utils/RedisLocationResultSet.pm @@ -150,41 +150,30 @@ sub _filter { my $match = 0; my $filter_applied = 0; my %attr = map { $_->name => 1 } $row->meta->get_all_attributes; - foreach my $f (keys %{ $filter }) { - if ($f eq "-and" && ref $filter->{$f} eq "ARRAY") { - foreach my $col (@{ $filter->{$f} }) { - next unless (ref $col eq "ARRAY"); - foreach my $innercol (@{ $col }) { - if (ref $innercol eq "HASH") { - foreach my $colname (keys %{ $innercol }) { - my $searchname = $colname; - $colname =~ s/^me\.//; - next if ($colname =~ /\./); # we don't support joined table columns - $filter_applied = 1; - if (ref $innercol->{$searchname} eq "") { - if (!exists $attr{$colname} || lc($row->$colname) ne lc($innercol->{$searchname})) { - } else { - $match = 1; - last; - } - } elsif (ref $innercol->{$searchname} eq "HASH" && exists $innercol->{$searchname}->{like}) { - my $fil = $innercol->{$searchname}->{like}; - $fil =~ s/^\%//; - $fil =~ s/\%$//; - if (!exists $attr{$colname} || $row->$colname !~ /$fil/i) { - } else { - $match = 1; - last; - } - } - } - last if ($match); - } - } + foreach my $colname (keys %{ $filter }) { + my $condition = $filter->{$colname}; + my $searchname = $colname; + $colname =~ s/^me\.//; + next if ($colname =~ /\./); # we don't support joined table columns + $filter_applied = 1; + if (ref $condition eq "") { + if (!exists $attr{$colname} || lc($row->$colname) ne lc($condition)) { + $match = 0; + last; + } else { + $match = 1; + } + } elsif (ref $condition eq "HASH" && exists $condition->{like}) { + my $fil = $condition->{like}; + $fil =~ s/^\%//; + $fil =~ s/\%$//; + if (!exists $attr{$colname} || $row->$colname !~ /$fil/i) { + $match = 0; + last; + } else { + $match = 1; } - last if ($match); } - } next if ($filter_applied && !$match); push @newrows, $row; diff --git a/t/api-rest/api-subscriberregistrations.t b/t/api-rest/api-subscriberregistrations.t index 0351896e73..8fe245fc53 100644 --- a/t/api-rest/api-subscriberregistrations.t +++ b/t/api-rest/api-subscriberregistrations.t @@ -48,7 +48,10 @@ $test_machine->check_bundle(); $test_machine->clear_test_data_all(); $test_machine->check_create_correct( 1, sub{ $_[0]->{contact} .= time().'_'.$_[1]->{i} ; } ); -#$test_machine->check_get2put(undef, undef, { ignore_fields => [qw/id _links/] }); + +for (my $i=0; $i < 15; $i++) { + $test_machine->check_get2put(undef, undef, { ignore_fields => [qw/id _links/] }); +} $test_machine->clear_data_created(); $test_machine->check_create_correct( 1, sub{ $_[0]->{contact} .= time().'_'.$_[1]->{i} ; } ); diff --git a/t/lib/Test/Collection.pm b/t/lib/Test/Collection.pm index fb0f1d1f80..b1efe1ddd0 100644 --- a/t/lib/Test/Collection.pm +++ b/t/lib/Test/Collection.pm @@ -487,6 +487,7 @@ sub get_uri_item{ $resuri = $self->normalize_uri('/'.( $item->{location} // '' )); return $resuri; } + sub get_item_hal{ my($self, $name, $uri, $reload, $number) = @_; $name ||= $self->name; @@ -1320,13 +1321,20 @@ sub check_get2put{ delete $put_out->{content_in}->{_embedded}; # check if put is ok $put_out->{content_in} = $self->process_data($put_in->{data_cb}, $put_out->{content_in}); + #we are going to use created or loaded item - lets take it to redefine it's uri if will be necessary after put @{$put_out}{qw/response content request/} = $self->request_put( $put_out->{content_in}, $put_in->{uri} ); foreach my $field (@{$ignore_fields}){ delete $get_out->{content}->{$field}; delete $put_out->{content}->{$field}; } $self->http_code_msg(200, "check_get2put: check put successful", $put_out->{response}, $put_out->{content} ); - is_deeply($get_out->{content}, $put_out->{content}, "$self->{name}: check_get2put: check put if unmodified put returns the same"); + if (!is_deeply($get_out->{content}, $put_out->{content}, "$self->{name}: check_get2put: check put if unmodified put returns the same")) { + diag(Dumper([$put_out->{content},$get_out->{content}])); + } + if ($put_out->{response}->header('Location') && ! $put_in->{uri} ) { + my $default_item = $self->get_item_hal($self->name); + $default_item->{location} = $put_out->{response}->header('Location'); + } return ($put_out,$get_out); }