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 704a741ff..cb2c7ee9d 100644 --- a/cfl_common/common/models.py +++ b/cfl_common/common/models.py @@ -8,7 +8,7 @@ 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 949350d2d..488cef54b 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 ..helpers.organisation 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/__init__.py b/portal/__init__.py index b076d5803..09ed46c59 100644 --- a/portal/__init__.py +++ b/portal/__init__.py @@ -1 +1 @@ -__version__ = "6.36.0" +__version__ = "6.36.2" diff --git a/portal/helpers/ratelimit.py b/portal/helpers/ratelimit.py index 1787e73b9..acf108842 100644 --- a/portal/helpers/ratelimit.py +++ b/portal/helpers/ratelimit.py @@ -161,7 +161,16 @@ def get_usage(request, group=None, fn=None, key=None, rate=None, method=ALL, inc cache_name = getattr(settings, "RATELIMIT_USE_CACHE", "default") cache = caches[cache_name] - cache_key = _make_cache_key(group, window, rate, value, method) + + if value == "": + return { + "count": 0, + "limit": 0, + "should_limit": False, + "time_left": -1, + } + else: + cache_key = _make_cache_key(group, window, rate, value, method) count = None added = cache.add(cache_key, initial_value, period + EXPIRATION_FUDGE) 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