From c2a30c131e26f9f717c076e5e95bfb9d4d5be1ea Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Fri, 24 Nov 2023 16:05:33 +0500 Subject: [PATCH 1/5] chore: fixing test. --- common/djangoapps/course_modes/tests/test_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/djangoapps/course_modes/tests/test_views.py b/common/djangoapps/course_modes/tests/test_views.py index 522540944726..d7b069865317 100644 --- a/common/djangoapps/course_modes/tests/test_views.py +++ b/common/djangoapps/course_modes/tests/test_views.py @@ -504,7 +504,7 @@ def test_course_closed(self): url = reverse('course_modes_choose', args=[str(self.course.id)]) response = self.client.get(url) # URL-encoded version of 1/1/15, 12:00 AM - redirect_url = reverse('dashboard') + '?course_closed=1%2F1%2F15%2C+12%3A00+AM' + redirect_url = reverse('dashboard') + '?course_closed=1%2F1%2F15%2C+12%3A00%E2%80%AFAM' self.assertRedirects(response, redirect_url) @ddt.data( From fe53d456a59dcaa80abd0cb0f3b60d345abbab5c Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Mon, 27 Nov 2023 18:10:21 +0500 Subject: [PATCH 2/5] chore: fixing tests. --- openedx/core/djangoapps/geoinfo/middleware.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/openedx/core/djangoapps/geoinfo/middleware.py b/openedx/core/djangoapps/geoinfo/middleware.py index 9b9df817e224..ff9ed271bbd1 100644 --- a/openedx/core/djangoapps/geoinfo/middleware.py +++ b/openedx/core/djangoapps/geoinfo/middleware.py @@ -12,8 +12,7 @@ import logging from django.utils.deprecation import MiddlewareMixin -from ipware.ip import get_client_ip -from ipware.utils import is_public_ip +from python_ipware import IpWare from .api import country_code_from_ip @@ -30,13 +29,18 @@ def process_request(self, request): Store country code in session. """ - new_ip_address = get_client_ip(request)[0] + ipw = IpWare() + new_ip_address_obj, _ = ipw.get_client_ip(meta=request.META) + + if new_ip_address_obj: + new_ip_address = format(new_ip_address_obj) + old_ip_address = request.session.get('ip_address', None) if not new_ip_address and old_ip_address: del request.session['ip_address'] del request.session['country_code'] - elif new_ip_address != old_ip_address and is_public_ip(new_ip_address): + elif new_ip_address != old_ip_address and new_ip_address_obj.is_global: country_code = country_code_from_ip(new_ip_address) request.session['country_code'] = country_code request.session['ip_address'] = new_ip_address From 594970c83ea5569a8aaef699b4bcb0051924cec9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 27 Nov 2023 18:16:08 +0500 Subject: [PATCH 3/5] feat: Upgrade Python dependency django-ipware (#33805) Commit generated by workflow `openedx/edx-platform/.github/workflows/upgrade-one-python-dependency.yml@refs/heads/master` Co-authored-by: awais786 --- requirements/edx/base.txt | 4 +++- requirements/edx/development.txt | 7 ++++++- requirements/edx/doc.txt | 6 +++++- requirements/edx/testing.txt | 6 +++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index c439cdae0422..baa25f55f7df 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -290,7 +290,7 @@ django-filter==23.3 # edx-enterprise # lti-consumer-xblock # openedx-blockstore -django-ipware==5.0.1 +django-ipware==6.0.0 # via # -r requirements/edx/kernel.in # edx-enterprise @@ -930,6 +930,8 @@ python-dateutil==2.8.2 # olxcleaner # ora2 # xblock +python-ipware==2.0.0 + # via django-ipware python-memcached==1.59 # via -r requirements/edx/paver.txt python-slugify==8.0.1 diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 121855ae45cf..1e7968ea1066 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -481,7 +481,7 @@ django-filter==23.3 # edx-enterprise # lti-consumer-xblock # openedx-blockstore -django-ipware==5.0.1 +django-ipware==6.0.0 # via # -r requirements/edx/doc.txt # -r requirements/edx/testing.txt @@ -1651,6 +1651,11 @@ python-dateutil==2.8.2 # olxcleaner # ora2 # xblock +python-ipware==2.0.0 + # via + # -r requirements/edx/doc.txt + # -r requirements/edx/testing.txt + # django-ipware python-memcached==1.59 # via # -r requirements/edx/doc.txt diff --git a/requirements/edx/doc.txt b/requirements/edx/doc.txt index 1e37ede6d68e..3741cd431127 100644 --- a/requirements/edx/doc.txt +++ b/requirements/edx/doc.txt @@ -349,7 +349,7 @@ django-filter==23.3 # edx-enterprise # lti-consumer-xblock # openedx-blockstore -django-ipware==5.0.1 +django-ipware==6.0.0 # via # -r requirements/edx/base.txt # edx-enterprise @@ -1110,6 +1110,10 @@ python-dateutil==2.8.2 # olxcleaner # ora2 # xblock +python-ipware==2.0.0 + # via + # -r requirements/edx/base.txt + # django-ipware python-memcached==1.59 # via -r requirements/edx/base.txt python-slugify==8.0.1 diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index 2ab577f31d91..af7d8c2e796c 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -382,7 +382,7 @@ django-filter==23.3 # edx-enterprise # lti-consumer-xblock # openedx-blockstore -django-ipware==5.0.1 +django-ipware==6.0.0 # via # -r requirements/edx/base.txt # edx-enterprise @@ -1243,6 +1243,10 @@ python-dateutil==2.8.2 # olxcleaner # ora2 # xblock +python-ipware==2.0.0 + # via + # -r requirements/edx/base.txt + # django-ipware python-memcached==1.59 # via -r requirements/edx/base.txt python-slugify==8.0.1 From 53c44da1cedfc4bd4c8b6f3717b973cbbcbd40ad Mon Sep 17 00:00:00 2001 From: magajh Date: Wed, 6 Dec 2023 14:21:08 -0500 Subject: [PATCH 4/5] chore: compile requirements --- requirements/common_constraints.txt | 4 ---- requirements/edx/development.txt | 1 - requirements/edx/testing.txt | 1 - 3 files changed, 6 deletions(-) diff --git a/requirements/common_constraints.txt b/requirements/common_constraints.txt index a0d4097134f6..7313473a1675 100644 --- a/requirements/common_constraints.txt +++ b/requirements/common_constraints.txt @@ -24,7 +24,3 @@ elasticsearch<7.14.0 # django-simple-history>3.0.0 adds indexing and causes a lot of migrations to be affected - -# tox>4.0.0 isn't yet compatible with many tox plugins, causing CI failures in almost all repos. -# Details can be found in this discussion: https://github.com/tox-dev/tox/discussions/1810 -tox<4.0.0 diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 1e7968ea1066..04588b85fb37 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -2058,7 +2058,6 @@ tomlkit==0.12.1 # snowflake-connector-python tox==3.28.0 # via - # -c requirements/edx/../common_constraints.txt # -r requirements/edx/testing.txt # tox-battery tox-battery==0.6.2 diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index af7d8c2e796c..187cac37139b 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -1518,7 +1518,6 @@ tomlkit==0.12.1 # snowflake-connector-python tox==3.28.0 # via - # -c requirements/edx/../common_constraints.txt # -r requirements/edx/testing.in # tox-battery tox-battery==0.6.2 From 120dc3cb5e7166d606547f27179bd5e986b47866 Mon Sep 17 00:00:00 2001 From: magajh Date: Wed, 6 Dec 2023 14:41:18 -0500 Subject: [PATCH 5/5] fix: course_modes View test --- common/djangoapps/course_modes/tests/test_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/djangoapps/course_modes/tests/test_views.py b/common/djangoapps/course_modes/tests/test_views.py index d7b069865317..522540944726 100644 --- a/common/djangoapps/course_modes/tests/test_views.py +++ b/common/djangoapps/course_modes/tests/test_views.py @@ -504,7 +504,7 @@ def test_course_closed(self): url = reverse('course_modes_choose', args=[str(self.course.id)]) response = self.client.get(url) # URL-encoded version of 1/1/15, 12:00 AM - redirect_url = reverse('dashboard') + '?course_closed=1%2F1%2F15%2C+12%3A00%E2%80%AFAM' + redirect_url = reverse('dashboard') + '?course_closed=1%2F1%2F15%2C+12%3A00+AM' self.assertRedirects(response, redirect_url) @ddt.data(