Skip to content

Commit

Permalink
Tests for template tag get_back_button
Browse files Browse the repository at this point in the history
  • Loading branch information
Skirmantas Jurgaitis committed Apr 23, 2013
1 parent e25f726 commit 3fbda67
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions oscar/templatetags/history_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ def get_back_button(context):

referrer = request.META.get('HTTP_REFERER', None)
if not referrer:
return False
return None

try:
url = urlparse.urlparse(referrer)
except:
return False
return None

if request.get_host() != url.netloc:
try:
Site.objects.get(domain=url.netloc)
except Site.DoesNotExist:
# Came from somewhere else, don't show back button:
return False
return None

try:
match = resolve(url.path)
Expand Down
15 changes: 15 additions & 0 deletions tests/functional/customer/history_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from oscar_testsupport.factories import create_product
from oscar.apps.customer.history_helpers import get_recently_viewed_product_ids
from oscar.templatetags.history_tags import get_back_button
from django.http import HttpRequest


Expand All @@ -24,6 +25,20 @@ def test_id_gets_added_to_cookie(self):
request.COOKIES['oscar_recently_viewed_products'] = response.cookies['oscar_recently_viewed_products'].value
self.assertTrue(self.product.id in get_recently_viewed_product_ids(request))

def test_get_back_button(self):
request = HttpRequest()

request.META['SERVER_NAME'] = 'test'
request.META['SERVER_PORT'] = 8000
request.META['HTTP_REFERER'] = 'http://www.google.com'
backbutton = get_back_button({'request': request})
self.assertEqual(backbutton, None)

request.META['HTTP_REFERER'] = 'http://test:8000/search/'
backbutton = get_back_button({'request': request})
self.assertTrue(backbutton)
self.assertEqual(backbutton['title'], 'Back to search results')


class TestAUserWhoLogsOut(TestCase):
username = 'customer'
Expand Down

0 comments on commit 3fbda67

Please sign in to comment.