Skip to content

Commit

Permalink
fix: test_renew_non_json_body not connect to a real url (#669)
Browse files Browse the repository at this point in the history
The test should not connect to a real url but mock the connection
properly
  • Loading branch information
bzwei authored Mar 13, 2024
1 parent 0c5b709 commit baae810
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/test_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest.mock import patch
from unittest.mock import MagicMock, patch

import aiohttp
import pytest

from ansible_rulebook import token
Expand All @@ -26,6 +27,10 @@ def __init__(self, data):
self.data = data

async def json(self):
if not isinstance(self.data, dict):
raise aiohttp.client_exceptions.ContentTypeError(
MagicMock(), MagicMock()
)
return self.data

async def __aexit__(self, exc_type, exc, tb):
Expand Down Expand Up @@ -64,5 +69,8 @@ async def test_renew_invalid_token():
@pytest.mark.asyncio
async def test_renew_non_json_body():
prepare_settings()
with pytest.raises(TokenNotFound):
await token.renew_token()
with patch("ansible_rulebook.token.aiohttp.ClientSession.post") as mock:
data = "non json text"
mock.return_value = MockResponse(data)
with pytest.raises(TokenNotFound):
await token.renew_token()

0 comments on commit baae810

Please sign in to comment.