def test(self): s = Shurl.objects.get(pk=1) self.assertEqual(s.short_suffix, "1") self.assertEqual(s.access_count, 0) another_s = Shurl.objects.get(pk=66) self.assertEqual(another_s.short_suffix, "12") yet_another_s = Shurl.objects.get(pk=63) self.assertEqual(yet_another_s.short_url(), "cak.es/_") # test duplication handling code t = Shurl.get_or_create("http://www.test.com/stuff/") self.assertEqual(t.pk, 1)
def home(request): '''View with a form for submitting a URL to be shortened and saving the shortened URL upon POSTing''' if request.method == 'GET': form = ShurlForm() return render_to_response('index.html', {'form':form,}, context_instance=RequestContext(request)) else: # handle post from form form = ShurlForm(request.POST) form.is_valid() # get_or_create does dup detection for us shurl = Shurl.get_or_create(form.cleaned_data['url']) return render_to_response('thanks.html', {'shurl':shurl,}, context_instance=RequestContext(request)) return render('index.html')