def test_filter(self): header_matches = IHeaderMatchList(self._mlist) header_matches.append('header-1', 'pattern-1', tag='tag1') header_matches.append('header-1', 'pattern-3', tag='tag1') header_matches.append('header-2', 'pattern-') header_matches.append('header-3', 'pattern-2', tag='tag1') header_matches.append('header-3', 'pattern-3', chain='hold') match_tag = header_matches.filter(header='header-1', tag='tag1') self.assertEqual(len(list(match_tag)), 2) match_tag = header_matches.filter(tag='tag1') self.assertEqual(len(list(match_tag)), 3) match_tag = header_matches.filter(chain='hold') self.assertEqual(len(list(match_tag)), 1)
def _find(self, request, response): validator = Validator( header=str, action=enum_validator(Action), tag=str, _optional=('action', 'tag', 'header') ) try: data = validator(request) except ValueError as error: bad_request(response, str(error)) return # Remove any optional pagination elements. action = data.pop('action', None) if action is not None: data['chain'] = action.name service = IHeaderMatchList(self._mlist) self.header_matches = list(service.filter(**data)) # Return 404 if no values were found. if len(self.header_matches) == 0: return not_found( response, 'Cound not find any HeaderMatch for provided search options.') resource = self._make_collection(request) okay(response, etag(resource))