Commits

Carl Meyer committed 0f7aae8

improve test coverage

Comments (0)

Files changed (2)

model_utils/tests/models.py

     title = models.CharField(max_length=50)
     body = SplitField()
 
-    def __unicode__(self):
-        return self.title
-
 class NoRendered(models.Model):
     """
     Test that the no_excerpt_field keyword arg works. This arg should

model_utils/tests/tests.py

 
 from django.test import TestCase
 from django.conf import settings
+from django.db import models
+from django.db.models.fields import FieldDoesNotExist
+from django.core.exceptions import ImproperlyConfigured
+
 from django.contrib.contenttypes.models import ContentType
-from django.db.models.fields import FieldDoesNotExist
 
 from model_utils import ChoiceEnum, Choices
-from model_utils.fields import get_excerpt
-from model_utils.managers import QueryManager
+from model_utils.fields import get_excerpt, MonitorField
+from model_utils.managers import QueryManager, manager_from
+from model_utils.models import StatusModel, TimeFramedModel
 from model_utils.tests.models import (InheritParent, InheritChild, TimeStamp,
     Post, Article, Status, StatusPlainTuple, TimeFrame, Monitored,
     StatusManagerAdded, TimeFrameManagerAdded, Entry)
             self.post.body.excerpt = 'this should fail'
         self.assertRaises(AttributeError, _invalid_assignment)
 
+    def test_access_via_class(self):
+        def _invalid_access():
+            Article.body
+        self.assertRaises(AttributeError, _invalid_access)
+
+    def test_none(self):
+        a = Article(title='Some Title', body=None)
+        self.assertEquals(a.body, None)
+
+    def test_assign_splittext(self):
+        a = Article(title='Some Title')
+        a.body = self.post.body
+        self.assertEquals(a.body.excerpt, u'summary\n')
+
+    def test_value_to_string(self):
+        f = self.post._meta.get_field('body')
+        self.assertEquals(f.value_to_string(self.post), self.full_text)
+
 
 class MonitorFieldTests(TestCase):
     def setUp(self):
         self.instance.save()
         self.assertEquals(self.instance.name_changed, changed)
 
+    def test_no_monitor_arg(self):
+        self.assertRaises(TypeError, MonitorField)
+
         
 class ChoicesTests(TestCase):
     def setUp(self):
                           "('DRAFT', 'DRAFT', 'DRAFT'), "
                           "('PUBLISHED', 'PUBLISHED', 'PUBLISHED'))")
 
+    def test_wrong_length_tuple(self):
+        self.assertRaises(ValueError, Choices, ('a',))
+
         
 class LabelChoicesTests(ChoicesTests):
     def setUp(self):
     def test_manager_available(self):
         self.assert_(isinstance(TimeFrameManagerAdded.timeframed, QueryManager))
 
+    def test_conflict_error(self):
+        def _run():
+            class ErrorModel(TimeFramedModel):
+                timeframed = models.BooleanField()
+        self.assertRaises(ImproperlyConfigured, _run)
+        
+                
 class StatusModelTests(TestCase):
     def setUp(self):
         self.model = Status
     def test_manager_available(self):
         self.assert_(isinstance(StatusManagerAdded.active, QueryManager))
 
+    def test_conflict_error(self):
+        def _run():
+            class ErrorModel(StatusModel):
+                STATUS = (
+                    ('active', 'active'),
+                    ('deleted', 'deleted'),
+                    )
+                active = models.BooleanField()
+        self.assertRaises(ImproperlyConfigured, _run)
+                
+
 class QueryManagerTests(TestCase):
     def setUp(self):
         data = ((True, True, 0),
 
     def test_function(self):
         self.assertEqual(Entry.objects.unpublished().count(), 1)
+
+    def test_typecheck(self):
+        self.assertRaises(TypeError, manager_from, 'somestring')
+