Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added basic tests for databrowse. Refs #5968.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17406 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7ad7a8d2d32704872430a03885e1b763b2b667ad 1 parent 1cc8007
@aaugustin aaugustin authored
View
1  django/contrib/databrowse/models.py
@@ -0,0 +1 @@
+# Empty models.py to allow for specifying databrowse as a test label.
View
58 django/contrib/databrowse/tests.py
@@ -0,0 +1,58 @@
+from django.contrib import databrowse
+from django.db import models
+from django.test import TestCase
+
+
+class SomeModel(models.Model):
+ some_field = models.CharField(max_length=50)
+
+ def __unicode__(self):
+ return self.some_field
+
+
+class SomeOtherModel(models.Model):
+ some_other_field = models.CharField(max_length=50)
+
+ def __unicode__(self):
+ return self.some_other_field
+
+
+class YetAnotherModel(models.Model):
+ yet_another_field = models.CharField(max_length=50)
+
+ def __unicode__(self):
+ return self.yet_another_field
+
+
+class DatabrowseTests(TestCase):
+
+ def test_databrowse_register_unregister(self):
+ databrowse.site.register(SomeModel)
+ self.assertTrue(SomeModel in databrowse.site.registry)
+ databrowse.site.register(SomeOtherModel, YetAnotherModel)
+ self.assertTrue(SomeOtherModel in databrowse.site.registry)
+ self.assertTrue(YetAnotherModel in databrowse.site.registry)
+
+ self.assertRaisesMessage(
+ databrowse.sites.AlreadyRegistered,
+ 'The model SomeModel is already registered',
+ databrowse.site.register, SomeModel, SomeOtherModel
+ )
+
+ databrowse.site.unregister(SomeOtherModel)
+ self.assertFalse(SomeOtherModel in databrowse.site.registry)
+ databrowse.site.unregister(SomeModel, YetAnotherModel)
+ self.assertFalse(SomeModel in databrowse.site.registry)
+ self.assertFalse(YetAnotherModel in databrowse.site.registry)
+
+ self.assertRaisesMessage(
+ databrowse.sites.NotRegistered,
+ 'The model SomeModel is not registered',
+ databrowse.site.unregister, SomeModel, SomeOtherModel
+ )
+
+ self.assertRaisesMessage(
+ databrowse.sites.AlreadyRegistered,
+ 'The model SomeModel is already registered',
+ databrowse.site.register, SomeModel, SomeModel
+ )
Please sign in to comment.
Something went wrong with that request. Please try again.