PageRenderTime 122ms CodeModel.GetById 61ms app.highlight 6ms RepoModel.GetById 54ms app.codeStats 0ms

/tests/regressiontests/sites_framework/tests.py

https://code.google.com/p/mango-py/
Python | 34 lines | 27 code | 7 blank | 0 comment | 0 complexity | 54da205fd26e49acb0bf2ad515da19e8 MD5 | raw file
 1from django.conf import settings
 2from django.contrib.sites.models import Site
 3from django.test import TestCase
 4
 5from models import SyndicatedArticle, ExclusiveArticle, CustomArticle, InvalidArticle, ConfusedArticle
 6
 7class SitesFrameworkTestCase(TestCase):
 8    def setUp(self):
 9        Site.objects.get_or_create(id=settings.SITE_ID, domain="example.com", name="example.com")
10        Site.objects.create(id=settings.SITE_ID+1, domain="example2.com", name="example2.com")
11        
12    def test_site_fk(self):
13        article = ExclusiveArticle.objects.create(title="Breaking News!", site_id=settings.SITE_ID)
14        self.assertEqual(ExclusiveArticle.on_site.all().get(), article)
15    
16    def test_sites_m2m(self):
17        article = SyndicatedArticle.objects.create(title="Fresh News!")
18        article.sites.add(Site.objects.get(id=settings.SITE_ID))
19        article.sites.add(Site.objects.get(id=settings.SITE_ID+1))
20        article2 = SyndicatedArticle.objects.create(title="More News!")
21        article2.sites.add(Site.objects.get(id=settings.SITE_ID+1))
22        self.assertEqual(SyndicatedArticle.on_site.all().get(), article)
23        
24    def test_custom_named_field(self):
25        article = CustomArticle.objects.create(title="Tantalizing News!", places_this_article_should_appear_id=settings.SITE_ID)
26        self.assertEqual(CustomArticle.on_site.all().get(), article)
27    
28    def test_invalid_name(self):
29        article = InvalidArticle.objects.create(title="Bad News!", site_id=settings.SITE_ID)
30        self.assertRaises(ValueError, InvalidArticle.on_site.all)
31        
32    def test_invalid_field_type(self):
33        article = ConfusedArticle.objects.create(title="More Bad News!", site=settings.SITE_ID)
34        self.assertRaises(TypeError, ConfusedArticle.on_site.all)