From 4193bb9f5de68a0b442f0e3620e49850410ab72a Mon Sep 17 00:00:00 2001 From: Henty Date: Fri, 1 Jul 2022 16:20:34 +0100 Subject: [PATCH] Lets go --- README.md | 2 +- requirements.txt | 2 +- setup.cfg | 2 +- tcsocket/app/settings.py | 8 ++++++-- tcsocket/requirements.txt | 18 +++++++++--------- tests/conftest.py | 16 ++++++++-------- tests/requirements.txt | 12 ++++++------ 7 files changed, 32 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 8be016e3..f9ac5983 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Backend application for [TutorCruncher's](https://tutorcruncher.com) web integra # LICENSE -Copyright TutorCruncher ltd. 2017 - 2021. +Copyright TutorCruncher ltd. 2017 - 2022. All rights reserved. ## Deploying diff --git a/requirements.txt b/requirements.txt index 9666bcdf..065d040e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ # this should install everything you need for development or testing, you might also want to install "ipython" -r tcsocket/requirements.txt -r tests/requirements.txt -aiohttp-devtools==0.13.1 +aiohttp-devtools==1.0.post0 diff --git a/setup.cfg b/setup.cfg index 759c099d..1af7d22e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [tool:pytest] testpaths = tests -addopts = --isort --aiohttp-loop uvloop --aiohttp-fast --tb=native +addopts = --isort --tb=native [flake8] max-line-length = 120 diff --git a/tcsocket/app/settings.py b/tcsocket/app/settings.py index 1999d580..801f5548 100644 --- a/tcsocket/app/settings.py +++ b/tcsocket/app/settings.py @@ -10,7 +10,7 @@ class Settings(BaseSettings): - pg_dsn: Optional[str] = 'postgresql://postgres@localhost:5432/socket' + database_url: Optional[str] = 'postgresql://postgres@localhost:5432/socket' redis_settings: RedisSettings = 'redis://localhost:6379' redis_database: int = 0 @@ -39,6 +39,10 @@ def parse_redis_settings(cls, v): database=int((conf.path or '0').strip('/')), ) + @property + def pg_dsn(self): + return self.database_url.replace('gres://', 'gresql://') + @property def images_url(self): return f'https://{self.aws_bucket_name}' @@ -66,7 +70,7 @@ def pg_port(self): class Config: fields = { 'port': {'env': 'PORT'}, - 'pg_dsn': {'env': 'DATABASE_URL'}, + 'database_url': {'env': 'DATABASE_URL'}, 'redis_settings': {'env': 'REDISCLOUD_URL'}, 'tc_api_root': {'env': 'TC_API_ROOT'}, 'aws_access_key': {'env': 'AWS_ACCESS_KEY'}, diff --git a/tcsocket/requirements.txt b/tcsocket/requirements.txt index 2a641bcd..44a8acb5 100644 --- a/tcsocket/requirements.txt +++ b/tcsocket/requirements.txt @@ -1,19 +1,19 @@ -SQLAlchemy==1.3.23 +SQLAlchemy==1.4.39 aiodns==3.0.0 aiohttp==3.8.1 -aiopg==1.3.3 +aiopg==1.3.4 aioredis==1.3.1 arq==0.22 -boto3==1.20.44 +boto3==1.24.21 cchardet==2.1.7 gunicorn==20.1.0 python-dateutil==2.8.2 -pillow==9.0.0 -pydantic[email]==1.9.0 +pillow==9.1.1 +pydantic[email]==1.9.1 raven==6.10.0 -requests==2.27.1 +requests==2.28.1 uvloop==0.16.0 -ipython==7.31.1 -pgcli==3.3.1 -ipython-sql==0.4.0 +ipython==8.4.0 +pgcli==3.4.1 +ipython-sql==0.4.1 yarl==1.7.2 diff --git a/tests/conftest.py b/tests/conftest.py index 2eb52cbe..9c9c2a84 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -321,7 +321,7 @@ async def geocoding_view(request): return json_response(loc, status=status) -@pytest.yield_fixture(name='redis') +@pytest.fixture(name='redis') async def _fix_redis(settings): addr = settings.redis_settings.host, settings.redis_settings.port @@ -334,7 +334,7 @@ async def _fix_redis(settings): await redis.wait_closed() -@pytest.yield_fixture(name='worker_ctx') +@pytest.fixture(name='worker_ctx') async def _fix_worker_ctx(redis, settings, db_conn): session = ClientSession(timeout=ClientTimeout(total=10)) ctx = dict(settings=settings, pg_engine=MockEngine(db_conn), session=session, redis=redis) @@ -344,7 +344,7 @@ async def _fix_worker_ctx(redis, settings, db_conn): await session.close() -@pytest.yield_fixture(name='worker') +@pytest.fixture(name='worker') async def _fix_worker(redis, worker_ctx): worker = Worker(functions=WorkerSettings.functions, redis_pool=redis, burst=True, poll_delay=0.01, ctx=worker_ctx) @@ -383,7 +383,7 @@ def image_download_url(other_server): @pytest.fixture def settings(other_server): return Settings( - pg_dsn=os.getenv('DATABASE_URL', DB_DSN), + database_url=os.getenv('DATABASE_URL', DB_DSN), redis_database=7, master_key=MASTER_KEY, grecaptcha_secret='X' * 30, @@ -393,9 +393,9 @@ def settings(other_server): ) -@pytest.yield_fixture(scope='session') +@pytest.fixture(scope='session') def db(): - settings_ = Settings(pg_dsn=os.getenv('DATABASE_URL', DB_DSN)) + settings_ = Settings(database_url=os.getenv('DATABASE_URL', DB_DSN)) prepare_database(True, settings_) engine = sa_create_engine(settings_.pg_dsn) @@ -404,9 +404,9 @@ def db(): engine.dispose() -@pytest.yield_fixture +@pytest.fixture def db_conn(loop, settings, db): - engine = loop.run_until_complete(aio_create_engine(settings.pg_dsn, loop=loop)) + engine = loop.run_until_complete(aio_create_engine(settings.database_url, loop=loop)) conn = loop.run_until_complete(engine.acquire()) transaction = loop.run_until_complete(conn.begin()) diff --git a/tests/requirements.txt b/tests/requirements.txt index 4944e433..bd236d6e 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,14 +1,14 @@ attrs==21.4.0 -black==21.12b0 -coverage==6.2 +black==22.6.0 +coverage==6.4.1 flake8==4.0.1 isort==5.10.1 pycodestyle==2.8.0 pyflakes==2.4.0 -pytest==6.2.5 -pytest-aiohttp==0.3.0 +pytest==7.1.2 +pytest-aiohttp==1.0.4 pytest-cov==3.0.0 -pytest-isort==2.0.0 -pytest-mock==3.6.1 +pytest-isort==3.0.0 +pytest-mock==3.8.1 pytest-sugar==0.9.4 pytest-toolbox==0.4