def test_device_get_index(self, mock_f1, mock_f2):
     mock_f1.side_effect = [{'device': 1}, {'device': 2}]
     mock_f2.return_value = [[{'id': 1}], [{'id': 2}]]
     resp = api.device_get_index(self.conf)
     self.assertEqual(resp, [{'device': 1}, {'device': 2}])
     self.assertTrue(mock_f1.called)
     self.assertTrue(mock_f2.called)
     mock_f1.assert_any_call([{'id': 1}])
     mock_f1.assert_any_call([{'id': 2}])
     mock_f2.assert_called_once_with(self.conf)
Beispiel #2
0
 def index(self,  req):
     try:
         logger.debug("Got index request. Request: %s", req)
         result = core_api.device_get_index(self.conf)
         logger.debug("Obtained response: %s" % result)
         return {'devices': result}
     except exception.NotFound:
         msg = "Element not found"
         logger.debug(msg)
         raise webob.exc.HTTPNotFound(msg)
     except exception.NotAuthorized:
         msg = _("Unauthorized access")
         logger.debug(msg)
         raise webob.exc.HTTPForbidden(msg)
 def test_device_get_index(self, mock_f1, mock_f2):
     mock_f2.__iter__.return_value = 1
     api.device_get_index(self.conf)
     self.assertTrue(mock_f2.called, "None")