"""Test string utility functions.""" import pytest from royalties.utils.strings import ( base64decode, from_camelcase_to_snakecase, sanitize_s3_path, ) @pytest.mark.parametrize( 'test_string,expected', [ ('abC', 'abC'), ('++hello## world.', 'helloworld'), ('', ''), ('!KS93kd&3\\?1`(756^%$)', '!KS93kd31(756)'), ], ) def test_sanitize_s3_path(test_string, expected): """Test sanitize_s3_path.""" result = sanitize_s3_path(test_string) assert result == expected @pytest.mark.parametrize( 'test_string,expected', [ ('fooBar', 'foo_bar'), ('Foo', 'foo'), ('fooCSVBar', 'foo_csvbar'), ('foobar', 'foobar'), ('A', 'a'), ], ) def test_from_camelcase_to_snakecase(test_string, expected): """Test converting camelcase strings to snakecase.""" result = from_camelcase_to_snakecase(test_string) assert result == expected def test_base64decode(b64encoded_exchange_rates): """Test decoding base64 to csv data.""" result = base64decode(b64encoded_exchange_rates) expected = ( 'accounting_period_id\tfrom_currency_code\tto_currency_code\trate\n' '1026\tUSD\tEUR\t1.36\n' '1026\tUSD\tUAH\t0.039\n' '1026\tUSD\tRUB\t0.0123\n' '1026\tUSD\tGBP\t1.12\n' '1026\tUSD\tPLN\t0.12\n' ) assert result == expected