diff options
author | Florian Apolloner <florian@apolloner.eu> | 2013-02-26 09:53:47 +0100 |
---|---|---|
committer | Florian Apolloner <florian@apolloner.eu> | 2013-02-26 14:36:57 +0100 |
commit | 89f40e36246100df6a11316c31a76712ebc6c501 (patch) | |
tree | 6e65639683ddaf2027908d1ecb1739e0e2ff853b /tests/sites_framework/tests.py | |
parent | b3d2ccb5bfbaf6e7fe1f98843baaa48c35a70950 (diff) | |
download | django-89f40e36246100df6a11316c31a76712ebc6c501.tar.gz |
Merged regressiontests and modeltests into the test root.
Diffstat (limited to 'tests/sites_framework/tests.py')
-rw-r--r-- | tests/sites_framework/tests.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/sites_framework/tests.py b/tests/sites_framework/tests.py new file mode 100644 index 0000000000..8e664fd501 --- /dev/null +++ b/tests/sites_framework/tests.py @@ -0,0 +1,38 @@ +from __future__ import absolute_import + +from django.conf import settings +from django.contrib.sites.models import Site +from django.test import TestCase + +from .models import (SyndicatedArticle, ExclusiveArticle, CustomArticle, + InvalidArticle, ConfusedArticle) + + +class SitesFrameworkTestCase(TestCase): + def setUp(self): + Site.objects.get_or_create(id=settings.SITE_ID, domain="example.com", name="example.com") + Site.objects.create(id=settings.SITE_ID+1, domain="example2.com", name="example2.com") + + def test_site_fk(self): + article = ExclusiveArticle.objects.create(title="Breaking News!", site_id=settings.SITE_ID) + self.assertEqual(ExclusiveArticle.on_site.all().get(), article) + + def test_sites_m2m(self): + article = SyndicatedArticle.objects.create(title="Fresh News!") + article.sites.add(Site.objects.get(id=settings.SITE_ID)) + article.sites.add(Site.objects.get(id=settings.SITE_ID+1)) + article2 = SyndicatedArticle.objects.create(title="More News!") + article2.sites.add(Site.objects.get(id=settings.SITE_ID+1)) + self.assertEqual(SyndicatedArticle.on_site.all().get(), article) + + def test_custom_named_field(self): + article = CustomArticle.objects.create(title="Tantalizing News!", places_this_article_should_appear_id=settings.SITE_ID) + self.assertEqual(CustomArticle.on_site.all().get(), article) + + def test_invalid_name(self): + article = InvalidArticle.objects.create(title="Bad News!", site_id=settings.SITE_ID) + self.assertRaises(ValueError, InvalidArticle.on_site.all) + + def test_invalid_field_type(self): + article = ConfusedArticle.objects.create(title="More Bad News!", site=settings.SITE_ID) + self.assertRaises(TypeError, ConfusedArticle.on_site.all) |