Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade psycopg and FastAPI #484

Merged
merged 3 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: test
name: Unit Test
on: [pull_request]

jobs:
unit-test-postgres:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: run unit test using postgres
run: docker-compose run ibet-prime-postgres
7 changes: 4 additions & 3 deletions app/routers/e2e_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ def list_all_accounts(db: Session = Depends(db_session)):
# WHERE t2.account_address = t1.account_address
# )
rsa_key_aliased = aliased(E2EMessagingAccountRsaKey)
subquery_max = db.query(func.max(rsa_key_aliased.block_timestamp)). \
filter(rsa_key_aliased.account_address == E2EMessagingAccountRsaKey.account_address)
subquery_max = db.query(func.max(rsa_key_aliased.block_timestamp)).\
filter(rsa_key_aliased.account_address == E2EMessagingAccountRsaKey.account_address).\
scalar_subquery()
subquery = db.query(E2EMessagingAccountRsaKey). \
filter(E2EMessagingAccountRsaKey.block_timestamp == subquery_max)
latest_rsa_key = aliased(E2EMessagingAccountRsaKey, subquery.subquery("latest_rsa_key"), adapt_on_names=True)
Expand Down Expand Up @@ -517,7 +518,7 @@ def list_all_e2e_messages(
responses=get_routers_responses(422, 404)
)
def retrieve_e2e_messaging(
_id: str = Path(..., alias="id"),
_id: int = Path(..., alias="id"),
db: Session = Depends(db_session)):
"""Retrieve an e2e message"""

Expand Down
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
# Database
if 'pytest' in sys.modules: # for unit test
DATABASE_URL = os.environ.get("TEST_DATABASE_URL") or \
'postgresql://issuerapi:issuerapipass@localhost:5432/issuerapidb_test'
'postgresql+psycopg://issuerapi:issuerapipass@localhost:5432/issuerapidb_test'
purplesmoke05 marked this conversation as resolved.
Show resolved Hide resolved
else:
DATABASE_URL = os.environ.get("DATABASE_URL") or \
'postgresql://issuerapi:issuerapipass@localhost:5432/issuerapidb'
'postgresql+psycopg://issuerapi:issuerapipass@localhost:5432/issuerapidb'
DATABASE_SCHEMA = os.environ.get('DATABASE_SCHEMA')
DB_ECHO = True if CONFIG['database']['echo'] == 'yes' else False

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
context: ./
dockerfile: ./tests/Dockerfile
environment:
- TEST_DATABASE_URL=postgresql://apluser:apluserpass@postgres/apldb
- TEST_DATABASE_URL=postgresql+psycopg://apluser:apluserpass@postgres/apldb
- WEB3_HTTP_PROVIDER=http://quorum:8545
- RESPONSE_VALIDATION_MODE=1
links:
Expand Down
11 changes: 6 additions & 5 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async-timeout==4.0.2
attrs==22.2.0
base58==2.1.1
bitarray==2.7.3
boto3==1.26.68
boto3==1.26.78
botocore==1.29.78
certifi==2022.12.7
cffi==1.15.1
Expand All @@ -23,7 +23,7 @@ eth-keys==0.3.4
eth-rlp==0.2.1
eth-typing==2.3.0
eth-utils==1.10.0
fastapi==0.91.0
fastapi==0.92.0
frozenlist==1.3.3
greenlet==2.0.2
gunicorn==20.1.0
Expand All @@ -42,10 +42,11 @@ netaddr==0.8.0
orjson==3.8.6
parsimonious==0.8.1
protobuf==3.19.5
psycopg2-binary==2.9.5
psycopg==3.1.8
psycopg-binary==3.1.8
pycparser==2.21
pycryptodome==3.17
pydantic==1.10.4
pydantic==1.10.5
PyMySQL==1.0.2
pyrsistent==0.19.3
python-dateutil==2.8.2
Expand All @@ -57,7 +58,7 @@ shared-memory-dict==0.7.2
six==1.16.0
sniffio==1.3.0
SQLAlchemy==2.0.4
starlette==0.24.0
starlette==0.25.0
toolz==0.12.0
typing_extensions==4.5.0
urllib3==1.26.14
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
alembic==1.9.4
boto3==1.26.68
boto3>=1.26,<1.27
coincurve==18.0.0
eth-keyfile==0.5.1
eth-utils==1.10.0
fastapi==0.91.0
fastapi==0.92.0
gunicorn==20.1.0
orjson==3.8.6
psycopg2-binary==2.9.5
psycopg[binary]>=3.1,<3.2
pycryptodome==3.17
pydantic==1.10.4
pydantic==1.10.5
PyMySQL==1.0.2
pytz==2022.7.1
requests==2.28.2
Expand Down
25 changes: 25 additions & 0 deletions tests/test_app_routers_e2e_messaging_messages_{id}_GET.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,31 @@ def test_normal_1_4(self, client, db):
# Not Found Error
# no data
def test_error_1(self, client, db):
# request target API
resp = client.get(
self.base_url.format(id="id")
)

# assertion
assert resp.status_code == 422
assert resp.json() == {
'meta': {
'code': 1,
'title': 'RequestValidationError'
},
'detail': [
{
'loc': ['path', 'id'],
'msg': 'value is not a valid integer',
'type': 'type_error.integer'
}
]
}

# <Error_2>
# Not Found Error
# no data
def test_error_2(self, client, db):
# prepare data
e2e_messaging = {
"id": 10,
Expand Down