Skip to content

Commit

Permalink
make plint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zavarin-michael committed Jan 9, 2024
1 parent c9458ec commit 5a09e6c
Showing 1 changed file with 42 additions and 40 deletions.
82 changes: 42 additions & 40 deletions tests/unit/publication/gitlab/tokenizer/test_client.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
from unittest.mock import MagicMock, patch

import pytest

from overhave.publication.gitlab.tokenizer import TokenizerClient
from overhave.publication.gitlab.tokenizer.client import InvalidUrlException


class TestTokenizerClient:
"""Tests for :class:`TokenizerClient`."""

@pytest.mark.parametrize(
"test_tokenizer_client",
[{"initiator": "peka", "remote_key": "pepe", "remote_key_name": "sad-pepe", "url": "https://ya.ru"}],
indirect=True,
)
def test_tokenizer_client_get_token_works(self, test_tokenizer_client) -> None:
token_mock = "magic_token"
draft_id_mock = 4

client = test_tokenizer_client

request_mock = MagicMock()
request_mock.json = MagicMock(return_value={"token": token_mock})

with patch.object(TokenizerClient, "_make_request", return_value=request_mock) as make_request:
tokenizer_client = client.get_token(draft_id_mock)
assert tokenizer_client.token == token_mock
make_request.assert_called_once()

@pytest.mark.parametrize(
"test_tokenizer_client",
[{"initiator": "peka", "remote_key": "pepe", "remote_key_name": "sad-pepe"}],
indirect=True,
)
def test_tokenizer_client_get_token_url_validation_raises_error(self, test_tokenizer_client) -> None:
draft_id_mock = 4

with pytest.raises(InvalidUrlException):
test_tokenizer_client.get_token(draft_id_mock)
from unittest.mock import MagicMock, patch

import pytest

from overhave.publication.gitlab.tokenizer import TokenizerClient
from overhave.publication.gitlab.tokenizer.client import InvalidUrlException


class TestTokenizerClient:
"""Tests for :class:`TokenizerClient`."""

@pytest.mark.parametrize(
"test_tokenizer_client",
[{"initiator": "peka", "remote_key": "pepe", "remote_key_name": "sad-pepe", "url": "https://ya.ru"}],
indirect=True,
)
def test_tokenizer_client_get_token_works(self, test_tokenizer_client: TokenizerClient) -> None:
token_mock = "magic_token"
draft_id_mock = 4

client = test_tokenizer_client

request_mock = MagicMock()
request_mock.json = MagicMock(return_value={"token": token_mock})

with patch.object(TokenizerClient, "_make_request", return_value=request_mock) as make_request:
tokenizer_client = client.get_token(draft_id_mock)
assert tokenizer_client.token == token_mock
make_request.assert_called_once()

@pytest.mark.parametrize(
"test_tokenizer_client",
[{"initiator": "peka", "remote_key": "pepe", "remote_key_name": "sad-pepe"}],
indirect=True,
)
def test_tokenizer_client_get_token_url_validation_raises_error(
self, test_tokenizer_client: TokenizerClient
) -> None:
draft_id_mock = 4

with pytest.raises(InvalidUrlException):
test_tokenizer_client.get_token(draft_id_mock)

0 comments on commit 5a09e6c

Please sign in to comment.