add test_keyfile
This commit is contained in:
parent
cf817ffe27
commit
6fcf5869ad
|
@ -1,8 +1,34 @@
|
|||
import configparser
|
||||
import pytest
|
||||
import asyncio
|
||||
import io
|
||||
|
||||
from nvchecker.get_version import get_version as _get_version
|
||||
from nvchecker.core import Source
|
||||
|
||||
class TestSource(Source):
|
||||
def __init__(self, future, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._future = future
|
||||
|
||||
def on_update(self, name, version, oldver):
|
||||
self._future.set_result(version)
|
||||
|
||||
def on_exception(self, name, exc):
|
||||
self._future.set_exception(exc)
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
async def run_source():
|
||||
async def __call__(conf):
|
||||
future = asyncio.Future()
|
||||
file = io.StringIO(conf)
|
||||
file.name = '<StringIO>'
|
||||
|
||||
s = TestSource(future, file)
|
||||
await s.check()
|
||||
return await future
|
||||
|
||||
return __call__
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
async def get_version():
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2018 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
pytestmark = [pytest.mark.asyncio]
|
||||
|
||||
async def test_keyfile_missing(run_source):
|
||||
test_conf = '''\
|
||||
[example]
|
||||
github = harry-sanabria/ReleaseTestRepo
|
||||
'''
|
||||
|
||||
assert await run_source(test_conf) == '20140122.012101'
|
||||
|
||||
async def test_keyfile_invalid(run_source):
|
||||
with tempfile.NamedTemporaryFile(mode='w+') as f:
|
||||
f.write('''\
|
||||
[keys]
|
||||
github = xxx
|
||||
''')
|
||||
f.flush()
|
||||
test_conf = f'''\
|
||||
[example]
|
||||
github = harry-sanabria/ReleaseTestRepo
|
||||
|
||||
[__config__]
|
||||
keyfile = {f.name}
|
||||
'''
|
||||
|
||||
try:
|
||||
await run_source(test_conf)
|
||||
except Exception as e:
|
||||
assert e.code == 401
|
Loading…
Reference in New Issue