Exemplo n.º 1
0
    def testValidParameters(self):

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

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

        # Errors should be None.
        self.assertIsNone(errors)
Exemplo n.º 2
0
    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']])
Exemplo n.º 3
0
    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']])
Exemplo n.º 4
0
    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']])
Exemplo n.º 5
0
    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']])
Exemplo n.º 6
0
    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']])
Exemplo n.º 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)