def test_introspect(self): config = apps.get_app_config('tests') mod = introspect.create_anonymizers_module(config) expected = """ from anonymizer.tests.models import Other, EverythingModel from anonymizer import Anonymizer class OtherAnonymizer(Anonymizer): model = Other attributes = [ ('id', "SKIP"), ] class EverythingModelAnonymizer(Anonymizer): model = EverythingModel attributes = [ ('id', "SKIP"), ('name', "name"), ('email', "email"), ('username', "username"), ('address', "full_address"), ('o1_id', "SKIP"), ('lorem', "lorem"), ('similar_lorem', "lorem"), ('unique_lorem', "lorem"), ('some_varchar', "varchar"), ('birthday', "datetime"), ('age', "positive_small_integer"), ('icon', UNKNOWN_FIELD), ('some_datetime', "datetime"), ('some_date', "date"), ('sex', "choice"), ('price', "decimal"), ('binary', UNKNOWN_FIELD), ('uuid', UNKNOWN_FIELD), ('boolean', "bool"), ('small_integer', "small_integer"), ('positive_small_integer', "positive_small_integer"), ('postcode', "varchar"), ('country', "varchar"), ('first_name', "first_name"), ('similar_email', "email"), ('similar_email_other', "email"), ('phonenumber', "phonenumber"), ('last_name', "last_name"), ('street_address', "full_address"), ('state', "state"), ('zip_code', "zip_code"), ('company', "varchar"), ('similar_datetime', "datetime"), ('similar_date', "date"), ] """ self.assertEqual(mod.strip(), expected.strip())
def handle_app_config(self, app_config, **options): anonymizers_module_parent = ".".join( app_config.models_module.__name__.split(".")[:-1]) mod = importlib.import_module(anonymizers_module_parent) parent, discard = os.path.split(mod.__file__) # lop off __init__.pyc path = os.path.join(parent, 'anonymizers.py') # and add anonymizers. if os.path.exists(path): raise CommandError("File '%s' already exists." % path) module = introspect.create_anonymizers_module(app_config) with open(path, "w") as fd: fd.write(module)
def handle_app(self, app, **options): anonymizers_module_parent = ".".join(app.__name__.split(".")[:-1]) mod = importlib.import_module(anonymizers_module_parent) parent, discard = os.path.split(mod.__file__) # lop off __init__.pyc path = os.path.join(parent, 'anonymizers.py') # and add anonymizers. if os.path.exists(path): raise CommandError("File '%s' already exists." % path) module = introspect.create_anonymizers_module(app) with open(path, "w") as fd: fd.write(module)
def test_eveything(self): mod = introspect.create_anonymizers_module(test_models) expected = """ from anonymizer.tests.models import Other, EverythingModel from anonymizer import Anonymizer class OtherAnonymizer(Anonymizer): model = Other attributes = [ ('id', "SKIP"), ] class EverythingModelAnonymizer(Anonymizer): model = EverythingModel attributes = [ ('id', "SKIP"), ('username', "username"), ('name', "name"), ('email', "email"), ('address_city', "city"), ('address_post_code', "postcode"), ('address', "full_address"), ('o1_id', "SKIP"), ('something', "lorem"), ('something_else', "lorem"), ('some_varchar', "varchar"), ('birthday', "datetime"), ('age', "positive_small_integer"), ('icon', UNKNOWN_FIELD), ('some_datetime', "datetime"), ('some_date', "date"), ('sex', "choice"), ('price', "decimal"), ] """ self.assertEqual(mod.strip(), expected.strip())
def test_eveything(self): mod = introspect.create_anonymizers_module(test_models) expected = """ from anonymizer.tests.models import Other, EverythingModel from anonymizer import Anonymizer class OtherAnonymizer(Anonymizer): model = Other attributes = [ ('id', "SKIP"), ] class EverythingModelAnonymizer(Anonymizer): model = EverythingModel attributes = [ ('id', "SKIP"), ('username', "username"), ('name', "name"), ('email', "email"), ('address_city', "city"), ('address_post_code', "uk_postcode"), ('address', "full_address"), ('o1_id', "SKIP"), ('something', "lorem"), ('something_else', "lorem"), ('some_varchar', "varchar"), ('birthday', "datetime"), ('age', "positive_small_integer"), ('icon', UNKNOWN_FIELD), ('some_datetime', "datetime"), ('some_date', "date"), ('sex', "choice"), ('price', "decimal"), ] """ self.assertEqual(mod.strip(), expected.strip())