-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9458ec
commit 5a09e6c
Showing
1 changed file
with
42 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |