Skip to content

Commit

Permalink
Merge branch 'master' into daily_activity_deleted_users
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Sep 19, 2023
2 parents e3905e2 + cab82b1 commit a2f6a6a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion cfl_common/common/migrations/0041_populate_gb_counties.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion cfl_common/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions cfl_common/common/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion portal/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "6.36.0"
__version__ = "6.36.2"
11 changes: 10 additions & 1 deletion portal/helpers/ratelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions portal/tests/test_helper_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

0 comments on commit a2f6a6a

Please sign in to comment.