Skip to content

Commit

Permalink
fix #380: defrag urls in BidStatusView
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Oct 30, 2016
1 parent e2f8a48 commit fe7cdaf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
34 changes: 34 additions & 0 deletions auctions/tests/view_tests.py
Expand Up @@ -49,6 +49,20 @@ def test_post_new_offer(self, mock_messages):
retreive_bid = Bid.objects.get(pk=self.bid1.id)
self.assertEqual(retreive_bid.offer, 44)

def test_url_path_only(self):
self.assertEqual(
'https://github.com/codesy/codesy/issues/380',
self.view._url_path_only(
'https://github.com/codesy/codesy/issues/380#issue-163534117'
)
)
self.assertEqual(
'https://github.com/codesy/codesy/issues/380',
self.view._url_path_only(
'https://github.com/codesy/codesy/issues/380'
)
)

@fudge.patch('auctions.views.messages')
def test_post_new_ask_with_0_offer(self, mock_messages):
mock_messages.is_a_stub()
Expand All @@ -64,6 +78,26 @@ def test_post_new_ask_with_0_offer(self, mock_messages):
self.assertEqual(retreive_bid.offer, 0)
self.assertEqual(retreive_bid.ask, 5)

@fudge.patch('auctions.views.messages')
def test_GET_POST_with_url_fragment(self, mock_messages):
mock_messages.is_a_stub()
url = 'https://github.com/codesy/codesy/issues/380#issue-163534117'
self.view.request = (fudge.Fake().has_attr(
POST={
'url': url,
'ask': 5,
'offer': 0,
})
.has_attr(user=self.user1))
self.view.post()

self.view.request = (fudge.Fake()
.has_attr(GET={'url': url})
.has_attr(user=self.user1))
context = self.view.get_context_data()
self.assertEqual('https://github.com/codesy/codesy/issues/380',
context['bid'].url)


class ClaimStatusTestCase(TestCase):
def setUp(self):
Expand Down
9 changes: 7 additions & 2 deletions auctions/views.py
@@ -1,3 +1,5 @@
from urlparse import urldefrag

from django.shortcuts import redirect, get_object_or_404
from django.core.urlresolvers import reverse
from django.contrib import messages
Expand Down Expand Up @@ -31,8 +33,11 @@ def _get_bid(self, url):
except:
return None

def _url_path_only(self, url):
return urldefrag(url)[0]

def get_context_data(self, **kwargs):
url = self.request.GET['url']
url = self._url_path_only(self.request.GET['url'])
bid = self._get_bid(url)
if bid is None:
return dict({'bid': bid, 'url': url})
Expand Down Expand Up @@ -60,7 +65,7 @@ def post(self, *args, **kwargs):
"""
Save changes to bid and get payment for offer
"""
url = self.request.POST['url']
url = self._url_path_only(self.request.POST['url'])
new_ask_amount = self.request.POST['ask']
new_offer_amount = self.request.POST['offer']

Expand Down

0 comments on commit fe7cdaf

Please sign in to comment.