Skip to content

Commit

Permalink
fix: fix minor issues, remove docs from cicd flow (#18)
Browse files Browse the repository at this point in the history
Co-authored-by: Ran Isenberg <[email protected]>
  • Loading branch information
ran-isenberg and Ran Isenberg authored Aug 3, 2023
1 parent ede08b7 commit 26d789d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,3 @@ jobs:
- name: Destroy stack
if: always()
run: make destroy

generate_docs_on_main:
name: generate_docs_on_main
runs-on: ubuntu-latest
needs: [build]
permissions:
contents: write # for docs push
if: contains('refs/heads/main', github.ref)
steps:
- name: Check out repository code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Set up Python 3.11
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
with:
python-version: "3.11"
- name: Install dependencies
run: |
pip install --upgrade pip poetry
make deps
pip install -r dev_requirements.txt
- name: Generate docs
run: |
mkdocs gh-deploy --force
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from aws_cdk.aws_lambda_python_alpha import PythonLayerVersion
from aws_cdk.aws_logs import RetentionDays
from constructs import Construct
from {{cookiecutter.service_name}}.api_db_construct import ApiDbConstruct # type: ignore

from cdk.{{cookiecutter.service_name}}.api_db_construct import ApiDbConstruct
import cdk.{{cookiecutter.service_name}}.constants as constants


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from cdk_nag import AwsSolutionsChecks, NagSuppressions
from constructs import Construct
from git import Repo
from {{cookiecutter.service_name}}.api_construct import ApiConstruct # type: ignore

from cdk.{{cookiecutter.service_name}}.api_construct import ApiConstruct
from cdk.{{cookiecutter.service_name}}.configuration.configuration_construct import ConfigurationStore
from cdk.{{cookiecutter.service_name}}.constants import CONFIGURATION_NAME, ENVIRONMENT, SERVICE_NAME

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ def test_handler_200_ok(mocker, table_name: str):
assert response['Item']['order_item_count'] == order_item_count


def test_internal_server_error():
def test_internal_server_error(mocker):
mock_dynamic_configuration(mocker, MOCKED_SCHEMA)
db_handler: DynamoDalHandler = DynamoDalHandler('table')
table = db_handler._get_db_handler()
stubber = Stubber(table.meta.client)
stubber.add_client_error(method='put_item', service_error_code='ValidationException')
stubber.activate()
body = CreateOrderRequest(customer_name='RanTheBuilder', order_item_count=5)
response = call_create_order(generate_api_gw_event(body.model_dump()))
stubber.deactivate()
assert response['statusCode'] == HTTPStatus.INTERNAL_SERVER_ERROR
DynamoDalHandler._instances = {}


def test_handler_bad_request(mocker):
Expand Down
3 changes: 3 additions & 0 deletions {{cookiecutter.repo_name}}/tests/unit/test_db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ def test_raise_exception():
stubber.activate()
with pytest.raises(InternalServerException):
db_handler.create_order_in_db(customer_name='customer', order_item_count=5)
stubber.deactivate()
DynamoDalHandler._instances = {}

Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from abc import ABC, abstractmethod
from abc import ABC, ABCMeta, abstractmethod

from {{cookiecutter.service_name}}.dal.schemas.db import OrderEntry


class DalHandler(ABC):
class _SingletonMeta(ABCMeta):
_instances: dict = {}

def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(_SingletonMeta, cls).__call__(*args, **kwargs)
return cls._instances[cls]


class DalHandler(ABC, metaclass=_SingletonMeta):

@abstractmethod
def create_order_in_db(self, customer_name: str, order_item_count: int) -> OrderEntry:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create_order(event: Dict[str, Any], context: LambdaContext) -> Dict[str, Any
try:
my_configuration: MyConfiguration = parse_configuration(model=MyConfiguration) # type: ignore
logger.debug('fetched dynamic configuration', extra={'configuration': my_configuration.model_dump()})
except (SchemaValidationError, ConfigurationStoreError) as exc:
except (SchemaValidationError, ConfigurationStoreError) as exc: # pragma: no cover
logger.exception(f'dynamic configuration error, error={str(exc)}')
return build_response(http_status=HTTPStatus.INTERNAL_SERVER_ERROR, body={})

Expand Down

0 comments on commit 26d789d

Please sign in to comment.