Example #1
0
    def setUp(self):
        d = Domain(domain="http://www.test.com")
        d.save()
        s = Shurl(url="http://www.test.com", domain=d)
        s.save()
        s.assign_short_suffix()

        m = MonthLog(domain=d)
        m.save()

        past_time = datetime.date(2012, 3, 14)
        old_m = MonthLog(domain=d, creation_date=past_time, month=first_of_the_month(past_time))
        old_m.save()
Example #2
0
    def setUp(self):
        d = Domain(domain="http://www.test.com")
        d.save()
        s = Shurl(url="http://www.test.com/stuff/", domain=d)
        s.save()
        s.assign_short_suffix()

        # populate database with a lot of shurls
        i = 0
        while i < 66:
            url = "http://www.test.com/" + str(i) + "/"
            a = Shurl(url=url, domain=d)
            a.save()
            a.assign_short_suffix()
            i += 1
Example #3
0
    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)
Example #4
0
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')
Example #5
0
    def setUp(self):
        d = Domain(domain="http://www.test.com")
        d.save()
        s = Shurl(url="http://www.test.com/a/b/c/", domain=d)
        s.save()
        s.assign_short_suffix()

        t = Shurl(url="http://www.test.com/another_dir/", domain=d)
        t.save()
        t.assign_short_suffix()

        s.get_url()
        t.get_url()
        t.get_url()
Example #6
0
 def test_shortening_algorithm(self):
     self.assertEqual("9", Shurl.shortening_algo(9))
     self.assertEqual("a", Shurl.shortening_algo(10))
     self.assertEqual("A", Shurl.shortening_algo(36))
     self.assertEqual("_", Shurl.shortening_algo(63))
     self.assertEqual("10", Shurl.shortening_algo(64))