From e98b24dd9567d7e1274c52e7ef2db7a45439ddb5 Mon Sep 17 00:00:00 2001 From: faucomte97 Date: Mon, 18 Sep 2023 16:51:55 +0100 Subject: [PATCH] fix: Move postcode helper to common --- {portal => cfl_common/common}/helpers/organisation.py | 0 .../common/migrations/0041_populate_gb_counties.py | 2 +- cfl_common/common/models.py | 4 ++-- cfl_common/common/tests/test_models.py | 10 ++++++++++ portal/tests/test_helper_methods.py | 10 ---------- 5 files changed, 13 insertions(+), 13 deletions(-) rename {portal => cfl_common/common}/helpers/organisation.py (100%) diff --git a/portal/helpers/organisation.py b/cfl_common/common/helpers/organisation.py similarity index 100% rename from portal/helpers/organisation.py rename to cfl_common/common/helpers/organisation.py diff --git a/cfl_common/common/migrations/0041_populate_gb_counties.py b/cfl_common/common/migrations/0041_populate_gb_counties.py index 2484c0851..e45f148b3 100644 --- a/cfl_common/common/migrations/0041_populate_gb_counties.py +++ b/cfl_common/common/migrations/0041_populate_gb_counties.py @@ -1,7 +1,7 @@ import pgeocode from django.db import migrations -from portal.helpers.organisation import sanitise_uk_postcode +from ..helpers.organisation import sanitise_uk_postcode class Migration(migrations.Migration): diff --git a/cfl_common/common/models.py b/cfl_common/common/models.py index cacff07af..8813b1fe2 100644 --- a/cfl_common/common/models.py +++ b/cfl_common/common/models.py @@ -1,14 +1,14 @@ -import pgeocode import re from datetime import timedelta from uuid import uuid4 +import pgeocode from django.contrib.auth.models import User from django.db import models from django.utils import timezone from django_countries.fields import CountryField -from portal.helpers.organisation import sanitise_uk_postcode +from .helpers.organisation import sanitise_uk_postcode class UserProfile(models.Model): diff --git a/cfl_common/common/tests/test_models.py b/cfl_common/common/tests/test_models.py index f5168d5b4..348e3117e 100644 --- a/cfl_common/common/tests/test_models.py +++ b/cfl_common/common/tests/test_models.py @@ -6,6 +6,7 @@ from .utils.organisation import create_organisation_directly, join_teacher_to_organisation from .utils.student import create_independent_student_directly from .utils.teacher import signup_teacher_directly +from ..models import sanitise_uk_postcode class TestModels(TestCase): @@ -90,6 +91,15 @@ def test_school_postcode(self): assert school.county == "" + def test_sanitise_uk_postcode(self): + postcode_with_space = "AL10 9NE" + postcode_without_space = "AL109UL" + invalid_postcode = "123" + + assert sanitise_uk_postcode(postcode_with_space) == "AL10 9NE" # Check it stays the same + assert sanitise_uk_postcode(postcode_without_space) == "AL10 9UL" # Check a space is added + assert sanitise_uk_postcode(invalid_postcode) == "123" # Check nothing happens + def test_daily_activity_serializer(self): daily_activity = DailyActivity() diff --git a/portal/tests/test_helper_methods.py b/portal/tests/test_helper_methods.py index bff476c4f..23482b72c 100644 --- a/portal/tests/test_helper_methods.py +++ b/portal/tests/test_helper_methods.py @@ -2,7 +2,6 @@ from unittest.mock import patch, Mock from portal.helpers.password import is_password_pwned -from portal.helpers.organisation import sanitise_uk_postcode class TestClass: @@ -29,12 +28,3 @@ def test_is_password_pwned__status_code_not_200(self, mock_get): # Assert mock_get.assert_called_once_with(f"https://api.pwnedpasswords.com/range/{sha1_hash[:5]}") assert not result - - def test_sanitise_uk_postcode(self): - postcode_with_space = "AL10 9NE" - postcode_without_space = "AL109UL" - invalid_postcode = "123" - - assert sanitise_uk_postcode(postcode_with_space) == "AL10 9NE" # Check it stays the same - assert sanitise_uk_postcode(postcode_without_space) == "AL10 9UL" # Check a space is added - assert sanitise_uk_postcode(invalid_postcode) == "123" # Check nothing happens