1
0
Fork 0
mirror of synced 2024-06-26 10:00:20 +12:00

Update tests

This commit is contained in:
Serene-Arc 2021-03-09 19:32:51 +10:00 committed by Ali Parlakci
parent afe618916b
commit 933be21392

View file

@ -2,6 +2,7 @@
# coding=utf-8
import configparser
from pathlib import Path
from unittest.mock import MagicMock
import pytest
@ -42,10 +43,10 @@ def test_split_scopes(test_scopes: str, expected: set[str]):
@pytest.mark.online
@pytest.mark.parametrize('test_scopes', (
('random',),
('scope', 'another_scope'),
{'random', },
{'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):
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):
mock_authoriser = MagicMock()
mock_authoriser.refresh_token = None
test_manager = OAuth2TokenManager(example_config)
test_manager = OAuth2TokenManager(example_config, None)
test_manager.pre_refresh_callback(mock_authoriser)
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.refresh_token = 'changed_token'
test_manager = OAuth2TokenManager(example_config)
test_manager = OAuth2TokenManager(example_config, test_path)
test_manager.post_refresh_callback(mock_authoriser)
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