Commits

Tim Savage  committed ca5df31

Initial work on adding testing.

  • Participants
  • Parent commits 3350d94

Comments (0)

Files changed (8)

File django_extras/contrib/auth/fixtures/owners.json

+[
+    {
+        "model":"auth.user",
+        "pk":1,
+        "fields":{
+            "username": "standard 1",
+            "first_name":"Standard",
+            "last_name":"User 1"
+        }
+    },
+    {
+        "model":"auth.user",
+        "pk":2,
+        "fields":{
+            "username": "standard 2",
+            "first_name":"Standard",
+            "last_name":"User 2"
+        }
+    },
+    {
+        "model":"auth.user",
+        "pk":3,
+        "fields":{
+            "username": "staff",
+            "first_name":"Staff",
+            "last_name":"User"
+        }
+    },
+    {
+        "model":"auth.user",
+        "pk":4,
+        "fields":{
+            "username": "admin",
+            "first_name":"Admin",
+            "last_name":"User"
+        }
+    }
+]

File django_extras/contrib/auth/tests.py

+from django import test
+from django.db import models
+from django.contrib.auth.models import User
+from django_extras.contrib.auth.models import SingleOwnerMixin, MultipleOwnerMixin
+
+
+class SingleOwner(SingleOwnerMixin, models.Model):
+    name = models.CharField(max_length=50)
+    description = models.TextField()
+
+
+class MultiOwner(MultipleOwnerMixin, models.Model):
+    name = models.CharField(max_length=50)
+    description = models.TextField()
+
+
+class SingleOwnerTestCase(test.TransactionTestCase):
+    fixtures = ['owners.json']
+
+    def setUp(self):
+        self.user1 = User.objects.get(pk=1)
+        self.user2 = User.objects.get(pk=2)
+        self.user_staff = User.objects.get(pk=3)
+        self.user_admin = User.objects.get(pk=4)
+
+        SingleOwner.objects.create(name="Test 1", description="123", owner_id=1)
+        SingleOwner.objects.create(name="Test 2", description="123", owner_id=2)
+        SingleOwner.objects.create(name="Test 3", description="123", owner_id=3) # Staff
+        SingleOwner.objects.create(name="Test 4", description="123", owner_id=4) # Admin
+
+    def testOwnedBy(self):
+        s = SingleOwner.objects.get(1)
+        self.assertTrue(s.owned_by(self.user1))
+
+
+class MultiOwnerTestTestCase(test.TransactionTestCase):
+    fixtures = ['owners.json']
+

File django_extras/tests/__init__.py

+__author__ = 'tsavage'

File django_extras/tests/types.py

+#coding=UTF-8
+from unittest import TestCase
+from django_extras.types import Money
+
+class MoneyTestCase(TestCase):
+
+    LARGE = Money('200000000.0000')
+    SMALL = Money('100.000')
+    NEGATIVE = Money('-200000.0000')
+
+    FORMAT_POSITIVE = Money('123456.789')
+    FORMAT_NEGATIVE = Money('-12345.6789')
+
+    def test_format_default(self):
+        self.assertEqual('123,456.79', self.FORMAT_POSITIVE.format())
+        self.assertEqual('-12,345.68', self.FORMAT_NEGATIVE.format())
+
+    def test_format_places(self):
+        self.assertEqual('123,456.7890', self.FORMAT_POSITIVE.format(places=4))
+        self.assertEqual('-12,345.678900', self.FORMAT_NEGATIVE.format(places=6))
+
+    def test_format_currency_symbol(self):
+        self.assertEqual('$123,456.79', self.FORMAT_POSITIVE.format(currency_symbol='$'))
+        self.assertEqual('-£12,345.68', self.FORMAT_NEGATIVE.format(currency_symbol='£'))
+
+    def test_format_europe(self):
+        self.assertEqual('123.456,79', self.FORMAT_POSITIVE.format(separator='.', decimal_place=','))
+        self.assertEqual('-12.345,68', self.FORMAT_NEGATIVE.format(separator='.', decimal_place=','))
+
+    def test_format_signs(self):
+        self.assertEqual('p123,456.79', self.FORMAT_POSITIVE.format(positive_sign="p"))
+        self.assertEqual('n12,345.68', self.FORMAT_NEGATIVE.format(negative_sign="n"))
+
+    def test_format_trailing_negative(self):
+        self.assertEqual('123,456.79', self.FORMAT_POSITIVE.format(trailing_negative=" neg"))
+        self.assertEqual('-12,345.68 neg', self.FORMAT_NEGATIVE.format(trailing_negative=" neg"))
+
+# Use fabric to automate some stuff
+from fabric.api import *
+
+def run_tests():
+    local('python test_runner.py')

File test_runner.py

+# Helper test runner for running tests against django_extras
+import os
+
+from optparse import OptionParser
+
+from django.conf import settings
+from django.core.management import call_command
+
+def main():
+    parser = OptionParser()
+    parser.add_option('--DATABASE_ENGINE', dest='DATABASE_ENGINE', default='sqlite3')
+    parser.add_option('--DATABASE_NAME',   dest='DATABASE_NAME',   default='test.db')
+    parser.add_option('--DATABASE_USER',   dest='DATABASE_USER',   default='')
+    parser.add_option('--DATABASE_PASSWORD', dest='DATABASE_PASSWORD', default='')
+    parser.add_option('--DATABASE_HOST',   dest='DATABASE_HOST',   default='')
+    parser.add_option('--DATABASE_PORT',   dest='DATABASE_PORT',  default='')
+    parser.add_option('--SITE_ID',         dest='SITE_ID', type='int', default=1)
+
+    options, args = parser.parse_args()
+
+    settings.configure(**{
+        'DATABASES': {
+            'default': {
+                'ENGINE': options.DATABASE_ENGINE,
+                'NAME': options.DATABASE_NAME,
+                'USER': options.DATABASE_USER,
+                'PASSWORD': options.DATABASE_PASSWORD,
+                'HOST': options.DATABASE_HOST,
+                'PORT': options.DATABASE_PORT,
+            },
+        },
+        'SITE_ID': options.SITE_ID,
+        'ROOT_URLCONF': '',
+        'TEMPLATE_LOADERS': (
+            'django.template.loaders.filesystem.load_template_source',
+            'django.template.loaders.app_directories.load_template_source',
+        ),
+        'TEMPLATE_DIRS': (
+            os.path.join(os.path.dirname(__file__), 'templates'),
+        ),
+        'INSTALLED_APPS': (
+            #"django.contrib.auth",
+            "django.contrib.contenttypes",
+            "django.contrib.sessions",
+            "django.contrib.sites",
+
+            "django_extras",
+            "django_extras.contrib.auth",
+        ),
+    })
+    call_command('test', 'django_extras', 'auth')
+
+
+if __name__ == '__main__':
+    main()

File tests/__init__.py

-__author__ = 'tsavage'

File tests/types.py

-#coding=UTF-8
-from unittest import TestCase
-from django_extras.types import Money
-
-class MoneyTestCase(TestCase):
-
-    LARGE = Money('200000000.0000')
-    SMALL = Money('100.000')
-    NEGATIVE = Money('-200000.0000')
-
-    FORMAT_POSITIVE = Money('123456.789')
-    FORMAT_NEGATIVE = Money('-12345.6789')
-
-    def test_format_default(self):
-        self.assertEqual('123,456.79', self.FORMAT_POSITIVE.format())
-        self.assertEqual('-12,345.68', self.FORMAT_NEGATIVE.format())
-
-    def test_format_places(self):
-        self.assertEqual('123,456.7890', self.FORMAT_POSITIVE.format(places=4))
-        self.assertEqual('-12,345.678900', self.FORMAT_NEGATIVE.format(places=6))
-
-    def test_format_currency_symbol(self):
-        self.assertEqual('$123,456.79', self.FORMAT_POSITIVE.format(currency_symbol='$'))
-        self.assertEqual('-£12,345.68', self.FORMAT_NEGATIVE.format(currency_symbol='£'))
-
-    def test_format_europe(self):
-        self.assertEqual('123.456,79', self.FORMAT_POSITIVE.format(separator='.', decimal_place=','))
-        self.assertEqual('-12.345,68', self.FORMAT_NEGATIVE.format(separator='.', decimal_place=','))
-
-    def test_format_signs(self):
-        self.assertEqual('p123,456.79', self.FORMAT_POSITIVE.format(positive_sign="p"))
-        self.assertEqual('n12,345.68', self.FORMAT_NEGATIVE.format(negative_sign="n"))
-
-    def test_format_trailing_negative(self):
-        self.assertEqual('123,456.79', self.FORMAT_POSITIVE.format(trailing_negative=" neg"))
-        self.assertEqual('-12,345.68 neg', self.FORMAT_NEGATIVE.format(trailing_negative=" neg"))
-