From ec08df909e4d244ca683d3cb753a887631f4b34d Mon Sep 17 00:00:00 2001 From: Dalton Barreto Date: Thu, 8 Oct 2020 22:52:10 -0300 Subject: [PATCH] Movendo config.py pra dentro da pasta do projeto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Geralmente todo o código do projeto está dentro dessa pasta. Até porque no momento de fazer pip install esse arquivo deve ir junto. --- config.py => myproj/config.py | 5 +---- tests/test_config.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) rename config.py => myproj/config.py (76%) create mode 100644 tests/test_config.py diff --git a/config.py b/myproj/config.py similarity index 76% rename from config.py rename to myproj/config.py index d1d4b0a..bcb08b2 100644 --- a/config.py +++ b/myproj/config.py @@ -1,5 +1,4 @@ import os -from typing import Optional from pydantic import BaseSettings @@ -18,9 +17,7 @@ class Settings(BaseSettings): DEBUG: bool = True class Config: - env_prefix = ( - os.getenv("NAMESPACE", "DEV").upper() + "_" - ) # defaults to 'APP_' + env_prefix = os.getenv("NAMESPACE", "DEV").upper() + "_" settings = Settings() diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..ab683c4 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,19 @@ +import os +from importlib import reload + +from asynctest import TestCase, mock + +from myproj import config + + +class ConfigTest(TestCase): + async def test_debug_is_false(self): + with mock.patch.dict(os.environ, DEV_DEBUG="0"): + s = config.Settings() + self.assertEqual(s.DEBUG, False) + + async def test_other_namespace(self): + with mock.patch.dict(os.environ, NAMESPACE="PROD", PROD_DEBUG="0"): + reload(config) + s = config.Settings() + self.assertEqual(s.DEBUG, False)