Ejemplo n.º 1
0
    def test_api_generation(self):
        """
        Makes sure api keys are generated on registration
        """
        resp = self.register_user("apiuser", "this_/is_OUR_secret")
        assert resp.status_code == 302

        user = Account.objects(username="******").first()
        assert len(user.apikey) == 32 and len(user.secret) == 40
Ejemplo n.º 2
0
def get_account(value, field='username'):
    """
    Retrieve an Account object.

    :Parameters:
        - `value`: Value to filter by.
        - `field`: Field to filter on. Default field is username.
    """
    return Account.objects(**{field: value}).first()
Ejemplo n.º 3
0
    def create_user(self, username, password, roles=[]):
        """
        Shortcut for creating users.
        """
        if username not in self._created_users:
            self._created_users.append(username)

        self.account = Account.objects(username=username).first()

        if self.account:
            return

        account = Account()
        account.username = username
        account.password = generate_password_hash(
            password,
            application.app.config['BCRYPT_LOG_ROUNDS']
        )
        account.active = True
        account.roles = roles
        account.save()

        self.account = account
Ejemplo n.º 4
0
 def __call__(self, form, field):
     if Account.objects(username=field.data).first():
         raise ValidationError('Username is not available.')
Ejemplo n.º 5
0
def delete_user(username):
    for account in Account.objects(username=username):
        account.delete()