Skip to content

Commit 3efc167

Browse files
committed
switch from requests to httpx
1 parent 019e4b5 commit 3efc167

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
4141
- name: Install python dependencies
4242
run: |
43-
python -m pip install pytest pytest-asyncio httpx pypgstac==0.7.1 psycopg[pool] brotlipy requests boto3 pytest-pgsql psycopg2
43+
python -m pip install pytest pytest-asyncio httpx pypgstac==0.7.1 psycopg[pool] brotlipy boto3 pytest-pgsql psycopg2
4444
4545
- name: Test CDK DB Bootstrap
4646
working-directory: ./infrastructure/aws

infrastructure/aws/dockerfiles/Dockerfile.db

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG PYTHON_VERSION=3.9
1+
ARG PYTHON_VERSION=3.10
22

33
FROM public.ecr.aws/lambda/python:${PYTHON_VERSION}
44

@@ -10,7 +10,7 @@ WORKDIR /tmp
1010
RUN python -m pip install pip -U
1111

1212
RUN echo "Using PGSTAC Version ${PGSTAC_VERSION}"
13-
RUN python -m pip install requests psycopg["binary,pool"] pypgstac==${PGSTAC_VERSION} -t /asset
13+
RUN python -m pip install httpx psycopg["binary,pool"] pypgstac==${PGSTAC_VERSION} -t /asset
1414

1515
COPY infrastructure/aws/handlers/db_handler.py /asset/handler.py
1616

infrastructure/aws/handlers/db_handler.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
"""Bootstrap Postgres db."""
22

33
import json
4+
import logging
45

56
import boto3
7+
import httpx
68
import psycopg
7-
import requests
89
from psycopg import sql
910
from psycopg.conninfo import make_conninfo
1011
from pypgstac.db import PgstacDB
1112
from pypgstac.migrate import Migrate
1213

14+
logger = logging.getLogger("eoapi-bootstrap")
15+
1316

1417
def send(
1518
event,
@@ -56,10 +59,12 @@ def send(
5659
headers = {"content-type": "", "content-length": str(len(json_responseBody))}
5760

5861
try:
59-
response = requests.put(responseUrl, data=json_responseBody, headers=headers)
60-
print("Status code: " + response.reason)
62+
response = httpx.put(responseUrl, data=json_responseBody, headers=headers)
63+
print(f"Status code: {response.status_code}")
64+
logger.debug(f"OK - Status code: {response.status_code}")
6165
except Exception as e:
62-
print("send(..) failed executing requests.put(..): " + str(e))
66+
print("send(..) failed executing httpx.put(..): " + str(e))
67+
logger.debug(f"NOK - failed executing PUT requests: {e}")
6368

6469

6570
def get_secret(secret_name):

infrastructure/aws/tests/test_bootstrap.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
"""Test bootstrap handler."""
22

33
import json
4+
import logging
45
from unittest.mock import patch
56

67
from handlers import db_handler
78

89

9-
@patch("handlers.db_handler.requests")
10+
@patch("handlers.db_handler.httpx")
1011
@patch("handlers.db_handler.boto3")
11-
def test_bootstrap(boto3, requests, database_url):
12+
def test_bootstrap(boto3, httpx, database_url, caplog):
1213
"""Test Bootstrap."""
1314
boto3.client.return_value.get_secret_value.side_effect = [
1415
# connection_params
@@ -38,11 +39,12 @@ def test_bootstrap(boto3, requests, database_url):
3839
]
3940

4041
class put:
41-
"""Fake requests.put response."""
42+
"""Fake httpx.put response."""
4243

44+
status_code: int = 200
4345
reason: str = "All Good"
4446

45-
requests.put.return_value = put()
47+
httpx.put.return_value = put()
4648

4749
event = {
4850
"StackId": "eoapi-test",
@@ -66,4 +68,7 @@ class ctx:
6668

6769
context = ctx()
6870

69-
db_handler.handler(event, context)
71+
with caplog.at_level(logging.DEBUG, logger="eoapi-bootstrap"):
72+
db_handler.handler(event, context)
73+
for record in caplog.records:
74+
assert record.message == "OK - Status code: 200"

0 commit comments

Comments
 (0)