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

Update Api (major) #2023

Merged
merged 3 commits into from
Sep 19, 2024
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
259 changes: 169 additions & 90 deletions api/poetry.lock

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,32 @@ python-dotenv = "^1.0.0"
pydantic = "^2.4.2"
botocore = "^1.31.62"
boto3 = "^1.28.62"
smart-open = "^6.1.0"
smart-open = "^7.0.0"
pytz = "^2023.3.post1"
APIFlask = "^2.1.0"
marshmallow-dataclass = { extras = ["enum", "union"], version = "^8.5.8" }
marshmallow = "^3.20.1"
gunicorn = "^22.0.0"
gunicorn = "^23.0.0"
psycopg = { extras = ["binary"], version = "^3.1.19" }
pydantic-settings = "^2.0.3"
flask-cors = "^5.0.0"
opensearch-py = "^2.5.0"

[tool.poetry.group.dev.dependencies]
black = "^23.9.1"
black = "^24.0.0"
isort = "^5.12.0"
mypy = "^1.8.0"
moto = { extras = ["s3"], version = "^4.0.2" }
moto = { extras = ["s3"], version = "^5.0.0" }
types-pytz = "^2023.3.1.1"
coverage = "^7.3.2"
Faker = "^19.8.0"
Faker = "^28.0.0"
factory-boy = "^3.3.0"
bandit = "^1.7.5"
pytest = "^7.4.2"
pytest = "^8.0.0"
pytest-watch = "^4.2.0"
pytest-lazy-fixture = "^0.6.3"
types-pyyaml = "^6.0.12.11"
setuptools = "^68.2.2"
pydot = "1.4.2"
setuptools = "^75.0.0"
pydot = "3.0.1"
sadisplay = "0.4.9"
ruff = "^0.4.0"
debugpy = "^1.8.1"
Expand Down
1 change: 1 addition & 0 deletions api/src/adapters/db/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

For usage information look at the package docstring in __init__.py
"""

import abc
import logging

Expand Down
1 change: 1 addition & 0 deletions api/src/adapters/db/flask_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def health():
db_client = flask_db.get_db(current_app)
# db_client.get_connection() or db_client.get_session()
"""

from functools import wraps
from typing import Callable, Concatenate, ParamSpec, TypeVar

Expand Down
6 changes: 2 additions & 4 deletions api/src/api/schemas/extension/field_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ class Regexp(validators.Regexp):
)

@typing.overload
def __call__(self, value: str) -> str:
...
def __call__(self, value: str) -> str: ...

@typing.overload
def __call__(self, value: bytes) -> bytes:
...
def __call__(self, value: bytes) -> bytes: ...

def __call__(self, value: str | bytes) -> str | bytes:
if self.regex.match(value) is None: # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-08-10 15:52:10.626153

"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-10-18 16:37:18.252136

"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-11-27 14:43:04.227044

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-12-11 13:13:33.446941

"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-01-29 14:07:42.665723

"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-02-02 11:36:33.241412

"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-02-07 12:16:16.564629

"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-02-12 15:58:54.880550

"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-02-21 13:44:50.932948

"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-03-07 10:20:15.639825

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-03-07 10:44:08.694002

"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-03-12 13:22:57.718265

"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-04-16 13:36:35.993325

"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-04-19 13:41:34.017203

"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-04-24 15:27:13.602523

"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-05-01 11:14:34.332661

"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-05-02 10:11:35.832837

"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-05-07 14:41:19.401963

"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-05-09 15:06:48.010975

"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2024-07-08 12:43:45.240782

"""

import sqlalchemy as sa
from alembic import op

Expand Down
14 changes: 8 additions & 6 deletions api/src/db/models/agency_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ class Agency(ApiSchemaTable, TimestampMixin):

assistance_listing_number: Mapped[str]

agency_submission_notification_setting: Mapped[
AgencySubmissionNotificationSetting
] = mapped_column(
"agency_submission_notification_setting_id",
LookupColumn(LkAgencySubmissionNotificationSetting),
ForeignKey(LkAgencySubmissionNotificationSetting.agency_submission_notification_setting_id),
agency_submission_notification_setting: Mapped[AgencySubmissionNotificationSetting] = (
mapped_column(
"agency_submission_notification_setting_id",
LookupColumn(LkAgencySubmissionNotificationSetting),
ForeignKey(
LkAgencySubmissionNotificationSetting.agency_submission_notification_setting_id
),
)
)

agency_contact_info_id: Mapped[BigInteger | None] = mapped_column(
Expand Down
8 changes: 4 additions & 4 deletions api/src/db/models/opportunity_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ class OpportunitySummary(ApiSchemaTable, TimestampMixin):
updated_by: Mapped[str | None]
created_by: Mapped[str | None]

link_funding_instruments: Mapped[
list["LinkOpportunitySummaryFundingInstrument"]
] = relationship(
back_populates="opportunity_summary", uselist=True, cascade="all, delete-orphan"
link_funding_instruments: Mapped[list["LinkOpportunitySummaryFundingInstrument"]] = (
relationship(
back_populates="opportunity_summary", uselist=True, cascade="all, delete-orphan"
)
)
link_funding_categories: Mapped[list["LinkOpportunitySummaryFundingCategory"]] = relationship(
back_populates="opportunity_summary", uselist=True, cascade="all, delete-orphan"
Expand Down
1 change: 0 additions & 1 deletion api/src/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
logger.info("message")
"""


import src.logging.config as config


Expand Down
1 change: 1 addition & 0 deletions api/src/logging/flask_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

flask_logger.init_app(logger, app)
"""

import logging
import time
import uuid
Expand Down
1 change: 1 addition & 0 deletions api/src/logging/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

See https://docs.python.org/3/library/logging.html#formatter-objects
"""

import json
import logging
from datetime import date, datetime
Expand Down
14 changes: 8 additions & 6 deletions api/src/task/opportunities/set_current_opportunities_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ def _process_opportunity(self, opportunity: Opportunity) -> None:
"existing_opportunity_status": opportunity.opportunity_status,
}
log_extra |= get_log_extra_for_summary(
opportunity.current_opportunity_summary.opportunity_summary
if opportunity.current_opportunity_summary
else None,
(
opportunity.current_opportunity_summary.opportunity_summary
if opportunity.current_opportunity_summary
else None
),
"existing",
)
logger.info("Processing opportunity %s", opportunity.opportunity_id, extra=log_extra)
Expand Down Expand Up @@ -245,9 +247,9 @@ def is_opportunity_changed(
def get_log_extra_for_summary(summary: OpportunitySummary | None, prefix: str) -> dict[str, Any]:
return {
f"{prefix}_opportunity_summary_id": summary.opportunity_summary_id if summary else None,
f"{prefix}_opportunity_summary_revision_number": summary.revision_number
if summary
else None,
f"{prefix}_opportunity_summary_revision_number": (
summary.revision_number if summary else None
),
f"{prefix}_opportunity_summary_is_forecast": summary.is_forecast if summary else None,
f"{prefix}_opportunity_summary_post_date": summary.post_date if summary else None,
f"{prefix}_opportunity_summary_close_date": summary.close_date if summary else None,
Expand Down
3 changes: 2 additions & 1 deletion api/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def reset_aws_env_vars(monkeypatch):

@pytest.fixture
def mock_s3(reset_aws_env_vars):
with moto.mock_s3():
# https://docs.getmoto.org/en/stable/docs/configuration/index.html#whitelist-services
with moto.mock_aws(config={"core": {"service_whitelist": ["s3"]}}):
yield boto3.resource("s3")


Expand Down
1 change: 1 addition & 0 deletions api/tests/lib/db_testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper functions for testing database code."""

import contextlib
import logging

Expand Down
1 change: 1 addition & 0 deletions api/tests/src/db/models/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
The factories are based on the `factory_boy` library. See
https://factoryboy.readthedocs.io/en/latest/ for more information.
"""

import random
from datetime import datetime
from typing import Optional
Expand Down
Loading