def test_03_get_option(self): # First declared in config.ini overwritten by config.development.ini self.assertEqual(get_option('APP', 'DEVELOPMENT'), True) self.assertEqual(get_option('APP', 'DEBUG'), True) # Only declared in config.ini self.assertEqual(get_option('APP', 'SQLALCHEMY_TRACK_MODIFICATIONS'), False) # Only declared in config.development.ini self.assertEqual(get_option('X_API', 'KEY'), 'fweffqdqfedefwefewf')
def __flask_setup(): global app, cache app = Flask(__name__, static_folder='react_app/build', template_folder='react_app/build') app.wsgi_app = ProxyFix(app.wsgi_app) app.config['DEVELOPMENT'] = get_option('FLASK', 'DEVELOPMENT') app.config['DEBUG'] = get_option('FLASK', 'DEBUG') CORS(app, resources={r"/search-iframe*": {"origins": "*"}}) cache = RedisCache(REDIS_HOST, REDIS_PORT, REDIS_PASS)
def test_05_get_option(self): # First declared in config.ini overwritten by config.production.ini self.assertEqual(get_option('APP', 'X_RATE'), 1.80) # First declared in config.ini overwritten by config.production.ini and then overwritten by environment vars self.assertEqual(get_option('APP', 'BASE_URL'), 'http://0.0.0.0:5004') # Declared in environment vars self.assertEqual(get_option('APP', 'SQLALCHEMY_DATABASE_URI'), 'postgresql://talhasch:@localhost:5434/db_name') # Declared in config.ini self.assertEqual(get_option('APP', 'SQLALCHEMY_TRACK_MODIFICATIONS'), False) # Declared in environment vars self.assertEqual(get_option('APP', 'SQLALCHEMY_POOL_SIZE'), 100)
import json import os import redis import requests from cachelib import RedisCache from flask import Flask, send_from_directory from flask import request, jsonify, abort from flask_cors import CORS from werkzeug.middleware.proxy_fix import ProxyFix from xonfig import get_option REDIS_HOST = get_option('REDIS', 'HOST') REDIS_PORT = get_option('REDIS', 'PORT') REDIS_PASS = get_option('REDIS', 'PASS') r = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASS, decode_responses=True) API_URL = get_option('ESEARCH_API', 'URL') API_TOKEN = get_option('ESEARCH_API', 'TOKEN') API_REQUEST_TIMEOUT = get_option('ESEARCH_API', 'REQUEST_TIMEOUT') API_CACHE_TIMEOUT = get_option('ESEARCH_API', 'CACHE_TIMEOUT') app = None cache = None def __flask_setup(): global app, cache app = Flask(__name__, static_folder='react_app/build', template_folder='react_app/build')
def test_07_get_option(self): # Should be raise NoOptionError with self.assertRaises(NoOptionError): self.assertEqual(get_option('APP', 'DEBUG1'), True)
def test_05_get_option(self): # Get option tests self.assertEqual(get_option('APP', 'DEBUG'), True) self.assertEqual(get_option('APP', 'SECRET_KEY'), 'VERY-SECRET-K3Y') self.assertEqual(get_option('APP', 'SQLALCHEMY_POOL_SIZE'), 100) self.assertEqual(get_option('APP', 'X_RATE'), 1.23)
import os import requests import redis import time os.sys.path.append( os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))) from xonfig import get_option API_URL = get_option('ESEARCH_API', 'URL') API_TOKEN = get_option('ESEARCH_API', 'TOKEN') REDIS_HOST = get_option('REDIS', 'HOST') REDIS_PORT = get_option('REDIS', 'PORT') REDIS_PASS = get_option('REDIS', 'PASS') r = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASS, decode_responses=True) while True: headers = {'Content-Type': 'application/json', 'Authorization': API_TOKEN} resp = requests.get('{}/{}'.format(API_URL, 'stats'), headers=headers, timeout=10) doc_count = resp.json()['hits'] assert type(doc_count) == int r.set('doc_count', doc_count) time.sleep(1)