From f024e9cf57ee563e3291ae0810aa816cd282f626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Freitag?= Date: Fri, 23 Feb 2024 12:01:24 +0100 Subject: [PATCH] Remove PhoneNumberInternationalFallbackWidget Following the deprecation plan. --- phonenumber_field/widgets.py | 20 ---------------- tests/test_widgets.py | 44 +----------------------------------- 2 files changed, 1 insertion(+), 63 deletions(-) diff --git a/phonenumber_field/widgets.py b/phonenumber_field/widgets.py index c11b59b3..ff9d11b7 100644 --- a/phonenumber_field/widgets.py +++ b/phonenumber_field/widgets.py @@ -163,23 +163,3 @@ def format_value(self, value): if self.region in region_codes: return value.as_national return super().format_value(value) - - -class PhoneNumberInternationalFallbackWidget(RegionalPhoneNumberWidget): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - warnings.warn( - f"{self.__class__.__name__} will be removed in the next major version. " - "Use phonenumber_field.widgets.RegionalPhoneNumberWidget instead.", - DeprecationWarning, - stacklevel=2, - ) - - def format_value(self, value): - if isinstance(value, PhoneNumber): - if value.is_valid() and value.country_code: - region_codes = region_codes_for_country_code(value.country_code) - if self.region in region_codes: - return value.as_national - return value.as_international - return super().format_value(value) diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 988d50c5..edea1a44 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -7,11 +7,7 @@ from phonenumber_field import formfields, widgets from phonenumber_field.phonenumber import PhoneNumber -from phonenumber_field.widgets import ( - PhoneNumberInternationalFallbackWidget, - PhoneNumberPrefixWidget, - RegionalPhoneNumberWidget, -) +from phonenumber_field.widgets import PhoneNumberPrefixWidget, RegionalPhoneNumberWidget class PhonePrefixSelectTest(SimpleTestCase): @@ -313,41 +309,3 @@ def test_no_region(self): widget.render("number", number), f'', ) - - -class PhoneNumberInternationalFallbackWidgetTest(SimpleTestCase): - def test_raises_deprecation_warning(self): - msg = ( - "PhoneNumberInternationalFallbackWidget will be removed in the next major " - "version. Use phonenumber_field.widgets.RegionalPhoneNumberWidget " - "instead." - ) - with self.assertWarnsMessage(DeprecationWarning, msg): - - class _(forms.Form): - number = formfields.PhoneNumberField( - widget=PhoneNumberInternationalFallbackWidget - ) - - def test_fallback_widget_switches_between_national_and_international(self): - region = "GB" - number_string = "01606 751 78" - number = PhoneNumber.from_string(number_string, region=region) - gb_widget = PhoneNumberInternationalFallbackWidget() - gb_widget.region = "GB" - de_widget = PhoneNumberInternationalFallbackWidget() - de_widget.region = "DE" - self.assertHTMLEqual( - gb_widget.render("number", number), - '', - ) - self.assertHTMLEqual( - de_widget.render("number", number), - '', - ) - - # If there's been a validation error, the value should be included verbatim - self.assertHTMLEqual( - gb_widget.render("number", "error"), - '', - )