From 8d1753c9ee01533dd6529a77b74671dc05240142 Mon Sep 17 00:00:00 2001 From: Kevin Deldycke Date: Mon, 13 Apr 2015 19:00:43 +0200 Subject: [PATCH] Always use the common name of a country if available instead of its official default value. --- CHANGES.rst | 2 ++ postal_address/address.py | 9 ++++++++- postal_address/tests/test_address.py | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index cf50a70..77cf100 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,8 @@ ChangeLog * Include internal fields disguised as properties when ``repr``-ing the ``Address`` object. +* Always use the common name of a country if available instead of its official + default value. 0.6.1 (2015-04-07) diff --git a/postal_address/address.py b/postal_address/address.py index c3616f4..4e1276a 100644 --- a/postal_address/address.py +++ b/postal_address/address.py @@ -446,8 +446,15 @@ def country(self): @property def country_name(self): - """ Return country's name. """ + """ Return country's name. + + Common name always takes precedence over the default name, as the + latter isoften pompous, and sometimes false (i.e. not in sync with + current political situation). + """ if self.country: + if hasattr(self.country, 'common_name'): + return self.country.common_name return self.country.name return None diff --git a/postal_address/tests/test_address.py b/postal_address/tests/test_address.py index eb152cc..fa04d4f 100644 --- a/postal_address/tests/test_address.py +++ b/postal_address/tests/test_address.py @@ -473,6 +473,7 @@ def test_country_alias_normalization(self): # subdivision_code='TW-TTT') for address in [address1, address2]: # address3]: self.assertEqual(address.country_code, 'TW') + self.assertEqual(address.country_name, 'Taiwan') self.assertEqual(address.subdivision_code, 'TW-TTT') def test_subdivision_derived_fields(self): @@ -651,6 +652,7 @@ def test_non_strict_mode_normalization(self): self.assertEqual(address.postal_code, '10694') self.assertEqual(address.city_name, 'Tainan City') self.assertEqual(address.country_code, 'TW') + self.assertEqual(address.country_name, 'Taiwan') self.assertEqual(address.subdivision_code, 'TW-TNN') def test_rendering(self):