Skip to content

Commit

Permalink
add test for open api schema controller + isort
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtedn21 committed Nov 13, 2023
1 parent a4ad621 commit db43742
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 39 deletions.
2 changes: 1 addition & 1 deletion alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from logging.config import fileConfig

from database import Base
from sqlalchemy import engine_from_config, pool

from alembic import context
from database import Base

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
9 changes: 2 additions & 7 deletions martin_eden/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from martin_eden import core
from martin_eden import database
from martin_eden import http_utils
from martin_eden import base
from martin_eden import openapi
from martin_eden import routing
from martin_eden import utils
from martin_eden import (base, core, database, http_utils, openapi, routing,
utils)

__all__ = [
'core',
Expand Down
2 changes: 1 addition & 1 deletion martin_eden/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import ParamSpecArgs, ParamSpecKwargs, Any
from typing import Any, ParamSpecArgs, ParamSpecKwargs

from marshmallow import Schema
from marshmallow.decorators import post_dump
Expand Down
11 changes: 6 additions & 5 deletions martin_eden/core.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@

import asyncio
import dataclasses
import json
import socket
from asyncio import AbstractEventLoop
from typing import Any, Optional
from martin_eden.routing import FindControllerError

from dacite import from_dict as dataclass_from_dict

from martin_eden.base import Controller
from martin_eden.database import DataBase, query_params_to_alchemy_filters
from martin_eden.http_utils import HttpHeadersParser, HttpMethod, create_response_headers
from martin_eden.http_utils import (HttpHeadersParser, HttpMethod,
create_response_headers)
from martin_eden.openapi import OpenApiBuilder
from martin_eden.routing import ControllerDefinitionError, get_controller, register_route
from martin_eden.routing import (ControllerDefinitionError,
FindControllerError, get_controller,
register_route)
from martin_eden.utils import get_argument_names
from martin_eden.base import Controller

db = DataBase()

Expand Down
22 changes: 8 additions & 14 deletions martin_eden/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@

from marshmallow.fields import Date, DateTime, Int, Nested, Str
from marshmallow_enum import EnumField as MarshmallowEnum
from sqlalchemy.ext.asyncio import (
AsyncAttrs,
AsyncEngine,
async_sessionmaker,
create_async_engine,
)
from sqlalchemy.ext.asyncio import (AsyncAttrs, AsyncEngine,
async_sessionmaker, create_async_engine)
from sqlalchemy.orm import DeclarativeBase

from martin_eden.base import CustomSchema
from martin_eden.utils import (
get_name_of_model,
get_python_field_type_from_alchemy_field,
is_enum_alchemy_field,
is_property_secondary_relation,
is_simple_alchemy_field,
is_special_alchemy_field,
)
from martin_eden.utils import (get_name_of_model,
get_python_field_type_from_alchemy_field,
is_enum_alchemy_field,
is_property_secondary_relation,
is_simple_alchemy_field,
is_special_alchemy_field)


class Base(AsyncAttrs, DeclarativeBase):
Expand Down
9 changes: 3 additions & 6 deletions martin_eden/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
from typing import TYPE_CHECKING

from martin_eden.base import CustomJsonSchema, CustomSchema
from martin_eden.utils import (
dict_set,
get_name_of_model,
get_operation_id_for_openapi,
get_python_field_type_from_alchemy_field,
)
from martin_eden.utils import (dict_set, get_name_of_model,
get_operation_id_for_openapi,
get_python_field_type_from_alchemy_field)

if TYPE_CHECKING:
from database import Base as BaseModel
Expand Down
5 changes: 2 additions & 3 deletions tests/test_http_headers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from martin_eden.http_utils import (
HttpHeadersParser, create_response_headers,
)
import pytest

from martin_eden.http_utils import HttpHeadersParser, create_response_headers
from tests.conftest import base_http_request, base_http_result_headers


Expand Down
22 changes: 20 additions & 2 deletions tests/test_http_message_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import json

import pytest
from martin_eden.routing import register_route

from martin_eden.core import HttpMessageHandler
from tests.conftest import base_http_result_headers, base_http_request
from martin_eden.http_utils import HttpHeadersParser
from martin_eden.routing import register_route
from tests.conftest import base_http_request, base_http_result_headers

pytest_plugins = ('pytest_asyncio',)

Expand Down Expand Up @@ -70,3 +74,17 @@ async def test_options_method(http_get_request, http_headers):
response = await handler.handle_request()

assert response == http_headers


@pytest.mark.asyncio
async def test_openapi_schema(http_get_request):
http_get_request = http_get_request.replace(b'/users/', b'/schema/')

handler = HttpMessageHandler(http_get_request)
response = await handler.handle_request()

parser = HttpHeadersParser(response.decode('utf8'))
openapi_result = json.loads(parser.body)
assert openapi_result['paths'] == {
'/test/': {'get': {'operationId': 'test_get'}}
}

0 comments on commit db43742

Please sign in to comment.