from src.store_utils import _abbreviate_owner, derive_schema_name, normalise_url class TestNormaliseUrl: def test_strips_https_scheme(self): assert normalise_url("https://test.myshopify.com") == "test.myshopify.com" def test_strips_http_scheme(self): assert normalise_url("http://test.myshopify.com") == "test.myshopify.com" def test_strips_www(self): assert normalise_url("www.test.myshopify.com") == "test.myshopify.com" def test_lowercases(self): assert normalise_url("TEST.MYSHOPIFY.COM") == "test.myshopify.com" def test_strips_trailing_slash(self): assert normalise_url("test.myshopify.com/") == "test.myshopify.com" def test_strips_path(self): assert normalise_url("https://test.myshopify.com/some/path") == "test.myshopify.com" def test_strips_query_string(self): assert normalise_url("https://test.myshopify.com?foo=bar") == "test.myshopify.com" def test_strips_fragment(self): assert normalise_url("https://test.myshopify.com#section") == "test.myshopify.com" def test_strips_surrounding_whitespace(self): assert normalise_url(" test.myshopify.com ") == "test.myshopify.com" def test_strips_surrounding_quotes(self): assert normalise_url('"test.myshopify.com"') == "test.myshopify.com" def test_https_www_combined(self): assert normalise_url("https://www.test.myshopify.com/") == "test.myshopify.com" class TestAbbreviateOwner: def test_ceremony_of_roses(self): assert _abbreviate_owner("Ceremony of Roses") == "COR" def test_the_orchard(self): assert _abbreviate_owner("The Orchard") == "ORCHARD" def test_kings_road(self): assert _abbreviate_owner("Kings Road") == "KRM" def test_kings_road_merch_eu(self): assert _abbreviate_owner("Kings Road Merch EU") == "KRM" def test_kings_road_merch_us(self): assert _abbreviate_owner("Kings Road Merch US") == "KRM" def test_none_returns_empty(self): assert _abbreviate_owner(None) == "" def test_empty_string_returns_empty(self): assert _abbreviate_owner("") == "" def test_whitespace_only_returns_empty(self): assert _abbreviate_owner(" ") == "" def test_comment_value_returns_empty(self): assert _abbreviate_owner("#some comment") == "" def test_arbitrary_value_uppercased_with_underscores(self): assert _abbreviate_owner("Sony Music Entertainment") == "SONY_MUSIC_ENTERTAINMENT" def test_leading_trailing_underscores_stripped(self): result = _abbreviate_owner(" Brand ") assert not result.startswith("_") assert not result.endswith("_") class TestDeriveSchemaName: def test_basic_no_country_no_owner(self): assert derive_schema_name("test.myshopify.com", None, None, None) == "shopify_test" def test_dashes_in_slug_become_underscores(self): assert derive_schema_name("my-store.myshopify.com", None, None, None) == "shopify_my_store" def test_myshopify_suffix_stripped(self): result = derive_schema_name("brand.myshopify.com", None, None, None) assert "myshopify" not in result def test_with_rep_owner(self): assert derive_schema_name("test.myshopify.com", None, "Ceremony of Roses", None) == "shopify_cor_test" def test_with_selling_country(self): assert derive_schema_name("test.myshopify.com", "US", None, None) == "shopify_us_test" def test_with_owner_and_country(self): assert derive_schema_name("test.myshopify.com", "GB", "Ceremony of Roses", None) == "shopify_cor_gb_test" def test_rep_owner_takes_precedence_over_merch_company(self): result = derive_schema_name("test.myshopify.com", None, "Ceremony of Roses", "Kings Road") assert result == "shopify_cor_test" def test_merch_company_used_when_rep_owner_absent(self): result = derive_schema_name("test.myshopify.com", None, None, "Ceremony of Roses") assert result == "shopify_cor_test" def test_country_starting_with_hash_is_ignored(self): assert derive_schema_name("test.myshopify.com", "#N/A", None, None) == "shopify_test" def test_result_is_lowercase(self): result = derive_schema_name("TEST.myshopify.com", "US", None, None) assert result == result.lower() def test_country_uppercased_in_result(self): assert derive_schema_name("test.myshopify.com", "gb", None, None) == "shopify_gb_test"