Skip to content

Commit

Permalink
Merge pull request #14 from zavarin-michael/master
Browse files Browse the repository at this point in the history
Заварин Михаил. Тесты для tokenizer client
  • Loading branch information
artamaney authored Jan 14, 2024
2 parents 14e1a16 + 5a09e6c commit 9919d5d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/unit/publication/gitlab/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Callable, Mapping, Sequence, cast

import pytest
from _pytest.fixtures import FixtureRequest
from faker import Faker
from pytest_mock import MockFixture

Expand Down Expand Up @@ -67,6 +68,16 @@ def get_tokenizer_settings():
return get_tokenizer_settings


@pytest.fixture()
def test_tokenizer_client(request: FixtureRequest) -> TokenizerClient:
return TokenizerClient(
settings=TokenizerClientSettings(
enabled=True,
**request.param,
)
)


@pytest.fixture()
def test_gitlab_publisher_with_default_reviewers(
test_file_settings: OverhaveFileSettings,
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/publication/gitlab/tokenizer/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +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: 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 9919d5d

Please sign in to comment.