def testGetCatalogForbiden(self, mock_ucs): """Invoke a 403 http error""" # setup UCS mocks mock_ucs.return_value.login.return_value = False # call getCaltalog result = controler.getCatalog(HOST, USER, PASS, 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': 'Forbiden', 'stack': ''}, 403))
def testGetCatalogFailure(self, mock_ucs): # setup UCS mocks mock_ucs.return_value.login.return_value = False # call getCaltalog result = controler.getCatalog(HOST, USER, PASS, 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() mock_ucs.return_value.logout.assert_not_called() self.assertIsNone(result)
def testGetCatalogInternalServerError(self, mock_ucs): """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 = [""] # call getCaltalog result = controler.getCatalog(HOST, USER, PASS, 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) # verify return data self.assertEqual(result, ({'message': "Couldn't fetch sys/rack1", 'stack': '', 'status': 500}, 500))
def testGetCatalogSuccess(self, mock_ucs): # 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)]] # call getCaltalog result = controler.getCatalog(HOST, USER, PASS, 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"')\