def setUp(self): super(BaseTestCase, self).setUp() self.password = random_string() self.user = self.create_user(self.password) self.login()
def token_setup(self, return_url=None): token = utils.random_string(20) session.put('token',token) cookie.set('token',token, secure_p=True) if return_url: raise cherrypy.HTTPRedirect(return_url) else: return template.render('locksession/token_setup')
def set_required_rut(self, data, field, length=6): if field not in data: rut = '{}.{}.{}-{}'.format( self.random_int(minimum=1, maximum=99), self.random_int(minimum=100, maximum=990), self.random_int(minimum=100, maximum=990), random_string(length=1, chars='k' + string.digits), ) data[field] = rut
def create_user(self, password=None, **kwargs): if kwargs.get('first_name') is None: kwargs['first_name'] = random_string(length=6) if kwargs.get('last_name') is None: kwargs['last_name'] = random_string(length=6) if kwargs.get('email') is None: kwargs['email'] = "*****@*****.**" % random_string(length=6) if kwargs.get('is_active') is None: kwargs['is_active'] = True user = User.objects.create(**kwargs) if password is not None: user.set_password(password) user.save() return user
def file_path(self, name): """ Generic method to give to a FileField or ImageField in it's upload_to parameter. This returns the name of the class, concatenated with the id of the object and the name of the file. """ base_path = "{}/{}/{}/{}" return base_path.format(self.__class__.__name__, str(utils.today()), utils.random_string(30), name)
def generate_value(self, field, commit=True): if field.name == 'rut': return '{}.{}.{}-{}'.format( random.randint(1, 99), random.randint(100, 990), random.randint(100, 990), random_string(length=1, chars='k' + string.digits), ) elif isinstance(field, PhoneNumberField): return '+569' + str(random.randint(1, 9)) * 8 elif isinstance(field, FilerImageField): return Image.objects.create() return super(CustomMommy, self).generate_value(field, commit)
def file_path(self, name): """ Generic method to give to a FileField or ImageField in it's upload_to parameter. This returns the name of the class, concatenated with the id of the object and the name of the file. """ base_path = u"{}/{}/{}" return base_path.format( self.__class__.__name__, utils.random_string(30), name )
def file_path(self, name): """ Generic method to give to a FileField or ImageField in it's upload_to parameter. This returns the name of the class, concatenated with the id of the object and the name of the file. """ base_path = u"{}/{}/{}" # name would have problematics chars, to fix that we slugify filename filename, ext = os.path.splitext(name) name = '{}{}'.format( slugify(filename), ext, ) return base_path.format( self.__class__.__name__, utils.random_string(30), name )
def random_string(self, length=6, chars=None): return random_string(length=length, chars=chars)
def generate_password(self): self.password = utils.random_string(16)
def random_email(self): return "{}@{}.{}".format( random_string(length=6), random_string(length=6), random_string(length=2) )
def set_required_url(self, data, field, length=6): if field not in data: data[field] = 'http://{}.com'.format( random_string(length=length))
def set_required_string(self, data, field, length=6, include_spaces=True): if field not in data: data[field] = random_string( length=length, include_spaces=include_spaces, )