Skip to content

Commit 08ce747

Browse files
AlwinEggerMarcoSteinacher
authored andcommitted
auto cleanup sources
1 parent bb9deb9 commit 08ce747

6 files changed

Lines changed: 31 additions & 20 deletions

File tree

django/cohiva/tests/test_utils_countries.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def test_get_country_choices_prioritizes_and_localizes(self):
4545
patch("cohiva.utils.countries.pycountry.countries", fake_countries),
4646
patch("cohiva.utils.countries._current_language", return_value="de"),
4747
patch("cohiva.utils.countries.locale.strxfrm", side_effect=lambda value: value),
48-
patch("cohiva.utils.countries.gettext.translation", return_value=translation) as translation_mock,
48+
patch(
49+
"cohiva.utils.countries.gettext.translation", return_value=translation
50+
) as translation_mock,
4951
):
5052
choices = countries.get_country_choices()
5153

@@ -96,8 +98,13 @@ def test_country_name_from_code_returns_localized_name(self):
9698
translation = DummyTranslation({"Germany": "Deutschland"})
9799
with (
98100
patch("cohiva.utils.countries._current_language", return_value="de"),
99-
patch("cohiva.utils.countries.gettext.translation", return_value=translation) as translation_mock,
100-
patch("cohiva.utils.countries.pycountry.countries.get", return_value=SimpleNamespace(name="Germany")),
101+
patch(
102+
"cohiva.utils.countries.gettext.translation", return_value=translation
103+
) as translation_mock,
104+
patch(
105+
"cohiva.utils.countries.pycountry.countries.get",
106+
return_value=SimpleNamespace(name="Germany"),
107+
),
101108
):
102109
self.assertEqual(countries.country_name_from_code("de"), "Deutschland")
103110
translation_mock.assert_called_once()
@@ -124,7 +131,10 @@ def fake_search_fuzzy(value):
124131

125132
with (
126133
patch("cohiva.utils.countries.pycountry.countries.get", side_effect=fake_get),
127-
patch("cohiva.utils.countries.pycountry.countries.search_fuzzy", side_effect=fake_search_fuzzy),
134+
patch(
135+
"cohiva.utils.countries.pycountry.countries.search_fuzzy",
136+
side_effect=fake_search_fuzzy,
137+
),
128138
):
129139
self.assertEqual(countries.normalize_country_code(""), "")
130140
self.assertEqual(countries.normalize_country_code(" "), "")

django/cohiva/utils/countries.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
This centralizes ISO alpha-2 codes and helps translate between
44
legacy free-text values and normalized codes.
55
"""
6-
from functools import lru_cache
76

8-
import pycountry
97
import gettext
108
import locale
9+
from functools import lru_cache
10+
11+
import pycountry
1112

1213
DEFAULT_COUNTRY_CODE = "CH"
1314
PRIORITY_CODES = ["CH", "DE", "AT", "FR", "IT"]
@@ -118,5 +119,3 @@ def normalize_country_code(value: str) -> str:
118119
except LookupError:
119120
return ""
120121
return match.alpha_2
121-
122-

django/geno/billing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from svglib.svglib import svg2rlg
2727

2828
import geno.settings as geno_settings
29+
from cohiva.utils.countries import normalize_country_code
2930
from cohiva.utils.pdf import PdfGenerator
3031
from cohiva.utils.strings import pluralize
3132
from cohiva.views.admin import CohivaAdminViewMixin, ResponseVariant
@@ -38,7 +39,6 @@
3839
Split,
3940
Transaction,
4041
)
41-
from cohiva.utils.countries import normalize_country_code
4242

4343
from .models import (
4444
Address,

django/geno/migrations/0021_address_country_iso_codes.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
get_default_country_code,
66
normalize_country_code,
77
)
8-
98
from geno.utils import send_info_mail
109

1110
COUNTRY_CHOICES = get_country_choices()
@@ -16,21 +15,27 @@ def migrate_country_to_iso(apps, schema_editor):
1615
for address in Address.objects.all():
1716
code = normalize_country_code(address.country)
1817
if code is None:
19-
send_info_mail(f"Problem migrating Address.country to code", f"Could not normalize country code '{address.country}' for Address {address.pk} (setting to empty)")
18+
send_info_mail(
19+
"Problem migrating Address.country to code",
20+
f"Could not normalize country code '{address.country}' for Address {address.pk} (setting to empty)",
21+
)
2022
code = ""
2123
address.country = code
2224
address.save(update_fields=["country"])
2325
Building = apps.get_model("geno", "Building")
2426
for building in Building.objects.all():
2527
code = normalize_country_code(building.country)
2628
if code is None:
27-
send_info_mail(f"Problem migrating Building.country to code", f"Could not normalize country code '{building.country}' for Building {building.pk} (setting to empty)")
29+
send_info_mail(
30+
"Problem migrating Building.country to code",
31+
f"Could not normalize country code '{building.country}' for Building {building.pk} (setting to empty)",
32+
)
2833
code = ""
2934
building.country = code
3035
building.save(update_fields=["country"])
3136

32-
class Migration(migrations.Migration):
3337

38+
class Migration(migrations.Migration):
3439
dependencies = [
3540
("geno", "0020_alter_registrationevent_enable_telephone"),
3641
]
@@ -60,4 +65,3 @@ class Migration(migrations.Migration):
6065
),
6166
),
6267
]
63-

django/geno/models.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
from filer.fields.file import FilerFileField
2323

2424
import geno.settings as geno_settings
25+
from cohiva.utils.countries import (
26+
get_country_choices,
27+
get_default_country_code,
28+
)
2529
from cohiva.utils.settings import (
2630
get_default_email,
2731
get_default_formal_choice,
@@ -34,11 +38,6 @@
3438
nformat,
3539
sanitize_filename,
3640
) # , send_info_mail, send_error_mail
37-
from cohiva.utils.countries import (
38-
country_name_from_code,
39-
get_country_choices,
40-
get_default_country_code,
41-
)
4241

4342
logger = logging.getLogger("access_portal")
4443

django/geno/tests/test_billing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
add_invoice_obj,
1414
build_structured_qrbill_address,
1515
create_qrbill,
16-
get_reference_nr,
1716
transform_qrbill_country,
1817
)
1918
from geno.models import (

0 commit comments

Comments
 (0)