From af5e40833545921f21f5b29c6c44210d864b8d7e Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 25 Jan 2024 14:16:04 -0300 Subject: [PATCH] [Tests][Datasheet download][Added] More download cases - Already downloaded - Existing file in dry mode --- tests/test_plot/test_misc_2.py | 35 +++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/tests/test_plot/test_misc_2.py b/tests/test_plot/test_misc_2.py index d28e0dba..5ac7695f 100644 --- a/tests/test_plot/test_misc_2.py +++ b/tests/test_plot/test_misc_2.py @@ -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