Last active
December 21, 2023 11:59
-
-
Save deepanshumehtaa/7405572860c2ecf4bc73ff2e3620a3a1 to your computer and use it in GitHub Desktop.
pytest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeDataClass: | |
url_img1 = ( | |
"https://test-m-invoice.s3.amazonaws.com/ttl-public/images/valid+image.jpg" | |
) | |
url_img2 = ( | |
"http://s3.pdd-1623763075688.jpeg" | |
) | |
class TestXYZ: | |
@pytest.fixture | |
def fixt(self, mocker): | |
"""TODO: can create fixtures with dummy db""" | |
m3 = mocker.patch("src.utilities.config.AppConfig.update_config") | |
m3.return_value = None | |
return m3 | |
@pytest.mark.parametrize( | |
"data", | |
[ | |
SomeDataClass.valid_data(), | |
SomeDataClass.valid_data2(), | |
SomeDataClass.valid_data3(), | |
SomeDataClass.valid_data_diff_case(), | |
], | |
) | |
def test_with_valid_data(self, mocker, data): | |
"""Valid Request data test""" | |
mock_app_config = mocker.patch("src.utilities.config.AppConfig") | |
mock_app_config.update_config.return_value = MockAppConfig.update_config | |
mock_app_config.AWS_REGION = MockAppConfig.AWS_REGION | |
mocker.patch("sqlalchemy.create_engine", return_value=None) | |
m3 = mocker.patch("src.utilities.config.AppConfig.update_config") | |
m3.return_value = None | |
from src.input.request_parser import ImageValidationRequestParser | |
_ = ImageValidationRequestParser(json_data=data) | |
@pytest.mark.parametrize( | |
"data", | |
[ | |
SomeDataClass.invalid_data_extra_info(), | |
SomeDataClass.invalid_url(), | |
SomeDataClass.side_invalid_type(), | |
], | |
) | |
def test_invalid_data(self, mocker, data): | |
"""Test for invalid data""" | |
m3 = mocker.patch("src.utilities.config.AppConfig.update_config") | |
m3.return_value = None | |
mocker.patch("sqlalchemy.create_engine", return_value=None) | |
from src.input.request_parser import ImageValidationRequestParser | |
with pytest.raises(exceptions.JSONInvalidTypeException): | |
_ = ImageValidationRequestParser(json_data=data) | |
@pytest.mark.parametrize( | |
"data", | |
[ | |
SomeDataClass.valid_data(), | |
SomeDataClass.valid_data2(), | |
SomeDataClass.valid_data3(), | |
], | |
) | |
def test_parse(self, fixt, data): | |
from src.input.request_parser import ImageValidationRequestParser | |
response = ImageValidationRequestParser.parse(data) | |
assert response.__class__ == ImageValidationRequestParser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment