Ejemplo n.º 1
0
def test_register_anonym_only():
    class UserAnonym(register_models.AnonymBase):
        email = fields.string('test_email_{seq}@preply.com',
                              seq_callback=datetime.datetime.now)
        username = fields.string('test_username_{seq}@preply.com',
                                 seq_callback=datetime.datetime.now)
        first_name = fields.string('first name {seq}')
        last_name = fields.string('last name {seq}')
        password = fields.password('password')
        is_staff = fields.function(lambda: False)

        class Meta:
            exclude_fields = [
                'is_active', 'is_superuser', 'last_login', 'date_joined'
            ]

    class GroupAnonym(register_models.AnonymBase):
        name = fields.string("group_name_{seq}")

        class Meta:
            pass

    register_models.register_anonym([
        (User, UserAnonym),
        (Group, GroupAnonym),
    ])

    Anonymizer(only='django.contrib.auth.models.Group')

    with pytest.raises(LookupError):
        Anonymizer(only='django.contrib.auth.models.WrongGroup')
Ejemplo n.º 2
0
def test_register_skip_only():
    register_models.register_skip([User, Permission, Group])

    Anonymizer(only='django.contrib.auth.models.Group')

    with pytest.raises(LookupError):
        Anonymizer(only='django.contrib.auth.models.WrongGroup')
Ejemplo n.º 3
0
def test_register_clean_only():
    register_models.register_clean([
        (User, register_models.AnonymBase),
        (Permission, register_models.AnonymBase(truncate=True)),
        (Group, register_models.AnonymBase())
    ])
    Anonymizer(only='django.contrib.auth.models.Group')

    with pytest.raises(LookupError):
        Anonymizer(only='django.contrib.auth.models.WrongGroup')
Ejemplo n.º 4
0
 def handle(self, *args, **options):
     self.action = options['action']
     self.check_only = options['check_only']
     self.only = options['only']
     self.soft_mode = options['soft_mode']
     start = time.time()
     anonymizer = Anonymizer(soft_mode=self.soft_mode, only=self.only)
     self.stdout.write('Check pass successfully')
     self.stdout.write(f'{"=-" * 25}=')
     if self.check_only is True:
         return
     if self.action is None or self.action == 'anonymize':
         if ((self.only is None) or
             (self.only is not None
              and self.only in Anonymizer.anonym_models)) and len(
                  anonymizer.anonym_models) > 0:
             self.stdout.write('Anonymizing started')
             anonymizer.anonymize(only=self.only)
             self.stdout.write('Anonymizing finished')
     if self.action is None or self.action == 'clean':
         if ((self.only is None) or
             (self.only is not None and self.only in Anonymizer.clean_models
              )) and len(anonymizer.clean_models) > 0:
             self.stdout.write('Cleaning started')
             anonymizer.clean(only=self.only)
             self.stdout.write('Cleaning finished')
     end = time.time() - start
     self.stdout.write(f'{"=-" * 25}=')
     self.stdout.write(f'Total time (sec.): {end:.2f}')
Ejemplo n.º 5
0
 def handle(self, *args, **options):
     start = time.time()
     anonymizer = Anonymizer(soft_mode=options['soft_mode'])
     if options['action'] is None or options['action'] == 'anonymize':
         anonymizer.anonymize()
     if options['action'] is None or options['action'] == 'clean':
         anonymizer.clean()
     end = time.time()
     print('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=')
     print('Total time (sec.): {}'.format(end - start))
Ejemplo n.º 6
0
 def handle(self, *args, **options):
     print 'Anonymizer found next DB settings:'
     for db in settings.DATABASES:
         print '{} -- NAME: {}, HOST: {}'.format(
             db, settings.DATABASES[db]['NAME'],
             settings.DATABASES[db]['HOST'] or 'localhsot')
     start = time.time()
     anonymizer = Anonymizer(soft_mode=options['soft_mode'])
     if options['action'] is None or options['action'] == 'anonymize':
         anonymizer.anonymize()
     if options['action'] is None or options['action'] == 'clean':
         anonymizer.clean()
     end = time.time()
     print '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='
     print 'Total time (sec.): {}'.format(end - start)