-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporary tests for feature flagging
Why these changes are being introduced: * We do not need to heavily test the feature flagging logic, knowing it will be removed after development work. But a bit of testing can ensure that it works as expected while termporarily in a deployed state. How this addresses that need: * Adds new test file tests/test_temporary_feature_flagging.py that is noted to be removed after development work is complete * Test branching logic in Format Input handler using 'ETL_VERSION' env var * Test config function for retrieving 'ETL_VERSION' env var Side effects of this change: * None Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/TIMX-412
- Loading branch information
1 parent
9f4d3ba
commit 766cf59
Showing
1 changed file
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# ruff: noqa: PLR2004 | ||
|
||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from lambdas import format_input | ||
from lambdas.config import get_etl_version | ||
|
||
# NOTE: FEATURE FLAG: this test file can be removed completely after v2 parquet work. | ||
|
||
|
||
@pytest.fixture | ||
def mocked_etl_v1_generate_transform_commands_method(): | ||
with patch( | ||
"lambdas.commands._etl_v1_generate_transform_commands_method" | ||
) as mocked_method: | ||
yield mocked_method | ||
|
||
|
||
@pytest.fixture | ||
def mocked_etl_v2_generate_transform_commands_method(): | ||
with patch( | ||
"lambdas.commands._etl_v2_generate_transform_commands_method" | ||
) as mocked_method: | ||
yield mocked_method | ||
|
||
|
||
@pytest.fixture | ||
def mocked_etl_v1_generate_load_commands_method(): | ||
with patch("lambdas.commands._etl_v1_generate_load_commands_method") as mocked_method: | ||
yield mocked_method | ||
|
||
|
||
@pytest.fixture | ||
def mocked_etl_v2_generate_load_commands_method(): | ||
with patch("lambdas.commands._etl_v2_generate_load_commands_method") as mocked_method: | ||
yield mocked_method | ||
|
||
|
||
def test_etl_version_helper_function_no_env_var_is_v1(monkeypatch): | ||
monkeypatch.delenv("ETL_VERSION") | ||
assert get_etl_version() == 1 | ||
|
||
|
||
def test_etl_version_helper_function_env_var_is_1_is_v1(monkeypatch): | ||
monkeypatch.setenv("ETL_VERSION", "1") | ||
assert get_etl_version() == 1 | ||
|
||
|
||
def test_etl_version_helper_function_env_var_is_2_is_v2(monkeypatch): | ||
monkeypatch.setenv("ETL_VERSION", "2") | ||
assert get_etl_version() == 2 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"env_value", | ||
[ | ||
"pumpkin_pie", # throws ValueError because not integer | ||
"3", # throws ValueError because not 1 or 2 | ||
], | ||
) | ||
def test_etl_version_helper_function_env_var_value_is_unsupported(env_value, monkeypatch): | ||
monkeypatch.setenv("ETL_VERSION", env_value) | ||
with pytest.raises(ValueError): # noqa: PT011 | ||
get_etl_version() | ||
|
||
|
||
def test_lambda_handler_etl_version_v1_with_next_step_transform_invokes_v1_code( | ||
mocked_etl_v1_generate_transform_commands_method, s3_client | ||
): | ||
s3_client.put_object( | ||
Bucket="test-timdex-bucket", | ||
Key="testsource/testsource-2022-01-02-daily-extracted-records-to-index.xml", | ||
Body="I am a file", | ||
) | ||
event = { | ||
"run-date": "2022-01-02T12:13:14Z", | ||
"run-type": "daily", | ||
"next-step": "transform", | ||
"source": "testsource", | ||
"verbose": "true", | ||
} | ||
format_input.lambda_handler(event, {}) | ||
mocked_etl_v1_generate_transform_commands_method.assert_called() | ||
|
||
|
||
def test_lambda_handler_etl_version_v2_with_next_step_transform_invokes_v2_code( | ||
mocked_etl_v2_generate_transform_commands_method, monkeypatch, s3_client | ||
): | ||
monkeypatch.setenv("ETL_VERSION", "2") | ||
s3_client.put_object( | ||
Bucket="test-timdex-bucket", | ||
Key="testsource/testsource-2022-01-02-daily-extracted-records-to-index.xml", | ||
Body="I am a file", | ||
) | ||
event = { | ||
"run-date": "2022-01-02T12:13:14Z", | ||
"run-type": "daily", | ||
"next-step": "transform", | ||
"source": "testsource", | ||
"verbose": "true", | ||
} | ||
format_input.lambda_handler(event, {}) | ||
mocked_etl_v2_generate_transform_commands_method.assert_called() | ||
|
||
|
||
def test_lambda_handler_etl_version_v1_with_next_step_load_invokes_v1_code( | ||
mocked_etl_v1_generate_load_commands_method, s3_client | ||
): | ||
s3_client.put_object( | ||
Bucket="test-timdex-bucket", | ||
Key="testsource/testsource-2022-01-02-daily-transformed-records-to-index.xml", | ||
Body="I am a file", | ||
) | ||
event = { | ||
"run-date": "2022-01-02T12:13:14Z", | ||
"run-type": "daily", | ||
"next-step": "load", | ||
"source": "testsource", | ||
} | ||
format_input.lambda_handler(event, {}) | ||
mocked_etl_v1_generate_load_commands_method.assert_called() | ||
|
||
|
||
def test_lambda_handler_etl_version_v2_with_next_step_load_invokes_v2_code( | ||
mocked_etl_v2_generate_load_commands_method, monkeypatch, s3_client | ||
): | ||
monkeypatch.setenv("ETL_VERSION", "2") | ||
s3_client.put_object( | ||
Bucket="test-timdex-bucket", | ||
Key="testsource/testsource-2022-01-02-daily-transformed-records-to-index.xml", | ||
Body="I am a file", | ||
) | ||
event = { | ||
"run-date": "2022-01-02T12:13:14Z", | ||
"run-type": "daily", | ||
"next-step": "load", | ||
"source": "testsource", | ||
} | ||
format_input.lambda_handler(event, {}) | ||
mocked_etl_v2_generate_load_commands_method.assert_called() |