From 923319ac9329cee8210912457418f9cfc417519a Mon Sep 17 00:00:00 2001 From: Christopher Dixon Date: Mon, 13 Nov 2023 11:24:03 -0500 Subject: [PATCH] wip: test_get --- tests/test_utils.py | 57 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 5e4c88e..5cbc4ad 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,8 +1,9 @@ import os import click import pytest +import requests from click.testing import CliRunner - +from requests.exceptions import ConnectionError, ChunkedEncodingError from src.getdat.utils import print_help, AnnasEbook class TestPrintHelp: @@ -282,4 +283,56 @@ def test__get_url( _scrape_key ) kwargs = {"link": link} - assert ebook._get_url(**kwargs) == expected_url \ No newline at end of file + assert ebook._get_url(**kwargs) == expected_url + + @pytest.mark.parametrize( + "msg, error, error_msg, is_download", + [ + ( + "This is a message echoed to user", + None, + "", + False + ), + ( + "", + None, + "", + False + ), + ( + "This is a message echoed to user", + ConnectionError, + "No connection established", + False + ), + ( + "", + ChunkedEncodingError, + "No connection established", + False + ), + ( + "", + ConnectionError, + "No connection established", + True + ), + ( + "This is a message echoed to user", + ChunkedEncodingError, + "No connection established", + True + ) + ] + ) + def test__get(self, msg, error, error_msg, is_download, mocker): + ebook = AnnasEbook(q=self.q, ext=self.ext, output_dir=self.output_dir) + mocked_get = mocker.patch.object(requests, 'get') + if error: + mocked_get.side_effect = error + else: + mocked_get.return_value = "OK" + # No error occured and returns response + assert ebook._get() == "OK" +