Update tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
|
from pathlib import Path
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -42,10 +43,10 @@ def test_split_scopes(test_scopes: str, expected: set[str]):
|
|||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.parametrize('test_scopes', (
|
@pytest.mark.parametrize('test_scopes', (
|
||||||
('random',),
|
{'random', },
|
||||||
('scope', 'another_scope'),
|
{'scope', 'another_scope'},
|
||||||
))
|
))
|
||||||
def test_check_scopes_bad(test_scopes: list[str]):
|
def test_check_scopes_bad(test_scopes: set[str]):
|
||||||
with pytest.raises(BulkDownloaderException):
|
with pytest.raises(BulkDownloaderException):
|
||||||
OAuth2Authenticator._check_scopes(test_scopes)
|
OAuth2Authenticator._check_scopes(test_scopes)
|
||||||
|
|
||||||
@@ -53,14 +54,18 @@ def test_check_scopes_bad(test_scopes: list[str]):
|
|||||||
def test_token_manager_read(example_config: configparser.ConfigParser):
|
def test_token_manager_read(example_config: configparser.ConfigParser):
|
||||||
mock_authoriser = MagicMock()
|
mock_authoriser = MagicMock()
|
||||||
mock_authoriser.refresh_token = None
|
mock_authoriser.refresh_token = None
|
||||||
test_manager = OAuth2TokenManager(example_config)
|
test_manager = OAuth2TokenManager(example_config, None)
|
||||||
test_manager.pre_refresh_callback(mock_authoriser)
|
test_manager.pre_refresh_callback(mock_authoriser)
|
||||||
assert mock_authoriser.refresh_token == example_config.get('DEFAULT', 'user_token')
|
assert mock_authoriser.refresh_token == example_config.get('DEFAULT', 'user_token')
|
||||||
|
|
||||||
|
|
||||||
def test_token_manager_write(example_config: configparser.ConfigParser):
|
def test_token_manager_write(example_config: configparser.ConfigParser, tmp_path: Path):
|
||||||
|
test_path = tmp_path / 'test.cfg'
|
||||||
mock_authoriser = MagicMock()
|
mock_authoriser = MagicMock()
|
||||||
mock_authoriser.refresh_token = 'changed_token'
|
mock_authoriser.refresh_token = 'changed_token'
|
||||||
test_manager = OAuth2TokenManager(example_config)
|
test_manager = OAuth2TokenManager(example_config, test_path)
|
||||||
test_manager.post_refresh_callback(mock_authoriser)
|
test_manager.post_refresh_callback(mock_authoriser)
|
||||||
assert example_config.get('DEFAULT', 'user_token') == 'changed_token'
|
assert example_config.get('DEFAULT', 'user_token') == 'changed_token'
|
||||||
|
with open(test_path, 'r') as file:
|
||||||
|
file_contents = file.read()
|
||||||
|
assert 'user_token = changed_token' in file_contents
|
||||||
|
|||||||
Reference in New Issue
Block a user