"""
Goal: Implement the default-config and test-config clases

@authors:
    Andrei Sura             <sura.andrei@gmail.com>
    Ruchi Vivek Desai       <ruchivdesai@gmail.com>
    Sanath Pasumarthy       <sanath@ufl.edu>
"""

import os
from datetime import timedelta
import logging

_basedir = os.path.abspath(os.path.dirname(__file__))


class DefaultConfig(object):

    """ Default configuration data """
    LOG_LEVEL = logging.DEBUG
    # CONFIDENTIAL_SETTINGS_FILE = '/srv/apps/dropper-alz/app/deploy/settings.conf'

    # same folder as the config.py
    CONFIDENTIAL_SETTINGS_FILE = os.path.abspath('deploy/settings.conf')

    # Use local or shib sso auth
    LOGIN_USING_SHIB_AUTH = True

    # REDCap project configs
    REDCAP_API_URL = ''
    REDCAP_API_TOKEN = ''
    REDCAP_DEMOGRAPHICS_FIELDS = ''

    # SSL Certificate config
    SERVER_SSL_KEY_FILE = '/etc/apache2/ssl/dropper.ctsi.ufl.edu.key'
    SERVER_SSL_CRT_FILE = '/etc/apache2/ssl/dropper.ctsi.ufl.edu.crt'

    # @see http://flask.pocoo.org/docs/0.10/config/
    # (!) Try changing this value to the real server name
    # if you keep getting back "GET / HTTP/1.1" 404 -
    SERVER_NAME = 'localhost:5000'

    # the browser will not send a cookie with the secure flag set over an
    # unencrypted HTTP request
    SESSION_COOKIE_SECURE = True

    # https://www.owasp.org/index.php/Session_Management_Cheat_Sheet
    # flask.pocoo.org/docs/0.10/api/#flask.Flask.permanent_session_lifetime
    PERMANENT_SESSION_LIFETIME = timedelta(minutes=30)

    DEBUG = False
    TESTING = False
    DEBUG_TB_ENABLED = False

    # Set to True in order to view every redirect in the debug toolbar
    DEBUG_TB_INTERCEPT_REDIRECTS = False

    # email config
    MAIL_SENDER_SUPPORT = os.getenv(
        'REDIDROPPER_MAIL_SENDER_SUPPORT',
        'admin@dropper.ctsi.ufl.edu')
    MAIL_SERVER = os.getenv(
        'REDIDROPPER_MAIL_SERVER',
        'smtp.gmail.com')
    MAIL_PORT = os.getenv('REDIDROPPER_MAIL_PORT', 465)
    # MAIL_PORT = os.getenv('REDIDROPPER_MAIL_PORT', 587)
    MAIL_USE_TLS = True
    MAIL_USE_SSL = False
    MAIL_USERNAME = os.environ.get('REDIDROPPER_MAIL_USERNAME')
    MAIL_PASSWORD = os.environ.get('REDIDROPPER_MAIL_PASSWORD')

    print MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD
    # Database configuration is stored outside version control
    # in the `application.cfg` file
    DB_HOST = ''
    DB_NAME = ''

    from base64 import b64encode
    from os import urandom
    random_key = b64encode(urandom(50))
    SECRET_KEY = os.getenv('SECRET_KEY', random_key)
    # Limit the max upload size for the app to 20 MB
    # @see https://pythonhosted.org/Flask-Uploads/
    DEFAULT_MAX_CONTENT_LENGTH = 20 * 1024 * 1024
    MAX_CONTENT_LENGTH = os.getenv(
        'REDIDROPPER_MAX_CONTENT_LENGTH',
        DEFAULT_MAX_CONTENT_LENGTH)

    # THREADS_PER_PAGE = 8
    CSRF_ENABLED = True
    CSRF_SESSION_KEY = ""

    # override as needed in CONFIDENTIAL_SETTINGS_FILE
    # os.path.expanduser('~/.redidropper/temp'))
    REDIDROPPER_UPLOAD_TEMP_DIR = os.getenv('REDIDROPPER_UPLOAD_TEMP_DIR',
                                            os.path.abspath('upload/temp'))

    REDIDROPPER_UPLOAD_SAVED_DIR = os.getenv('REDIDROPPER_UPLOAD_SAVED_DIR',
                                             os.path.abspath('upload//saved'))


class DebugConfig(DefaultConfig):

    """ Extra flag for debugging """
    DEBUG = True
    DEBUG_TB_ENABLED = True
    DEBUG_TB_INTERCEPT_REDIRECTS = False


class TestConfig(DefaultConfig):

    """ Configuration for running tests """
    TESTING = True
    CSRF_ENABLED = False

    if os.getenv('CONTINUOUS_INTEGRATION', '') > '':
        # resolve a path when runing with TravisCI
        CONFIDENTIAL_SETTINGS_FILE = \
            '~/build/ctsit/redi-dropper-client/app/deploy/settings.conf'

@@ -281,16 +281,15 @@
 ng%0A%0A
-_basedir
+BASEDIR
  = o
@@ -434,92 +434,8 @@
 EBUG
-%0A    # CONFIDENTIAL_SETTINGS_FILE = '/srv/apps/dropper-alz/app/deploy/settings.conf'
 %0A%0A  
@@ -508,24 +508,30 @@
 os.path.
-abspath(
+join(BASEDIR, 
 'deploy/
@@ -1474,24 +1474,25 @@
 ING = False%0A
+%0A
     DEBUG_TB
@@ -1673,33 +1673,24 @@
 = os.getenv(
-%0A        
 'REDIDROPPER
@@ -1724,35 +1724,54 @@
     
-'admin@dropper.ctsi.ufl.edu
+                            'admin@example.com
 ')%0A 
@@ -1793,33 +1793,24 @@
 = os.getenv(
-%0A        
 'REDIDROPPER
@@ -1820,24 +1820,44 @@
 IL_SERVER',%0A
+                    
         'smt
@@ -1930,66 +1930,8 @@
 65)%0A
-    # MAIL_PORT = os.getenv('REDIDROPPER_MAIL_PORT', 587)%0A
     
@@ -2860,57 +2860,8 @@
 ILE%0A
-    # os.path.expanduser('~/.redidropper/temp'))%0A
     
@@ -2979,32 +2979,95 @@
     os.path.
-abspath(
+join(BASEDIR,%0A                                                         
 'upload/temp
@@ -3205,24 +3205,88 @@
 ath.
-abspath(
+join(BASEDIR,%0A                                                          
 'upload/
 /sav
@@ -3281,17 +3281,16 @@
 'upload/
-/
 saved'))

Use relative paths in config.py