示例#1
0
class TestGetQueryResultsFromPost(unittest.TestCase):
    PARAMS = {'criteria': {}}

    def setUp(self):
        self.mock_query_method = mock.MagicMock()
        self.controller = SearchController(self.mock_query_method)
        self.controller.params = mock.MagicMock(return_value=self.PARAMS)

    def test_requires_criteria(self):
        self.controller.params = mock.MagicMock(return_value={})
        self.assertRaises(exceptions.MissingValue,
                          self.controller._get_query_results_from_post)

    def test_calls_query(self):
        self.controller._get_query_results_from_post()
        self.assertEqual(self.mock_query_method.call_count, 1)
        self.assertTrue(
            isinstance(self.mock_query_method.call_args[0][0], Criteria))

    def test_adds_id(self):
        # make sure it adds the 'id' field if not requested.
        self.controller.params = mock.MagicMock(
            return_value={'criteria': {
                'fields': ('name', )
            }})
        self.controller._get_query_results_from_post()
        self.assertTrue('id' in self.mock_query_method.call_args[0][0].fields)
示例#2
0
class TestGetQueryResultsFromGet(unittest.TestCase):
    def setUp(self):
        self.mock_query_method = mock.MagicMock()
        self.controller = SearchController(self.mock_query_method)

    @mock.patch('web.input', return_value={'field': []})
    def test_calls_query(self, mock_input):
        self.controller._get_query_results_from_get()
        self.assertEqual(mock_input.call_count, 1)
        self.assertEqual(self.mock_query_method.call_count, 1)
        self.assertTrue(
            isinstance(self.mock_query_method.call_args[0][0], Criteria))

    @mock.patch('web.input',
                return_value={
                    'field': [],
                    'limit': 10,
                    'foo': 1,
                    'bar': 2
                })
    @mock.patch('pulp.server.db.model.criteria.Criteria.from_client_input')
    def test_ignore_fields(self, mock_from_client, mock_input):
        self.controller._get_query_results_from_get(('foo', 'bar'))
        mock_from_client.assert_called_once_with({'limit': 10})

    @mock.patch('web.input', return_value={'field': ['name']})
    def test_adds_id(self, mock_input):
        # make sure it adds the 'id' field if not requested.
        self.controller._get_query_results_from_get()
        self.assertTrue('id' in self.mock_query_method.call_args[0][0].fields)
class TestGetQueryResultsFromPost(unittest.TestCase):
    PARAMS = {'criteria' : {}}

    def setUp(self):
        self.mock_query_method = mock.MagicMock()
        self.controller = SearchController(self.mock_query_method)
        self.controller.params = mock.MagicMock(return_value=self.PARAMS)

    def test_requires_criteria(self):
        self.controller.params = mock.MagicMock(return_value={})
        self.assertRaises(exceptions.MissingValue, self.controller._get_query_results_from_post)

    def test_calls_query(self):
        self.controller._get_query_results_from_post()
        self.assertEqual(self.mock_query_method.call_count, 1)
        self.assertTrue(isinstance(self.mock_query_method.call_args[0][0], Criteria))

    def test_adds_id(self):
        # make sure it adds the 'id' field if not requested.
        self.controller.params = mock.MagicMock(
            return_value={'criteria':{'fields':('name',)}})
        self.controller._get_query_results_from_post()
        self.assertTrue('id' in self.mock_query_method.call_args[0][0].fields)
class TestGetQueryResultsFromGet(unittest.TestCase):
    def setUp(self):
        self.mock_query_method = mock.MagicMock()
        self.controller = SearchController(self.mock_query_method)

    @mock.patch('web.input', return_value={'field':[]})
    def test_calls_query(self, mock_input):
        self.controller._get_query_results_from_get()
        self.assertEqual(mock_input.call_count, 1)
        self.assertEqual(self.mock_query_method.call_count, 1)
        self.assertTrue(isinstance(self.mock_query_method.call_args[0][0], Criteria))

    @mock.patch('web.input', return_value={'field':[], 'limit':10, 'foo':1, 'bar':2})
    @mock.patch('pulp.server.db.model.criteria.Criteria.from_client_input')
    def test_ignore_fields(self, mock_from_client, mock_input):
        self.controller._get_query_results_from_get(('foo','bar'))
        mock_from_client.assert_called_once_with({'limit':10})

    @mock.patch('web.input', return_value={'field':['name']})
    def test_adds_id(self, mock_input):
        # make sure it adds the 'id' field if not requested.
        self.controller._get_query_results_from_get()
        self.assertTrue('id' in self.mock_query_method.call_args[0][0].fields)
示例#5
0
文件: consumers.py 项目: ipanova/pulp
 def __init__(self):
     SearchController.__init__(self, managers.consumer_profile_manager().find_by_criteria)
 def setUp(self):
     self.mock_query_method = mock.MagicMock()
     self.controller = SearchController(self.mock_query_method)
 def setUp(self):
     self.mock_query_method = mock.MagicMock()
     self.controller = SearchController(self.mock_query_method)
     self.controller.params = mock.MagicMock(return_value=self.PARAMS)
示例#8
0
 def setUp(self):
     self.mock_query_method = mock.MagicMock()
     self.controller = SearchController(self.mock_query_method)
示例#9
0
 def setUp(self):
     self.mock_query_method = mock.MagicMock()
     self.controller = SearchController(self.mock_query_method)
     self.controller.params = mock.MagicMock(return_value=self.PARAMS)