def test_get(self): os.environ['VALUE'] = '1,2' value = environ.get_list('VALUE') self.assertEqual(value, ['1', '2']) os.environ['VALUE'] = '1,2' value = environ.get_list('VALUE', item_factory=int) self.assertEqual(value, [1, 2])
'PAGE_SIZE': 10 } # telegram TELEGRAM_BOT_TOKEN = easy_env.get('TELEGRAM_BOT_TOKEN', raise_error=True) TELEGRAM_TIMEOUT = 30 # seconds # celery REDIS_URL = easy_env.get('REDIS_URL', 'redis://localhost:6379/0') CELERY_BROKER_URL = REDIS_URL CELERY_RESULT_BACKEND = REDIS_URL CELERY_TASK_SERIALIZER = 'json' CELERY_WORKER_CONCURRENCY = easy_env.get_int('CELERY_WORKER_CONCURRENCY', default=multiprocessing.cpu_count()) CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler' CELERY_REDIS_MAX_CONNECTIONS = 20 # core TG_ADMINS = easy_env.get_list('ADMINS', [], item_factory=int) # reddit REDDIT_FETCH_SIZE = easy_env.get_int('REDDIT_FETCH_SIZE', default=100) # imgur IMGUR_CLIENT_ID = easy_env.get('IMGUR_CLIENT_ID') IMGUR_FETCH_LIMIT = easy_env.get_int('IMGUR_FETCH_LIMIT', default=100) IMGUR_DELETE_ON_FAIL = easy_env.get_bool('IMGUR_DELETE_ON_FAIL', default=True) # rss RSS_CLEAN_KEEP = easy_env.get_int('RSS_CLEAN_KEEP', default=30)
import easy_env from dotenv import find_dotenv, load_dotenv load_dotenv(find_dotenv()) DEBUG = easy_env.get_bool('DEBUG', default=False) USERBOT_NAME = easy_env.get('USERBOT_NAME', 'userbot') REDIS_URL = easy_env.get_str('REDIS_URL') API_ID = easy_env.get_int('API_ID', raise_error=True) API_HASH = easy_env.get('API_HASH', raise_error=True) USER_PHONE = easy_env.get('USER_PHONE') USER_PASSWORD = easy_env.get('USER_PASSWORD') NOU_LIST = easy_env.get_list('NOU_LIST', ['baka', 'idiot'], separator='|') NOU_PATTERN = "|".join([f"\\b{w}\\b" for w in NOU_LIST]) NOU_PATTERN = f'.*({NOU_PATTERN}).*' NOU_LIST_REGEX = re.compile(NOU_PATTERN, re.IGNORECASE) NAME = easy_env.get('NAME', 'dude') LOGS_FILE_PATH = easy_env.get('LOGS_FILE_PATH', 'logs.txt') LOGS_FILE_DIR = os.path.split(LOGS_FILE_PATH)[0] if LOGS_FILE_DIR: os.makedirs(LOGS_FILE_DIR, exist_ok=True) LOGGING_LEVEL = easy_env.get('LOGGING_LEVEL', 'DEBUG') LOGGING_LEVEL_ROOT = easy_env.get('LOGGING_LEVEL_ROOT', 'INFO') MASTER_KEY = easy_env.get('MASTER_KEY', 'key') PORT = easy_env.get('PORT', 5000)
def test_collections(self): os.environ['VALUE'] = '1,2' value = environ.get_list('VALUE', item_factory=int, collection=list) self.assertListEqual(value, [1, 2]) value = environ.get_list('VALUE', item_factory=int, collection=set) self.assertSetEqual(value, {1, 2})
def test_bad_value(self): os.environ['VALUE'] = '1,,2' with self.assertRaises(ValueError): environ.get_list('VALUE', item_factory=int)
def test_raise_error(self): with self.assertRaises(KeyError): environ.get_list('VALUE', raise_error=True)
def test_none(self): value = environ.get_list('VALUE') self.assertIsNone(value)
def test_get_default(self): value = environ.get_list('VALUE', [1, 2]) self.assertEqual(value, [1, 2])
def test_another_separator(self): os.environ['VALUE'] = '1 2' value = environ.get_list('VALUE', separator=' ') self.assertEqual(value, ['1', '2'])