Skip to content

Commit

Permalink
Merge branch 'master' into store_http_referrer
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy authored Jun 7, 2024
2 parents 52bef5f + 41b4ad9 commit 53566bc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ You may need to do this if you use a custom user model and upgrade Django.
### 4.3.0 (2024-06-07)

* ReferralResponse now stores http_referrer

* added tolerance to the ending slash in URL

### 4.2.0 (2023-01-12)

Expand Down
23 changes: 22 additions & 1 deletion pinax/referrals/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.auth import get_user_model
from django.test import TestCase

from pinax.referrals.models import Referral
from pinax.referrals.models import Referral, ReferralResponse


class Tests(TestCase):
Expand Down Expand Up @@ -78,3 +78,24 @@ def test_process_referral_authenticated_next_unsafe(self):
referral_response = referral.responses.first()
self.assertEqual(referral_response.user, referred_user)
self.assertEqual(referral_response.http_referrer, "https://referrer.com")

def test_process_referral_slash_both_variants(self):
referral = Referral.create(redirect_to="https://example.com/")
self.assertFalse(referral.responses.exists())
response = self.client.get(referral.url.rstrip("/"))
self.assertEqual(response.status_code, 302)
self.assertEqual(response["Location"], "https://example.com/")
self.assertEqual(referral.responses.count(), 1)
referral_response = referral.responses.first()
self.assertIsNone(referral_response.user)
self.assertEqual(response.cookies["pinax-referral"].value, f"{referral.code}:{referral_response.session_key}")

ReferralResponse.objects.all().delete()

response = self.client.get(referral.url.rstrip("/") + "/")
self.assertEqual(response.status_code, 302)
self.assertEqual(response["Location"], "https://example.com/")
self.assertEqual(referral.responses.count(), 1)
referral_response = referral.responses.first()
self.assertIsNone(referral_response.user)
self.assertEqual(response.cookies["pinax-referral"].value, f"{referral.code}:{referral_response.session_key}")
4 changes: 2 additions & 2 deletions pinax/referrals/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.urls import path
from django.urls import path, re_path

from .views import create_referral, process_referral

app_name = "pinax_referrals"

urlpatterns = [
path("", create_referral, name="create_referral"),
path("<str:code>", process_referral, name="process_referral")
re_path(r"^(?P<code>[\w-]+)/?$", process_referral, name="process_referral"),
]

0 comments on commit 53566bc

Please sign in to comment.