def test_success(self): generator = self.gsa._parse_xml(rhel70_xml) self.assertTrue(inspect.isgenerator(generator)) items = list(generator) self.assertListEqual(items, [ SearchResult('rhel7.0', 'Red Hat Enterprise Linux 7 base image'), SearchResult('redhat/rhel7.0', 'Red Hat Enterprise Linux 7 base image'), ])
def test_num_results(self, mock_search): mock_search.return_value = [ SearchBackend._format_result( SearchResult('rhel', 'Red Hat Enterprise Linux')), SearchBackend._format_result(SearchResult('foo', 'Foo')), SearchBackend._format_result(SearchResult('bar', 'Bar')), ] response = self.test_client.get('/v1/search?q=rhel') data = json.loads(response.data) self.assertEqual(data['num_results'], 3)
def test_no_description(self): """test when the description is missing from the XML""" generator = self.gsa._parse_xml(rhel70_no_desc_xml) items = list(generator) self.assertListEqual(items, [ SearchResult('rhel7.0', ''), ])
def test_workflow_filter_false(self, mock_parse_xml, mock_get_data, mock_filter): mock_parse_xml.return_value = [SearchResult('rhel', 'Red Hat Enterprise Linux', **SearchResult.result_defaults)] ret = self.gsa.search('foo') mock_get_data.assert_called_once_with('http://pulpproject.org/search?q=foo') self.assertEqual(len(list(ret)), 0)
def test_workflow_filter_true_with_image_repository_with_defaults( self, mock_is_authorized): """ When the should_filter attribute of SearchResult instance is default which is False, the base implementation of the filter_results is not called """ result = SearchResult('rhel', 'Red Hat Enterprise Linux', **SearchResult.result_defaults) ret_val = self.solr._filter_result(result) self.assertEquals(ret_val, True)
def test_workflow_filter_true_with_image_repository_document_kind( self, mock_is_authorized): """ When the should_filter attribute of SearchResult instance is True, the base implementation of the filter_results should be called and the return value should be the value returned by the mocked app_util.repo_is_authorized """ result = SearchResult('rhel', 'Red Hat Enterprise Linux', False, False, 0, True) ret_val = self.solr._filter_result(result) self.assertEquals(ret_val, True)
def test_workflow_filter_true_with_image_repository_with_defaults( self, mock_is_authorized, mock_name_is_authorised): """ When the should_filter attribute of SearchResult instance is default which is False, the base implementation of the filter_results is not called """ mock_name_is_authorised.side_effect = exceptions.HTTPError( mock.Mock(status=404), 'not found') result = SearchResult('rhel', 'Red Hat Enterprise Linux', **SearchResult.result_defaults) ret_val = self.solr._filter_result(result) self.assertEquals(ret_val, True)
def test_workflow_filter_false_with_image_repository_document_kind( self, mock_is_authorized): """ When the should_filter attribute of SearchResult instance is True, the base implementation of the filter_results should be called and the return value should be based on the value returned/exception raised by the mocked app_util.repo_is_authorized """ mock_is_authorized.side_effect = exceptions.HTTPError( httplib.NOT_FOUND) result = SearchResult('rhel', 'Red Hat Enterprise Linux', False, False, 0, True) ret_val = self.solr._filter_result(result) self.assertEquals(ret_val, False)
def test_with_results(self, mock_search): mock_search.return_value = [ SearchBackend._format_result( SearchResult('rhel', 'Red Hat Enterprise Linux')), ] response = self.test_client.get('/v1/search?q=rhel') data = json.loads(response.data) self.assertDictEqual(data, { 'query': 'rhel', 'num_results': 1, 'results': mock_search.return_value })
def test_workflow_filter_true(self, mock_parse_xml, mock_get_data, mock_filter): mock_parse_xml.return_value = [SearchResult('rhel', 'Red Hat Enterprise Linux', **SearchResult.result_defaults)] ret = self.gsa.search('foo') mock_get_data.assert_called_once_with('http://pulpproject.org/search?q=foo') self.assertDictEqual(list(ret)[0], { 'name': 'rhel', 'description': 'Red Hat Enterprise Linux', 'star_count': 0, 'is_trusted': False, 'is_official': False, })
def test_workflow_filter_true(self, mock_parse, mock_get_data, mock_filter): mock_parse.return_value = [ SearchResult('rhel', 'Red Hat Enterprise Linux', True, True, 5, True) ] ret = self.solr.search('foo') mock_get_data.assert_called_once_with( 'http://pulpproject.org/search?q=foo') self.assertDictEqual( list(ret)[0], { 'name': 'rhel', 'description': 'Red Hat Enterprise Linux', 'star_count': 5, 'is_trusted': True, 'is_official': True, 'should_filter': True })