def testGetCatalogInternalServerError(self, mock_ucs, mock_request): """Invoke a 500 http error""" # setup UCS mocks mock_ucs.return_value.login.return_value = True mock_ucs.return_value.logout.return_value = True mock_ucs.return_value.query_children.side_effect = [[]] mock_ucs.return_value.query_dn.side_effect = UcsException( 500, "Mock Server Error") mock_request.headers = MOCK_HEADER # call getCaltalog result = controler.getCatalog(identifier=MOCK_ID) # verify UCS Mocks were called mock_ucs.assert_called_with(HOST, USER, PASS, secure=False) mock_ucs.return_value.login.assert_called_once() calls = [mock.call(in_dn=MOCK_ID)] mock_ucs.return_value.query_children.assert_has_calls(calls) calls = [mock.call(dn=MOCK_ID)] mock_ucs.return_value.query_dn.assert_has_calls(calls) # verify return data self.assertEqual(result, ({ 'message': "Internal Server Error", 'stack': 'Mock Server Error', 'status': 500 }, 500))
def testGetCatalogForbiden(self, mock_ucs, mock_request, mock_current_app): """Invoke a 403 http error""" # setup UCS mocks mock_ucs.return_value = None mock_request.headers = MOCK_HEADER mock_current_app.config.get.return_value = self.mockCurrentApp("Anything") # call getCaltalog result = controler.getCatalog(identifier=MOCK_ID) # verify UCS Mocks were not called headers = {'ucs-user': USER, 'ucs-host': HOST, 'ucs-password': PASS} mock_ucs.assert_called_with(headers, mock_current_app.config.get("handlers")) self.assertEqual(result, ({'status': 403, 'message': 'Forbidden', 'stack': ''}, 403))
def testGetCatalogForbiden(self, mock_ucs, mock_request): """Invoke a 403 http error""" # setup UCS mocks mock_ucs.return_value.login.return_value = False mock_request.headers = MOCK_HEADER # call getCaltalog result = controler.getCatalog(identifier=MOCK_ID) # verify UCS Mocks were not called mock_ucs.assert_called_with(HOST, USER, PASS, secure=False) mock_ucs.return_value.login.assert_called_once() mock_ucs.return_value.query_dn.assert_not_called() self.assertEqual(result, ({'status': 403, 'message': 'Forbidden', 'stack': ''}, 403))
def testGetCatalogSuccess(self, mock_ucs, mock_request, mock_current_app): # setup UCS mocks mock_ucs.return_value.query_children.side_effect = [[self.mockCatalogClass(data=MOCK_DATA)]] mock_request.headers = MOCK_HEADER mock_current_app.config.get.return_value = self.mockCurrentApp("Anything").config # call getCaltalog result = controler.getCatalog(identifier=MOCK_ID) # verify UCS Mocks were called headers = {'ucs-user': USER, 'ucs-host': HOST, 'ucs-password': PASS} mock_ucs.assert_called_with(headers, mock_current_app.config.get("handlers")) calls = [mock.call(in_dn=MOCK_ID)] mock_ucs.return_value.query_children.assert_has_calls(calls) # verify return data self.assertIn({'data': 'data'}, result[0], 'result does not contain member "data"') self.assertEqual(MOCK_DATA, result[0][0]['data'], 'result["data"] does not equal "{}"'.format(MOCK_DATA)) self.assertNotIn('_privData', result[0], 'result contains private member "_privData"')\
def testGetCatalogSuccess(self, mock_ucs, mock_request): # setup UCS mocks mock_ucs.return_value.login.return_value = True mock_ucs.return_value.logout.return_value = True mock_ucs.return_value.query_children.side_effect = [[self.mockCatalogClass(data=MOCK_DATA)]] mock_request.headers = MOCK_HEADER # call getCaltalog result = controler.getCatalog(identifier=MOCK_ID) # verify UCS Mocks were called mock_ucs.assert_called_with(HOST, USER, PASS, secure=False) mock_ucs.return_value.login.assert_called_once() calls = [mock.call(in_dn=MOCK_ID)] mock_ucs.return_value.query_children.assert_has_calls(calls) mock_ucs.return_value.logout.assert_called_once() # verify return data self.assertIn({'data': 'data'}, result, 'result does not contain member "data"') self.assertEqual(MOCK_DATA, result[0]['data'], 'result["data"] does not equal "{}"'.format(MOCK_DATA)) self.assertNotIn('_privData', result, 'result contains private member "_privData"')\