def __init__(self) -> None: self._parser = ConfigParser() self._parser.read_dict(_DEFAULT_CONF) file_name = f'{IDENTIFIER}.conf' paths = [ Path(Path.home(), f'.{file_name}'), Path(f'/etc/{IDENTIFIER}', file_name), Path('/etc', file_name), ] path = from_environ('AUTOMX2_CONF') if path: paths.insert(0, Path(path)) for path in paths: log.debug(f'Checking {path.resolve()}') if path.exists(): log.debug(f'Reading {path.resolve()}') self._parser.read_file(path.open('rt')) return log.warning('No configuration file found')
from automx2.model import LDAP_HOSTNAME from automx2.model import LDAP_PORT from automx2.model import LDAP_SEARCH_BASE from automx2.model import Ldapserver from automx2.model import db from automx2.model import populate_db from automx2.server import APPLE_CONFIG_ROUTE from automx2.server import MOZILLA_CONFIG_ROUTE from automx2.server import MSOFT_CONFIG_ROUTE from automx2.server import app from automx2.util import from_environ from automx2.views import CONTENT_TYPE_XML from automx2.views import EMAIL_MOZILLA from automx2.views import EMAIL_OUTLOOK RUN_LDAP_TESTS = from_environ('RUN_LDAP_TESTS') == '1' def body(response: Response) -> str: return str(response.data, encoding='utf-8', errors='strict') class TestCase(unittest.TestCase): """Test case base class.""" create_db = True def setUp(self) -> None: app.config['TESTING'] = True app.config['DEBUG'] = False self.app = app.test_client() with app.app_context():
from automx2.util import unique BIGCORP_NAME = 'Big Corporation, Inc.' BIGCORP_SHORT = 'BigCorp' EGGS_DOMAIN = 'ham-n-eggs.tld' EGGS_NAME = 'Ham & Eggs' EGGS_SHORT = 'H+E' EXAMPLE_COM = 'example.com' EXAMPLE_NET = 'example.net' EXAMPLE_ORG = 'example.org' ORPHAN_DOMAIN = 'orphan.tld' OTHER_NAME = 'Some Other Provider' OTHER_SHORT = 'SOP' SERVERLESS_DOMAIN = 'serverless.tld' LDAP_BIND_PASSWORD = from_environ('LDAP_BIND_PASSWORD') LDAP_BIND_USER = from_environ('LDAP_BIND_USER') LDAP_HOSTNAME = from_environ('LDAP_HOSTNAME') LDAP_PORT = from_environ('LDAP_PORT', 636) LDAP_SEARCH_BASE = from_environ('LDAP_SEARCH_BASE', 'dc=example,dc=com') sample_server_names = { 'imap1': f'imap1.{unique()}.com', 'imap2': f'imap2.{unique()}.com', 'smtp1': f'primary-smtp.{unique()}.com', 'smtp2': f'secondary-smtp.{unique()}.com', } db = SQLAlchemy() server_domain_map = db.Table('server_domain',
def test_does_not_exist_with_default(self): default = unique() x = from_environ(self.DOES_NOT_EXIST, default=default) self.assertEqual(default, x)
def test_does_not_exist(self): x = from_environ(self.DOES_NOT_EXIST) self.assertIsNone(x)
def test_exists(self): x = from_environ(self.EXISTS) self.assertEqual(self.VALUE, x)