From fa177590906de6fdef3c51d4c4acf27af9b19c4d Mon Sep 17 00:00:00 2001 From: Vladg90 Date: Tue, 15 Apr 2014 13:58:02 +0300 Subject: Add URL shortening time duration tests --- brevisurl/tests/backends/test_local.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'brevisurl/tests/backends/test_local.py') diff --git a/brevisurl/tests/backends/test_local.py b/brevisurl/tests/backends/test_local.py index 4577376..8ddc7ed 100644 --- a/brevisurl/tests/backends/test_local.py +++ b/brevisurl/tests/backends/test_local.py @@ -1,5 +1,6 @@ +from django.db import transaction from django.core.exceptions import ValidationError -from django.test import TestCase +from django.test import TestCase, TransactionTestCase from django.core.validators import URLValidator import brevisurl.settings @@ -7,6 +8,9 @@ from brevisurl import get_connection from brevisurl.models import ShortUrl from brevisurl.backends.local import TokensExhaustedError +import random + + class TestLocalBrevisUrlBackend(TestCase): @@ -128,4 +132,21 @@ class TestLocalBrevisUrlBackend(TestCase): original_url = 'http://www.codescale.net/' connection = get_connection('brevisurl.backends.local.BrevisUrlBackend', domain='http://test.com/d/') short_url = connection.shorten_url(original_url) - self.assertRegexpMatches(short_url.shortened_url, r'^http://test\.com/d/[^/]{5}$') \ No newline at end of file + self.assertRegexpMatches(short_url.shortened_url, r'^http://test\.com/d/[^/]{5}$') + +class TestDuration(TransactionTestCase): + + def setUp(self): + self.connection = get_connection('brevisurl.backends.local.BrevisUrlBackend') + + def test_shorten_urls_duration(self): + for i in range(0, 10000): + url = 'http://www.codescale.net/%s' % random.getrandbits(30) + self.connection.shorten_url(url) + + @transaction.commit_on_success + def test_shorten_urls_duration_commit_on_success(self): + for i in range(0, 10000): + url = 'http://www.codescale.net/%s' % random.getrandbits(30) + self.connection.shorten_url(url) + -- cgit v1.2.3