diff options
| author | Vladimir Gorej | 2012-05-27 20:14:17 +0200 |
|---|---|---|
| committer | Vladimir Gorej | 2012-05-27 20:14:17 +0200 |
| commit | 4bd7b72aa0ca3a09ab99e1a3b41753df81de6af9 (patch) | |
| tree | 6328ed9894666eefc1f0d6b6c7b28a87b1fb4d31 /brevisurl/tests/test_models.py | |
| download | django-brevisurl-4bd7b72aa0ca3a09ab99e1a3b41753df81de6af9.tar.bz2 | |
Initial commit
Diffstat (limited to 'brevisurl/tests/test_models.py')
| -rw-r--r-- | brevisurl/tests/test_models.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/brevisurl/tests/test_models.py b/brevisurl/tests/test_models.py new file mode 100644 index 0000000..6942124 --- /dev/null +++ b/brevisurl/tests/test_models.py @@ -0,0 +1,38 @@ +from django.core.exceptions import ValidationError +from django.test import TestCase +from django.contrib.sites.models import Site + +from brevisurl.models import ShortUrl +from brevisurl import get_connection + + +class TestModels(TestCase): + + def test_model_save(self): + site = Site.objects.get_current() + connection = get_connection('brevisurl.backends.local.BrevisUrlBackend') + short_url = ShortUrl() + short_url.original_url = 'http://www.codescale.net/' + short_url.shortened_url = '{0}://{1}/12345'.format(connection.PROTOCOL, site.domain) + short_url.backend = connection.class_path + short_url.save() + self.assertIsNotNone(short_url.pk) + + def test_model_save_invalid_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() + self.short_url.original_url = 'www.codescale.' + self.short_url.shortened_url = '{0}://{1}/12345'.format(self.connection.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') + short_url = ShortUrl() + 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 |
