def test_veda_tokengen_fail(self, mock_logger, mock_post): """ Tests `veda_tokengen` method logs correct error message. """ mock_post.return_value = Mock(status_code=400, text='', content={}) response = veda_tokengen() self.assertFalse(response) mock_logger.error.assert_called_with('VEDA token generation')
def test_veda_tokengen(self, mock_post): """ Tests `veda_tokengen` method works correctly. """ access_token = 'dummy-val-token' response_data = json.dumps({'access_token': access_token}) mock_post.return_value = Mock(status_code=200, text=response_data, content=response_data) response = veda_tokengen() response = json.loads(response) self.assertEqual(response['access_token'], access_token)
def test_veda_tokengen_auth_fail(self, mock_logger, mock_post): """ Tests `veda_tokengen` method logs correct error message when authorization fails. """ access_token = 'dummy-val-token' response_data = json.dumps({'access_token': access_token}) # Mock request multiple times with different responses. mock_post.side_effect = [ Mock(status_code=200, text=response_data, content=response_data), Mock(status_code=400, text='', content={}) ] response = veda_tokengen() self.assertFalse(response) mock_logger.error.assert_called_with('VEDA token authorization')