Esempio n. 1
0
    def test_use_sentry(self):
        expect(Config.use_sentry()).to(be_false)

        self.config['sentry_dns'] = "https://*****:*****@sentry.io/application_id"
        self.write_config()
        Config.reload()

        expect(Config.use_sentry()).to(be_true)
Esempio n. 2
0
    def test_getattr(self):
        self.config = {
            "theme": "foo",
        }
        self.write_config()
        Config.reload()

        expect(lambda: Config.foo).to(raise_error(AttributeError))
        expect(lambda: Config.theme).not_to(raise_error)
Esempio n. 3
0
    def setUp(self):
        self.config = {}
        self.config_dir = tempfile.TemporaryDirectory()

        os.environ['CONFIG_DIR'] = self.config_dir.name

        self.write_config()

        Config._full_reload()
Esempio n. 4
0
    def test_init_results(self):
        """Make sure _init_results does what is expected"""

        config = Config()
        config.monitors = {"http://test/": {}, "http://test2/": {}}

        result = App._init_results(config)

        assert result["http://test/"] is None
        assert result["http://test2/"] is None
Esempio n. 5
0
def add_repo():
    name = input('Sync item name:')
    git_url = input('Git URL:')
    view_path = input('Mirror view path (default is "/"):') or '/'

    Config.repos[name] = {
        'git_url': git_url,
        'view_path': view_path,
    }

    Config.save()
Esempio n. 6
0
    def test_reload(self):
        self.config = {
            "theme": "foo",
            "debug": True,
        }
        self.write_config()

        Config.reload()

        expect(Config.theme).to(equal("foo"))
        expect(Config.debug).to(be_true)
Esempio n. 7
0
    def test_reload_creates_image_upload_directory(self):
        content_dir = tempfile.TemporaryDirectory()

        self.config = {
            'content_directory': content_dir.name
        }
        self.write_config()
        Config.reload()

        expect(os.path.exists(os.path.join(content_dir.name, 'image_uploads'))).to(be_true)

        content_dir.cleanup()
Esempio n. 8
0
    def test_get_database(self):
        self.config['databases'] = {
            "connection": {
                "driver": "sqlite",
                "database": ":memory:",
            },
        }
        self.write_config()
        Config.reload()

        db = Config.database()
        expect(db).to(be_an(orator.DatabaseManager))
Esempio n. 9
0
    def test_use_database(self):
        expect(Config.use_database()).to(be_false)

        self.config['databases'] = {
            "connection": {
                "driver": "sqlite",
                "database": ":memory:",
            },
        }
        self.write_config()
        Config.reload()

        expect(Config.use_database()).to(be_true)
Esempio n. 10
0
    def test_init_results(self):
        """Make sure _init_results does what is expected"""

        config = Config()
        config.monitors = {
            "http://test/": {},
            "http://test2/": {}
        }

        result = App._init_results(config)

        assert result["http://test/"] is None
        assert result["http://test2/"] is None
Esempio n. 11
0
def api_config_post():
    args = request.form
    name = args["name"]
    api = args["api"]
    token = args["token"]
    config = Config.query.get(1)
    if not config:
        config = Config(name, api, token)
        db.session.add(config)
        db.session.commit()
    config.name = name
    config.api = api
    config.token = token
    db.session.commit()
    return jsonify({"message": "OK."}), 200
Esempio n. 12
0
def config_fixture() -> Config:
    return Config(
        data_refresh_period=None,
        reverse_geocoding_path=TEST_DATA_PATH / "station_location.csv",
        port=0,
        user_content_storage=None,
        velib_data_base_path=TEST_DATA_PATH,
    )
Esempio n. 13
0
    def uri(self, type):
        db_uri = None

        if type == DBType.sqlite:
            db_uri = "sqlite:///" + Config()["database"]["sqlite"]["path"]

        if type == DBType.mysql:
            config = Config()["database"]["mysql"]
            db_uri = "mysql+pymysql://{0}:{1}@{2}:3306/{3}".format(
                config["user"], config["password"], config["host"],
                config["db"])

        if type == DBType.postgres:
            config = Config()["database"]["postgres"]
            db_uri = "postgresql://{0}:{1}@{2}:{3}/{4}".format(
                config["user"], config["password"], config["host"],
                config["port"], config["db"])

        return db_uri
    def index(self):
        themes = list(Config.themes().keys())
        if Config.theme and Config.theme in themes:
            default_theme = Config.theme
            themes.remove(default_theme)
        else:
            default_theme = None

        return self.template("danger/index.html",
                             generators=GeneratorService.all().values(),
                             themes=themes,
                             default_theme=default_theme)
Esempio n. 15
0
    def test_expected_configs(self):
        expected_region = 'test-region'
        expected_sender_email = '*****@*****.**'

        os.environ['SES_AWS_REGION'] = expected_region
        os.environ['SES_SENDER_EMAIL'] = expected_sender_email

        expected = Config(
            ses_aws_region=expected_region,
            ses_sender_email=expected_sender_email,
        )

        actual = get_configs_by_env()
        self.assertEqual(expected, actual)
    def deploy(self):
        if "location" not in request.form:
            return jsonify(success=False,
                           message="No location specified",
                           field="location"), 400
        generator_key = request.form["location"]

        if generator_key not in GeneratorService.all():
            return jsonify(success=False,
                           message="That deploy location doesn't exist",
                           field="location"), 400

        if "theme" not in request.form:
            return jsonify(success=False,
                           message="No theme specified",
                           field="theme"), 400
        theme_name = request.form["theme"]
        all_themes = Config.themes()

        if theme_name not in all_themes:
            return jsonify(success=False,
                           message="Theme not found",
                           field="theme"), 400
        theme_path = all_themes[theme_name]

        try:
            GeneratorService.all()[generator_key].deploy(theme_path=theme_path)
        except Exception as e:
            Config.capture_exception(e)
            return jsonify(
                success=False,
                message=
                "An error occurred when trying to deploy the site. No changes have been made, and your friendly neighborhood administrator has been alerted."
            ), 500

        return jsonify(success=True), 200
Esempio n. 17
0
    def test_database_is_memoized(self):
        self.config['databases'] = {
            "connection": {
                "driver": "sqlite",
                "database": ":memory:",
            },
        }
        self.write_config()
        Config.reload()

        db1 = Config.database()
        db2 = Config.database()

        expect(db1).to(be(db2))

        Config.reload()
        db3 = Config.database()

        expect(db1).not_to(be(db3))
Esempio n. 18
0
class _Model(orator.Model):
    __resolver = Config.database()

    __primary_key__ = 'pk'
    __guarded__ = []

    @classmethod
    def _table_name(cls):
        return cls.__table__ or inflection.tableize(cls.__name__)

    @classmethod
    def _columns(cls):
        connection = cls.resolve_connection()
        columns = connection.get_schema_manager().list_table_columns(
            cls._table_name())
        return {name: column.get_type() for name, column in columns.items()}

    # HACK!!!
    #   Done to allow templates to use column names as a variable
    #       {% set column = 'pk' %}
    #       {{ user[column] }}
    def __getitem__(self, item):
        return getattr(self, item)
Esempio n. 19
0
    def test_read_example(self):
        """Just try to read the example config and make sure we do it right"""

        config = Config()
        config.read_from_file('config.example.yaml')
Esempio n. 20
0
import pytest

from app import Config

Config.load_app_config("appconftest.conf")

from app.utils import ldap_utils


def test_get_user_from_ldap():

    with pytest.raises(ldap_utils.BoardLDAPConnectionError):
        ldap_utils.get_user_from_ldap("nouser", "nopass")
Esempio n. 21
0
    def test_read_example(self):
        """Just try to read the example config and make sure we do it right"""

        config = Config()
        config.read_from_file('config.example.yaml')
Esempio n. 22
0
def api_config_get():
    config = Config.query.get(1)
    if not config:
        config = Config("", "", "")
        db.session.commit()
    return jsonify({"config": config.to_dict()}), 200
Esempio n. 23
0
    def write_config(self):
        with open(os.path.join(self.config_dir.name, 'application.yaml'), 'w') as handler:
            handler.write(yaml.dump(self.config, default_flow_style = False))

        Config._full_reload()
Esempio n. 24
0
    def get_service(self, service):
        return self.c.catalog.service(service)

    def deregister_service(self, service_id):
        return self.c.agent.service.deregister(service_id)

    def register_service(self, service_name, vmid, port, address, tags):
        # register(name, service_id=None, address=None, port=None, tags=None, check=None, token=None, script=None, interval=None, ttl=None, http=None, timeout=None, enable_tag_override=False)
        self.c.agent.service.register(service_name,
                                      service_id=vmid,
                                      port=port,
                                      address=address,
                                      tags=[tags])


config = Config().read()
logging.basicConfig(filename=config['settings']['log_file'],
                    filemode='a',
                    format='%(asctime)s [ %(levelname)s ] - %(message)s',
                    datefmt='%m/%d/%Y  %H:%M:%S',
                    level=config['settings']['log_level'])


def register(service_name, data):
    new = []
    for x in data:
        new.append(x['vmid'])

    old = []
    for x in Consul().get_service(service_name)[1]:
        old.append(x['ServiceID'])
Esempio n. 25
0
import pytest

from app import Config
Config.load_app_config('appconftest.conf')

from app.db import db

def goodConfig():
  Config.load_app_config('appconftest.conf')

def badConfig():
  Config.database['host'] = 'badhost'
  Config.database['port'] = '0000'
  Config.database['user'] = '******'
  Config.database['passwd'] = 'badpass'
  Config.database['schema'] = 'bad_db'


def test_DBConnection_good():

  goodConfig()

  dbcm = db._DBConnectionManager()

  dbc = dbcm.get_connection( 'unittest_database' )
  assert dbc.conn is not None

  with pytest.raises(db.BoardDbConfigurationError):
    dbcm.get_connection( 'unittest_baddatabase' )

Esempio n. 26
0
    def __init__(self, bucket_name):
        self.bucket_name = bucket_name
        self._client = Config.aws_session().client('s3')
        self.s3 = Config.aws_session().resource('s3')

        self.bucket = self.s3.Bucket(self.bucket_name)
Esempio n. 27
0
import random
import time
import datetime
import calendar
import MySQLdb


from app import Config
Config.load_app_config()



g_conn = MySQLdb.connect( host        = Config.database['host'],
                          user        = Config.database['user'],
                          passwd      = Config.database['passwd'],
                          db          = Config.database['schema'],
                          charset     = 'utf8',
                          use_unicode = True)
g_conn.autocommit(False)
g_cur = g_conn.cursor()



def db_get_pronto_list( cutoff_date_start, cutoff_date_end ):

    sql = """SELECT problem_id, created, closed, type, severity
             FROM problem_report
             LEFT JOIN severity ON problem_report.severity_id = severity.id
             WHERE created <= %s AND ( `closed` IS NULL OR %s <= `closed` )"""
    params = ( cutoff_date_end, cutoff_date_start )
    g_cur.execute( sql, params )
Esempio n. 28
0
def insert_row(row):
    """
    This was another meathod I was trying out so that I could separate the data into better tables instead of just
    one, but time was an issue to get this project done.
    """
    session = Config.Session()
    try:
        movie = Movie(color=row[0],
                      director_name=row[1],
                      num_critic_for_reviews=int(row[2]),
                      duration=int(row[3]),
                      actor_2_name=row[6],
                      gross=int(row[8]),
                      genres=row[9],
                      actor_1_name=row[10],
                      movie_name=row[11],
                      num_voted_users=int(row[12]),
                      cast_total_facebook_likes=int(row[13]),
                      actor_3_name=row[14],
                      facenumber_in_poster=int(row[15]),
                      plot_keywords=row[16],
                      movie_imdb_link=row[17],
                      num_user_for_review=row[18],
                      language=row[19],
                      country=row[20],
                      content_rating=row[21],
                      budget=int(row[22]),
                      title_year=int(row[23]),
                      imdb_score=float(row[25]),
                      aspect_ration=float(row[26]),
                      movie_facebook_likes=int(row[27]))
        print(movie)
        session.add(movie)
        session.commit()
    except:
        print("Movie was not added to database")
    try:
        actor_1 = Actor(actor_name=row[10],
                        movie_name=row[11],
                        facebook_likes=int(row[7]))
        session.add(actor_1)
        session.commit()
    except:
        print("Actor 1 was not added to database.")
    try:
        actor_2 = Actor(actor_name=row[6],
                        movie_name=row[11],
                        facebook_likes=int(row[24]))
        session.add(actor_2)
        session.commit()
    except:
        print("Actor 2 was not added to database.")
    try:
        actor_3 = Actor(actor_name=row[14],
                        movie_name=row[11],
                        facebook_likes=int(row[5]))
        session.add(actor_3)
        session.commit()
    except:
        print("Actor 3 was not added to database.")
    try:
        director = Director(director_name=row[1],
                            movie_name=row[11],
                            facebook_likes=int(row[4]))
        session.add(director)
        session.commit()
    except:
        print("Director was not added  to database.")
Esempio n. 29
0
def interface(ctx):
    """SetupEnv: A simple templating program"""
    ctx.obj = Config()
Esempio n. 30
0
 def test_no_file(self):
     os.environ['CONFIG_DIR'] = os.path.join(self.config_dir.name, 'not_a_dir')
     expect(
         lambda: Config._full_reload()
     ).not_to(raise_error)
Esempio n. 31
0
from sqlalchemy.exc import DatabaseError
from flask_sqlalchemy import Model
from sqlalchemy.orm import sessionmaker

from app import Config
from app.utils.traces import print_exception_traces


class DBType(Enum):
    sqlite = 1
    mysql = 2
    postgres = 3


db_type = DBType.sqlite  # Default
if "sqlite" == Config()["database"]["active"]:
    db_type = DBType.sqlite
if "mysql" == Config()["database"]["active"]:
    db_type = DBType.mysql
if "postgres" == Config()["database"]["active"]:
    db_type = DBType.postgres


## Init session
class DBSession():
    def uri(self, type):
        db_uri = None

        if type == DBType.sqlite:
            db_uri = "sqlite:///" + Config()["database"]["sqlite"]["path"]
Esempio n. 32
0
 def setUpClass(cls):
     # create test database
     config = Config(RuntimeEnvironment.TEST)
     if not database_exists(config.db_uri):
         create_database(config.db_uri)
Esempio n. 33
0
def goodConfig():
  Config.load_app_config('appconftest.conf')
Esempio n. 34
0
import os
from flask import Flask
from app import log_util as log
from app import Config
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config.from_object(Config.ProductionConfig())
db = SQLAlchemy(app)

from app.models import SpecieDb
from app import routes
log.init_logger(os.path.dirname(app.instance_path))
# db.drop_all()
db.create_all()
Esempio n. 35
0
#!/usr/bin/env python3

import logging

from app import Config
from ldaploginprovider import LDAPLoginProvider

LOGFORMAT = "[%(asctime)s] [%(levelname)8s] --- %(message)s (%(filename)s:%(lineno)s)"
logging.basicConfig(level=logging.INFO, format=LOGFORMAT)

config = Config()
logging.info("Building ldap_provider")
ldap_provider = LDAPLoginProvider(config.ldap_server, config.ldap_base_dn, config.ldap_user_prefix)
ldap_provider.build_connection()

logging.info("Attempting to login")
user = ldap_provider.login(config.known_user, config.known_pass)
logging.info("Login: " + str(user.__dict__))
Esempio n. 36
0
 def test_get_database_no_config(self):
     expect(
         lambda: Config.database()
     ).to(raise_error(AttributeError))