aboutsummaryrefslogtreecommitdiffstats
path: root/brevisurl/tests
diff options
context:
space:
mode:
authorVladimír Gorej2013-12-07 02:31:08 -0800
committerVladimír Gorej2013-12-07 02:31:08 -0800
commite17323d333569dc44e007d54c477298c1ae4b0d0 (patch)
treec87b316b1e64037f5cc516b3edde46ada427c320 /brevisurl/tests
parentf18e5efd8b4e93633d270f27ea6987b3c21e8b74 (diff)
parentb4ec44220be0deaa09b8b8e015d41b738eaf128b (diff)
downloaddjango-brevisurl-e17323d333569dc44e007d54c477298c1ae4b0d0.tar.bz2
Merge pull request #19 from motiteux/feature/settings-url-length
Feature/settings url length
Diffstat (limited to 'brevisurl/tests')
-rw-r--r--brevisurl/tests/test_models.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/brevisurl/tests/test_models.py b/brevisurl/tests/test_models.py
index 9a843f1..f2c5113 100644
--- a/brevisurl/tests/test_models.py
+++ b/brevisurl/tests/test_models.py
@@ -1,3 +1,6 @@
+import random
+import string
+
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.contrib.sites.models import Site
@@ -6,6 +9,10 @@ import brevisurl.settings
from brevisurl.models import ShortUrl
from brevisurl import get_connection
+def _random_string(k):
+ """Generate a string of length k ascii letters randomly"""
+ return ''.join(random.choice(string.ascii_letters) for x in xrange(k))
+
class TestModels(TestCase):
@@ -25,12 +32,26 @@ class TestModels(TestCase):
self.site = Site.objects.get_current()
self.connection = get_connection('brevisurl.backends.local.BrevisUrlBackend')
self.short_url = ShortUrl()
- self.short_url.original_url = 'www.codescale.'
+ self.short_url.original_url = 'www.codescale{0}.'
self.short_url.shortened_url = '{0}://{1}/12345'.format(brevisurl.settings.LOCAL_BACKEND_DOMAIN_PROTOCOL,
self.site.domain)
self.short_url.backend = self.connection.class_path
self.short_url.save()
+ def test_model_save_too_long_original_url(self):
+ with self.assertRaises(ValidationError):
+ self.site = Site.objects.get_current()
+ self.connection = get_connection('brevisurl.backends.local.BrevisUrlBackend')
+ self.short_url = ShortUrl()
+ # len(self.short_url.original_url) == brevisurl.settings.LOCAL_BACKEND_ORIGINAL_URL_MAX_LENGTH + 8
+ self.short_url.original_url = 'www.{0}.com'.format(
+ _random_string(brevisurl.settings.LOCAL_BACKEND_ORIGINAL_URL_MAX_LENGTH))
+ self.short_url.shortened_url = '{0}://{1}/12345'.format(brevisurl.settings.LOCAL_BACKEND_DOMAIN_PROTOCOL,
+ self.site.domain)
+ self.short_url.backend = self.connection.class_path
+ self.short_url.save()
+
+
def test_model_save_invalid_shortened_url(self):
with self.assertRaises(ValidationError):
connection = get_connection('brevisurl.backends.local.BrevisUrlBackend')
@@ -38,4 +59,4 @@ class TestModels(TestCase):
short_url.original_url = 'http://www.codescale.net/'
short_url.shortened_url = 'www.codescale.'
short_url.backend = connection.class_path
- short_url.save() \ No newline at end of file
+ short_url.save()