Ejemplo n.º 1
0
 def test_str_representation(self):
     ShortUrl.objects.all().delete()
     url = ShortUrl()
     url.default_url = 'http://google.com'
     url.save()
     u = ShortUrl.objects.get(default_url='http://google.com')
     self.assertEqual(str(u), 'Short Url:3e9 Default Url:http://google.com')
Ejemplo n.º 2
0
 def test_invalid_url_returns_error(self):
     with self.assertRaises(Exception) as context:
         ShortUrl.objects.all().delete()
         u = ShortUrl()
         u.default_url = 'http://googl'
         u.save()
         self.assertTrue('This is broken' in context.exception)
     self.assertEqual(ShortUrl.objects.all().count(), 0)
Ejemplo n.º 3
0
def make(request):
    if request.method == "POST":
        form = UrlForm(request.POST)
        if form.is_valid():
            url = form.cleaned_data['url']
            u = ShortUrl(url=url)
            u.save()
            return render_to_response('finished.html', {
                    'surl': u,
            })
    else:
        form = UrlForm()
    return render_to_response('make.html', {
            'form': form,
    })
Ejemplo n.º 4
0
def list(request):
    urls = ShortUrl.objects.all()
    form = UrlForm()
    context = {
        'urls': urls,
    }
    if request.method == "POST":
        form = UrlForm(request.POST)
        if form.is_valid():
            url = form.cleaned_data['url']
            u = ShortUrl(url=url)
            u.save()
            context['obj':u]
            form = UrlForm()
    context['form'] = form
    return render_to_response('list.html', context)
Ejemplo n.º 5
0
class TestUrlShorten(TestCase):

    def setUp(self):
        self.url_1 = ShortUrl(url='/test-page/')
        self.url_2 = ShortUrl(url='/test-page/?query_string=True')
        self.url_3 = ShortUrl(url='/another-test-page/')
        self.url_4 = ShortUrl(url='http://www.a-full-url.com')

    @freeze_time('2000-01-01')
    @override_settings(EPOCH_KEY=946684800)
    def test_incrementing_base_62(self):
        self.url_1.save()
        self.assertEquals(self.url_1.short_code, '1')
        self.url_2.save()
        self.assertEquals(self.url_2.short_code, '2')
        self.url_3.save()
        self.assertEquals(self.url_3.short_code, '3')
        self.url_4.save()
        self.assertEquals(self.url_4.short_code, '4')
Ejemplo n.º 6
0
 def setUp(self):
     url = ShortUrl()
     url.default_url = 'http://bbc.com'
     url.mobile_url = 'http://m.bbc.com'
     url.tablet_url = 'http://t.bbc.com'
     url.save()
     url = ShortUrl()
     url.default_url = 'http://google.com'
     url.save()
Ejemplo n.º 7
0
 def setUp(self):
     self.url_1 = ShortUrl(url='/test-page/')
     self.url_2 = ShortUrl(url='/test-page/?query_string=True')
     self.url_3 = ShortUrl(url='/another-test-page/')
     self.url_4 = ShortUrl(url='http://www.a-full-url.com')