Ejemplo n.º 1
0
    def setUp(self):
        super(BaseTestCase, self).setUp()

        self.password = random_string()
        self.user = self.create_user(self.password)

        self.login()
Ejemplo n.º 2
0
 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')
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
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
    )
Ejemplo n.º 8
0
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)
Ejemplo n.º 10
0
 def generate_password(self):
     self.password = utils.random_string(16)
Ejemplo n.º 11
0
 def generate_password(self):
   self.password = utils.random_string(16)
Ejemplo n.º 12
0
 def random_string(self, length=6, chars=None):
     return random_string(length=length, chars=chars)
Ejemplo n.º 13
0
 def random_email(self):
     return "{}@{}.{}".format(
         random_string(length=6),
         random_string(length=6),
         random_string(length=2)
     )
Ejemplo n.º 14
0
 def set_required_url(self, data, field, length=6):
     if field not in data:
         data[field] = 'http://{}.com'.format(
             random_string(length=length))
Ejemplo n.º 15
0
 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,
         )