def testValidParameters(self):

        '''
        Valid parameters should pass the checks.
        '''

        errors = validation.validateAdminRegistration(
                'username',
                'password',
                'password')

        # Errors should be None.
        self.assertIsNone(errors)
    def testNoPassword(self):

        '''
        Empty or blank password should throw an error.
        '''

        # Blank password.
        errors = validation.validateAdminRegistration(
                'username',
                '',
                'password')

        # Check for error.
        self.assertEqual(errors['password'], [e['noPassword']])

        # None password.
        errors = validation.validateAdminRegistration(
                'username',
                None,
                'password')

        # Check for error.
        self.assertEqual(errors['password'], [e['noPassword']])
    def testNoUserName(self):

        '''
        Empty or blank username should throw an error.
        '''

        # Blank username.
        errors = validation.validateAdminRegistration(
                '',
                'password',
                'password')

        # Check for error.
        self.assertEqual(errors['username'], [e['noUsername']])

        # None username.
        errors = validation.validateAdminRegistration(
                None,
                'password',
                'password')

        # Check for error.
        self.assertEqual(errors['username'], [e['noUsername']])
    def testConfirmMatch(self):

        '''
        If the confirmation does not match the password, throw an error.
        '''

        # Mismatch.
        errors = validation.validateAdminRegistration(
                'username',
                'password',
                'nomatch')

        # Check for error.
        self.assertEqual(errors['confirm'], [e['confirmDoesNotMatch']])
    def testNoConfirm(self):

        '''
        Empty or blank password confirm should throw an error.
        '''

        # Blank confirm.
        errors = validation.validateAdminRegistration(
                'username',
                'password',
                '')

        # Check for error.
        self.assertEqual(errors['confirm'], [e['noConfirm']])

        # None password.
        errors = validation.validateAdminRegistration(
                'username',
                'password',
                None)

        # Check for error.
        self.assertEqual(errors['confirm'], [e['noConfirm']])
    def testUsernameUnavailable(self):

        '''
        Already registered username should throw an error.
        '''

        # Create an administrator.
        takenUsername = User('takenUsername', 'password', True)
        db.session.add(takenUsername)
        db.session.commit()

        # Taken username.
        errors = validation.validateAdminRegistration(
                'takenUsername',
                'password',
                'password')

        # Check for error.
        self.assertEqual(errors['username'], [e['usernameTaken']])
Beispiel #7
0
def register():

    ''' First admin registration. '''

    errors = None

    # If a form was posted.
    if request.method == 'POST':

        # Gather post.
        username = request.form['username']
        password = request.form['password']
        confirm = request.form['confirm']

        # Validate form.
        errors = validation.validateAdminRegistration(
                username,
                password,
                confirm)

        # If valid.
        if not errors:

            # Create the administrator.
            admin = models.User.createAdministrator(
                    username,
                    password)

            # Record the id, redirect.
            session['user_id'] = admin.id
            return redirect(url_for('browse'))

    # If not valid, render form again.
    return render_template(
            'admin/register.html',
            errors = errors,
            form = request.form)