7df8ed4a60
Change SecScanAPI to use a uri creation func instead of test context Pass config provider through validator context Remove app config dependency for validators
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import pytest
|
|
|
|
from httmock import urlmatch, HTTMock
|
|
|
|
from config import build_requests_session
|
|
from util.config.validator import ValidatorContext
|
|
from util.config.validators import ConfigValidationException
|
|
from util.config.validators.validate_torrent import BittorrentValidator
|
|
|
|
from test.fixtures import *
|
|
|
|
@pytest.mark.parametrize('unvalidated_config,expected', [
|
|
({}, ConfigValidationException),
|
|
({'BITTORRENT_ANNOUNCE_URL': 'http://faketorrent/announce'}, None),
|
|
])
|
|
def test_validate_torrent(unvalidated_config, expected, app):
|
|
announcer_hit = [False]
|
|
|
|
@urlmatch(netloc=r'faketorrent', path='/announce')
|
|
def handler(url, request):
|
|
announcer_hit[0] = True
|
|
return {'status_code': 200, 'content': ''}
|
|
|
|
with HTTMock(handler):
|
|
validator = BittorrentValidator()
|
|
if expected is not None:
|
|
with pytest.raises(expected):
|
|
config = ValidatorContext(unvalidated_config)
|
|
config.http_client = build_requests_session()
|
|
|
|
validator.validate(config)
|
|
assert not announcer_hit[0]
|
|
else:
|
|
config = ValidatorContext(unvalidated_config)
|
|
config.http_client = build_requests_session()
|
|
|
|
validator.validate(config)
|
|
assert announcer_hit[0]
|