def __get_vercode(account_id, testmin):
    '''
        @description:
            - returns the verification code
    '''

    testmin = '639%s' % str(testmin[-9:])

    correct_code = Verification.get_mobile_code(account_id=account_id,
                                                testmin=testmin)
    return correct_code
def __save_code(account_id, code=None, testmin=None, ver_id=None):
    '''
        saves the code generated
        in the Verification table
    '''
    if testmin:
        testmin = '639%s' % str(testmin[-9:])

    gen_logger = sms_api_logger.GeneralLogger()

    try:
        ver_obj = Verification.get_mobile_code(account_id=account_id,
                                               testmin=testmin)

        if ver_obj or ver_id:
            if not ver_id:
                ver_id = ver_obj['id']

            if code:
                Verification.update_mobile_code(account_id=account_id,
                                                code=code,
                                                mobile=testmin,
                                                ver_id=ver_id)
            else:
                Verification.update_mobile_code(account_id=account_id,
                                                mobile=testmin,
                                                ver_id=ver_id)

            gen_logger.info('testmin enrollment -- updating pincode',
                            {'account_id': account_id})

            return ver_obj['id'] if not ver_id else ver_id
        else:

            gen_logger.info('testmin enrollment -- saving pincode', {
                'account_id': account_id,
                'pincode': code
            })

            return Verification.save_mobile_code(account_id=account_id,
                                                 code=code,
                                                 mobile=testmin)

    except DuplicateVerificationCodeException, e:
        gen_logger.info('testmin enrollment -- pincode not unique', {
            'account_id': account_id,
            'error': str(e)
        })
        save_code(account_id, code, testmin)