# Path: app/utils.py
# FORMAT_US_DATE = "%x"
# FORMAT_US_DATE_TIME = '%x %X'
# FORMAT_US_DATE_TIME_ZONE = '%x %X %Z%z'
# FORMAT_DATABASE_DATE_TIME = "%Y-%m-%d %H:%M:%S"
# ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'tiff',
#                           'zip', 'tar', 'tgz', 'bz2'])
# FLASH_CATEGORY_ERROR = 'error'
# FLASH_CATEGORY_INFO = 'info'
# def _get_remote_addr():
# def _get_user_agent():
# def _create_salt():
# def _generate_sha512_hmac(pepper, salt, data):
# def generate_auth(pepper, password):
# def is_valid_auth(pepper, salt, candidate_password, correct_hash):
# def clean_str(dangerous):
# def clean_int(dangerous):
# def get_safe_int(unsafe, default=1, min_allowed=1, max_allowed=None):
# def flash_error(msg):
# def flash_info(msg):
# def pack(data):
# def pack_error(msg):
# def jsonify_error(data):
# def jsonify_success(data):
# def get_db_friendly_date_time():
# def localize_datetime(value, zone_name='US/Eastern'):
# def localize_est_date(value):
# def localize_est_datetime(value):
# def get_expiration_date(offset_days):
# def compute_text_md5(text):
# def get_email_token(email, salt, secret):
# def get_email_from_token(token, salt, secret, max_age=86400):
# def redcap_api_call(url, token, content, fields, max_time):
# def retrieve_redcap_subjects(url, token, fields, max_time=30):
# def retrieve_redcap_events(url, token, max_time=30):


import os
import time
from app import utils
from .base_test import BaseTestCase
'''
Goal: test functions in utils.py
'''



class UtilsTests(BaseTestCase):

    def test_create_salt(self):
        '''
        Verify the remote address reading
        https://realpython.com/blog/python/python-web-applications-with-flask-part-iii/
        '''
        # add testing request context
        # http://flask.pocoo.org/docs/0.10/api/#flask.ctx.RequestContext
        wsgi_env = {
            'REMOTE_ADDR': os.environ.get('REMOTE_ADDR', '1.2.3.4'),
            'HTTP_USER_AGENT': os.environ.get('HTTP_USER_AGENT', 'cURL')}

        # from werkzeug.datastructures import Headers
        # headers = Headers([('Referer', '/example/url')])
        # with app.test_request_context(environ_base=wsgi_env, headers=headers)

        with self.app.test_request_context(environ_base=wsgi_env):

# Path: app/utils.py
# FORMAT_US_DATE = "%x"
# FORMAT_US_DATE_TIME = '%x %X'
# FORMAT_US_DATE_TIME_ZONE = '%x %X %Z%z'
# FORMAT_DATABASE_DATE_TIME = "%Y-%m-%d %H:%M:%S"
# ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'tiff',
#                           'zip', 'tar', 'tgz', 'bz2'])
# FLASH_CATEGORY_ERROR = 'error'
# FLASH_CATEGORY_INFO = 'info'
# def _get_remote_addr():
# def _get_user_agent():
# def _create_salt():
# def _generate_sha512_hmac(pepper, salt, data):
# def generate_auth(pepper, password):
# def is_valid_auth(pepper, salt, candidate_password, correct_hash):
# def clean_str(dangerous):
# def clean_int(dangerous):
# def get_safe_int(unsafe, default=1, min_allowed=1, max_allowed=None):
# def flash_error(msg):
# def flash_info(msg):
# def pack(data):
# def pack_error(msg):
# def jsonify_error(data):
# def jsonify_success(data):
# def get_db_friendly_date_time():
# def localize_datetime(value, zone_name='US/Eastern'):
# def localize_est_date(value):
# def localize_est_datetime(value):
# def get_expiration_date(offset_days):
# def compute_text_md5(text):
# def get_email_token(email, salt, secret):
# def get_email_from_token(token, salt, secret, max_age=86400):
# def redcap_api_call(url, token, content, fields, max_time):
# def retrieve_redcap_subjects(url, token, fields, max_time=30):
# def retrieve_redcap_events(url, token, max_time=30):


# Path: tests/test_utils.py
import os
import time
from app import utils
from .base_test import BaseTestCase

'''
Goal: test functions in utils.py
'''



class UtilsTests(BaseTestCase):

    def test_create_salt(self):
        '''
        Verify the remote address reading
        https://realpython.com/blog/python/python-web-applications-with-flask-part-iii/
        '''
        # add testing request context
        # http://flask.pocoo.org/docs/0.10/api/#flask.ctx.RequestContext
        wsgi_env = {
            'REMOTE_ADDR': os.environ.get('REMOTE_ADDR', '1.2.3.4'),
            'HTTP_USER_AGENT': os.environ.get('HTTP_USER_AGENT', 'cURL')}

        # from werkzeug.datastructures import Headers
        # headers = Headers([('Referer', '/example/url')])
        # with app.test_request_context(environ_base=wsgi_env, headers=headers)

        with self.app.test_request_context(environ_base=wsgi_env):

            actual_ip = utils._get_remote_addr()