Luke Plant avatar Luke Plant committed 0ec66f1

Added test suite and basic introspection tests

Comments (0)

Files changed (10)

 include AUTHORS
 include docs/Makefile
 include docs/conf.py
+include manage.py
+include test_settings.py
 recursive-include docs *.rst
   And even then, your operating system may not delete the data from the
   disk. Properly getting rid of these traces is left as an excercise to the
   reader :-)
+
+
+Tests
+=====
+
+To run the test suite, do::
+
+    ./manage.py test --settings=test_settings

Empty file added.

anonymizer/tests/__init__.py

+import os
+import sys
+
+from django.conf import settings
+from django.utils import unittest
+from django.test import TestCase
+
+from anonymizer import introspect
+import anonymizer.tests.testapp.models
+
+class TestIntrospect(unittest.TestCase):
+
+    def setUp(self):
+        self._old_INSTALLED_APPS = settings.INSTALLED_APPS
+        settings.INSTALLED_APPS = settings.INSTALLED_APPS[:] + ["anonymizer.tests.testapp"]
+        from django.db.models.loading import cache
+        cache._populate()
+
+    def tearDown(self):
+        settings.INSTALLED_APPS = self._old_INSTALLED_APPS
+
+    def test_eveything(self):
+        mod = introspect.create_anonymizers_module(anonymizer.tests.testapp.models)
+        expected = """
+from anonymizer.tests.testapp.models import Other, EverythingModel
+from anonymizer import Anonymizer
+
+class OtherAnonymizer(Anonymizer):
+
+    model = Other
+
+    attributes = [
+         # Skipping field id
+    ]
+
+
+class EverythingModelAnonymizer(Anonymizer):
+
+    model = EverythingModel
+
+    attributes = [
+         # Skipping field id
+        ('username', "username"),
+        ('name', "name"),
+        ('email', "email"),
+        ('address_city', "city"),
+        ('address_post_code', "uk_postcode"),
+        ('address', "full_address"),
+         # Skipping field o1_id
+        ('something', "lorem"),
+        ('birthday', "datetime"),
+        ('age', "positive_small_integer"),
+        ('icon', UNKNOWN_FIELD),
+    ]
+"""
+        self.assertEqual(mod.strip(), expected.strip())
+
Add a comment to this file

anonymizer/tests/testapp/__init__.py

Empty file added.

anonymizer/tests/testapp/models.py

+from django.db import models
+
+
+class Other(models.Model):
+    pass
+
+
+class EverythingModel(models.Model):
+    name = models.CharField(max_length=30)
+    email = models.EmailField()
+    username = models.CharField(max_length=20, unique=True)
+    address_city = models.CharField(max_length=50)
+    address_post_code = models.CharField(max_length=10)
+    address = models.TextField()
+    o1 = models.ForeignKey(Other)
+    something = models.TextField()
+    birthday = models.DateTimeField()
+    age = models.PositiveSmallIntegerField()
+    icon = models.ImageField(upload_to='.')
 # The short X.Y version.
 version = '0.2'
 # The full version, including alpha/beta/rc tags.
-release = '0.2'
+release = '0.2.1'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
+#!/usr/bin/env python
+from django.core import management
+if __name__ == "__main__":
+    management.execute_from_command_line()
 
 setup(
     name = "django-anonymizer",
-    version = '0.2',
+    version = '0.2.1',
     packages = find_packages(),
     include_package_data = True,
 
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3'
+    },
+}
+
+INSTALLED_APPS = [
+    'anonymizer'
+]
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.