[Tests][Datasheet download][Added] More download cases
- Already downloaded - Existing file in dry mode
This commit is contained in:
parent
181853784d
commit
af5e408335
|
|
@ -583,34 +583,51 @@ def mocked_requests_get(url, allow_redirects=True, headers=None, timeout=20):
|
|||
raise requests.exceptions.ConnectionError()
|
||||
elif url == '6':
|
||||
raise requests.exceptions.RequestException("Hello!")
|
||||
elif url == 'ok':
|
||||
res.status_code = 200
|
||||
return res
|
||||
logging.error(url)
|
||||
return res
|
||||
|
||||
|
||||
@pytest.mark.indep
|
||||
def test_ds_net_error(caplog, monkeypatch):
|
||||
def test_ds_net_error(test_dir, caplog, monkeypatch):
|
||||
ctx = context.TestContext(test_dir, 'test_v5', 'empty_zip', '')
|
||||
dummy = ctx.get_out_path('dummy')
|
||||
with open(dummy, 'wt') as f:
|
||||
f.write('Hello!')
|
||||
with context.cover_it(cov):
|
||||
o = Download_Datasheets_Options()
|
||||
o._downloaded = {}
|
||||
o.download(Comp(), '1N1234.pdf', 'pp', '1N1234', None)
|
||||
o._downloaded = {'dnl'}
|
||||
o._created = []
|
||||
c = Comp()
|
||||
o.download(c, '1N1234.pdf', 'pp', '1N1234', None)
|
||||
assert 'Invalid URL' in caplog.text
|
||||
with monkeypatch.context() as m:
|
||||
caplog.clear()
|
||||
o.download(c, 'x', 'pp', 'dnl', None)
|
||||
assert 'already downloaded' in caplog.text
|
||||
caplog.clear()
|
||||
o._dry = True
|
||||
o.download(c, 'ok', '', dummy, None)
|
||||
o._dry = False
|
||||
assert dummy in o._created
|
||||
m.setattr('requests.get', mocked_requests_get)
|
||||
caplog.clear()
|
||||
o.download(Comp(), '1', 'pp', '1N1234', None)
|
||||
o.download(c, '1', 'pp', '1N1234', None)
|
||||
assert 'Failed with status 666' in caplog.text
|
||||
caplog.clear()
|
||||
o.download(Comp(), '2', 'pp', '1N1234', None)
|
||||
o.download(c, '2', 'pp', '1N1234', None)
|
||||
assert 'Timeout' in caplog.text
|
||||
caplog.clear()
|
||||
o.download(Comp(), '3', 'pp', '1N1234', None)
|
||||
o.download(c, '3', 'pp', '1N1234', None)
|
||||
assert 'SSL Error' in caplog.text
|
||||
caplog.clear()
|
||||
o.download(Comp(), '4', 'pp', '1N1234', None)
|
||||
o.download(c, '4', 'pp', '1N1234', None)
|
||||
assert 'More than 30 redirections' in caplog.text
|
||||
caplog.clear()
|
||||
o.download(Comp(), '5', 'pp', '1N1234', None)
|
||||
o.download(c, '5', 'pp', '1N1234', None)
|
||||
assert 'Connection' in caplog.text
|
||||
caplog.clear()
|
||||
o.download(Comp(), '6', 'pp', '1N1234', None)
|
||||
o.download(c, '6', 'pp', '1N1234', None)
|
||||
assert 'Hello!' in caplog.text
|
||||
|
|
|
|||
Loading…
Reference in New Issue