"""Tests for data transformation module.""" from flexmock import flexmock import pytest from availability_etl import constants from availability_etl import transform @pytest.mark.parametrize('store_id', constants.STORE_IDS) def test_store_internal_id_to_storefront_url(store_id): """Test store internal id to storefront url transformation.""" store_internal_id = 'some_id' row = dict( store_internal_id=store_internal_id, store_id=store_id, foo='bar', ) url_template = constants.STOREFRONT_URLS_TEMPLATES[store_id] expected_output = row.copy() del expected_output['store_internal_id'] expected_output['storefront_url'] = url_template.format(store_internal_id) assert ( transform.store_internal_id_to_storefront_url(row) == expected_output) @pytest.mark.parametrize('store_id', constants.STORE_IDS) def test_empty_store_internal_id_to_storefront_url(store_id): """Test empty store internal id to storefront url transformation.""" row = dict( store_internal_id='', store_id=store_id, foo='bar', ) expected_output = row.copy() del expected_output['store_internal_id'] expected_output['storefront_url'] = constants.CSV_EMPTY_STR assert ( transform.store_internal_id_to_storefront_url(row) == expected_output) @pytest.mark.parametrize( 'input_rows', ( (dict(foo='foo', bar='bar'), dict()), (), ) ) def test_transformed(input_rows): """Test transformed data rows generator.""" (flexmock(transform, store_internal_id_to_storefront_url=lambda x: x)) output_rows = list(transform.transformed(iter(input_rows))) assert len(input_rows) == len(output_rows) for out_row, expected_out in zip(input_rows, output_rows): assert out_row == expected_out