Skip to content

Commit 7dc9f25

Browse files
authored
Merge pull request #144 from python-ellar/test_coverage_fix
Test coverage fix
2 parents 1067360 + 2fa9f91 commit 7dc9f25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+65
-80
lines changed

ellar/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Ellar - Python ASGI web framework for building fast, efficient, and scalable RESTful APIs and server-side applications."""
22

3-
__version__ = "0.5.6"
3+
__version__ = "0.5.7"

ellar/cache/backends/local_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections import OrderedDict
66

77
from anyio import Lock
8-
from ellar.common.helper.event_loop import get_or_create_eventloop
8+
from ellar.common.utils.event_loop import get_or_create_eventloop
99

1010
from ..interface import IBaseCacheBackendAsync
1111
from ..make_key_decorator import make_key_decorator, make_key_decorator_and_validate

ellar/cache/backends/redis/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import typing as t
33
from abc import ABC
44

5-
from ellar.common.helper.event_loop import get_or_create_eventloop
5+
from ellar.common.utils.event_loop import get_or_create_eventloop
66

77
try:
88
from redis.asyncio import Redis

ellar/cache/make_key_decorator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import functools
22
import typing as t
33

4-
from ellar.common.helper import is_async_callable
4+
from ellar.common.utils import is_async_callable
55

66
if t.TYPE_CHECKING: # pragma: no cover
77
from .model import BaseCacheBackend

ellar/common/decorators/html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
TEMPLATE_GLOBAL_KEY,
1111
)
1212
from ellar.common.exceptions import ImproperConfiguration
13-
from ellar.common.helper import class_base_function_regex, get_name
1413
from ellar.common.responses.models import HTMLResponseModel
1514
from ellar.common.shortcuts import fail_silently
1615
from ellar.common.templating import TemplateFunctionData
1716
from ellar.common.types import TemplateFilterCallable, TemplateGlobalCallable
17+
from ellar.common.utils import class_base_function_regex, get_name
1818

1919
from .base import set_metadata as set_meta
2020

ellar/common/exceptions/callable_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import typing as t
22

3-
from ellar.common.helper import is_async_callable
43
from ellar.common.interfaces import IExceptionHandler, IHostContext
4+
from ellar.common.utils import is_async_callable
55
from starlette.concurrency import run_in_threadpool
66
from starlette.responses import Response
77

ellar/common/interfaces/controller_factory.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

ellar/common/params/args/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import inspect
22
import typing as t
33

4-
from ellar.common.helper.modelfield import create_model_field
4+
from ellar.common.utils.modelfield import create_model_field
55
from pydantic.fields import FieldInfo, ModelField, Required
66
from pydantic.schema import get_annotation_from_field_info
77

ellar/common/params/args/request_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import typing as t
22

33
from ellar.common.constants import MULTI_RESOLVER_KEY
4-
from ellar.common.helper.modelfield import create_model_field
54
from ellar.common.interfaces import IExecutionContext
65
from ellar.common.logger import logger
6+
from ellar.common.utils.modelfield import create_model_field
77
from pydantic import BaseModel, create_model
88
from pydantic.fields import ModelField
99
from starlette.convertors import Convertor

ellar/common/params/params.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import copy
2-
import re
3-
import sys
41
import typing as t
52
from enum import Enum
63

@@ -22,13 +19,6 @@
2219
WsBodyParameterResolver,
2320
)
2421

25-
if sys.version_info >= (3, 6):
26-
27-
def copier(x: t.Any, memo: t.Dict) -> t.Any:
28-
return x
29-
30-
copy._deepcopy_dispatch[type(re.compile(""))] = copier # type: ignore
31-
3222

3323
class ParamTypes(Enum):
3424
query = "query"

ellar/common/responses/models/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
from ellar.common.constants import SERIALIZER_FILTER_KEY
55
from ellar.common.exceptions import RequestValidationError
6-
from ellar.common.helper.modelfield import create_model_field
76
from ellar.common.interfaces import IExecutionContext, IResponseModel
87
from ellar.common.logger import request_logger
98
from ellar.common.serializer import SerializerFilter, serialize_object
9+
from ellar.common.utils.modelfield import create_model_field
1010
from ellar.reflect import reflect
1111
from pydantic import BaseModel
1212
from pydantic.fields import ModelField

ellar/common/responses/models/json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import typing as t
22

33
from ellar.common.constants import SERIALIZER_FILTER_KEY
4-
from ellar.common.helper.modelfield import create_model_field
54
from ellar.common.interfaces import IExecutionContext
65
from ellar.common.logger import request_logger
76
from ellar.common.serializer import SerializerFilter, serialize_object
7+
from ellar.common.utils.modelfield import create_model_field
88
from ellar.reflect import reflect
99

1010
from ..response_types import JSONResponse, Response

ellar/common/routing/mount.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import uuid
33

44
from ellar.common.constants import CONTROLLER_CLASS_KEY, GUARDS_KEY, VERSIONING_KEY
5-
from ellar.common.helper import get_unique_control_type
65
from ellar.common.logger import request_logger
76
from ellar.common.models import GuardCanActivate
87
from ellar.common.types import TReceive, TScope, TSend
8+
from ellar.common.utils import get_unique_control_type
99
from ellar.reflect import reflect
1010
from starlette.routing import BaseRoute, Match, Route, Router
1111
from starlette.routing import Mount as StarletteMount

ellar/common/routing/route.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
RESPONSE_OVERRIDE_KEY,
99
)
1010
from ellar.common.exceptions import ImproperConfiguration, RequestValidationError
11-
from ellar.common.helper import generate_operation_unique_id, get_name
1211
from ellar.common.interfaces import IExecutionContext
1312
from ellar.common.logger import request_logger
1413
from ellar.common.params import ExtraEndpointArg, RequestEndpointArgsModel
1514
from ellar.common.responses.models import RouteResponseModel
15+
from ellar.common.utils import generate_operation_unique_id, get_name
1616
from ellar.reflect import reflect
1717
from starlette.concurrency import run_in_threadpool
1818
from starlette.responses import Response

ellar/common/routing/route_collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import uuid
33
from collections import OrderedDict
44

5-
from ellar.common.helper import generate_controller_operation_unique_id
65
from ellar.common.logger import logger
6+
from ellar.common.utils import generate_controller_operation_unique_id
77
from starlette.routing import BaseRoute, Host, Mount
88

99

ellar/common/routing/websocket/route.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
ImproperConfiguration,
1010
WebSocketRequestValidationError,
1111
)
12-
from ellar.common.helper import get_name
1312
from ellar.common.interfaces import IExecutionContext
1413
from ellar.common.logger import request_logger
1514
from ellar.common.params import ExtraEndpointArg, WebsocketEndpointArgsModel
15+
from ellar.common.utils import get_name
1616
from ellar.reflect import reflect
1717
from starlette.routing import WebSocketRoute as StarletteWebSocketRoute
1818
from starlette.routing import compile_path
File renamed without changes.

ellar/common/utils/crypto.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import math
2+
import secrets
3+
4+
RANDOM_STRING_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
5+
6+
7+
def must_update_salt(salt: str, expected_entropy: int) -> bool:
8+
# Each character in the salt provides log_2(len(alphabet)) bits of entropy.
9+
return len(salt) * math.log2(len(RANDOM_STRING_CHARS)) < expected_entropy
10+
11+
12+
def get_random_string(length: int, allowed_chars: str = RANDOM_STRING_CHARS) -> str:
13+
"""
14+
Return a securely generated random string.
15+
16+
The bit length of the returned value can be calculated with the formula:
17+
log_2(len(allowed_chars)^length)
18+
19+
For example, with default `allowed_chars` (26+26+10), this gives:
20+
* length: 12, bit length =~ 71 bits
21+
* length: 22, bit length =~ 131 bits
22+
"""
23+
return "".join(
24+
secrets.choice(allowed_chars) for _ in range(length)
25+
) # pragma no cover
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

ellar/core/conf/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from ellar.common.compatible.dict import AttributeDictAccessMixin
44
from ellar.common.constants import ELLAR_CONFIG_MODULE
5-
from ellar.common.helper.importer import import_from_string
65
from ellar.common.types import VT
6+
from ellar.common.utils.importer import import_from_string
77
from starlette.config import environ
88

99
from .app_settings_models import ConfigValidationSchema

ellar/core/middleware/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import typing as t
22

3-
from ellar.common.helper import build_init_kwargs
43
from ellar.common.interfaces import IEllarMiddleware
54
from ellar.common.types import ASGIApp
5+
from ellar.common.utils import build_init_kwargs
66
from ellar.di import EllarInjector, injectable
77
from starlette.middleware import Middleware
88

ellar/core/modules/ref.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
TEMPLATE_FILTER_KEY,
1111
TEMPLATE_GLOBAL_KEY,
1212
)
13-
from ellar.common.helper import build_init_kwargs
1413
from ellar.common.models import ControllerBase
1514
from ellar.common.routing import ModuleMount
1615
from ellar.common.templating import ModuleTemplating
16+
from ellar.common.utils import build_init_kwargs
1717
from ellar.di import (
1818
MODULE_REF_TYPES,
1919
Container,

ellar/core/routing/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
CONTROLLER_OPERATION_HANDLER_KEY,
77
ROUTE_OPERATION_PARAMETERS,
88
)
9-
from ellar.common.helper import get_unique_control_type
109
from ellar.common.logger import logger
1110
from ellar.common.routing import (
1211
RouteOperation,
1312
RouteOperationBase,
1413
WebsocketRouteOperation,
1514
)
1615
from ellar.common.routing.schema import RouteParameters, WsRouteParameters
16+
from ellar.common.utils import get_unique_control_type
1717
from ellar.reflect import reflect
1818

1919

ellar/core/security/constants.py

Whitespace-only changes.

ellar/core/security/hashers/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import typing as t
22

3+
from ellar.common.utils.crypto import get_random_string
4+
35
from .argon2 import Argon2Hasher
4-
from .base import BaseHasher, EncodingType, get_random_string, must_update_salt
6+
from .base import BaseHasher, EncodingType
57
from .bcrypt import BCryptHasher, BCryptSHA256Hasher
68
from .md5 import MD5Hasher
79
from .pbkdf import PBKDF2Hasher, PBKDF2SHA1Hasher
@@ -125,7 +127,6 @@ def check_password(
125127
"BCryptHasher",
126128
"ScryptHasher",
127129
"MD5Hasher",
128-
"must_update_salt",
129130
"make_password",
130131
"check_password",
131132
"is_password_usable",

ellar/core/security/hashers/argon2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import typing as t
22

3+
from ellar.common.utils.crypto import must_update_salt
34
from passlib.hash import argon2
45

5-
from .base import BaseHasher, EncodingSalt, EncodingType, must_update_salt
6+
from .base import BaseHasher, EncodingSalt, EncodingType
67

78

89
class Argon2Hasher(BaseHasher):

ellar/core/security/hashers/base.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,21 @@
11
import math
2-
import secrets
32
import typing as t
43
from abc import ABC, abstractmethod
54

65
import passlib.utils.handlers as uh
6+
from ellar.common.utils.crypto import RANDOM_STRING_CHARS, get_random_string
77

88
# This will never be a valid encoded hash
99
UNUSABLE_PASSWORD_PREFIX = "!"
1010
UNUSABLE_PASSWORD_SUFFIX_LENGTH = (
1111
40 # number of random chars to add after UNUSABLE_PASSWORD_PREFIX
1212
)
1313

14-
RANDOM_STRING_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
15-
1614
__HASHERS_DICT: t.Dict[str, t.Type["BaseHasher"]] = {}
1715
EncodingType = t.Union[str, bytes]
1816
EncodingSalt = t.Optional[t.Union[str, bytes]]
1917

2018

21-
def must_update_salt(salt: str, expected_entropy: int) -> bool:
22-
# Each character in the salt provides log_2(len(alphabet)) bits of entropy.
23-
return len(salt) * math.log2(len(RANDOM_STRING_CHARS)) < expected_entropy
24-
25-
26-
def get_random_string(length: int, allowed_chars: str = RANDOM_STRING_CHARS) -> str:
27-
"""
28-
Return a securely generated random string.
29-
30-
The bit length of the returned value can be calculated with the formula:
31-
log_2(len(allowed_chars)^length)
32-
33-
For example, with default `allowed_chars` (26+26+10), this gives:
34-
* length: 12, bit length =~ 71 bits
35-
* length: 22, bit length =~ 131 bits
36-
"""
37-
return "".join(
38-
secrets.choice(allowed_chars) for _ in range(length)
39-
) # pragma no cover
40-
41-
4219
class BaseHasher(ABC):
4320
hasher: t.Union[t.Type[uh.GenericHandler], t.Any]
4421
algorithm: str

ellar/core/security/hashers/md5.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import typing as t
22

3+
from ellar.common.utils.crypto import must_update_salt
34
from passlib.hash import md5_crypt
45

5-
from .base import BaseHasher, EncodingSalt, EncodingType, must_update_salt
6+
from .base import BaseHasher, EncodingSalt, EncodingType
67

78

89
class MD5Hasher(BaseHasher):

ellar/core/security/hashers/pbkdf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from ellar.common.utils.crypto import must_update_salt
12
from passlib.hash import django_pbkdf2_sha1, django_pbkdf2_sha256
23

3-
from .base import BaseHasher, must_update_salt
4+
from .base import BaseHasher
45

56

67
class PBKDF2Hasher(BaseHasher):

ellar/openapi/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from ellar.common import IIdentitySchemes
55
from ellar.common.compatible import AttributeDict, cached_property
66
from ellar.common.constants import GUARDS_KEY, REF_PREFIX
7-
from ellar.common.helper.modelfield import create_model_field
87
from ellar.common.routing import ModuleMount, RouteOperation
98
from ellar.common.routing.controller import ControllerRouteOperation
9+
from ellar.common.utils.modelfield import create_model_field
1010
from ellar.openapi.constants import OPENAPI_OPERATION_KEY, OPENAPI_TAG
1111
from pydantic import AnyUrl, BaseModel, EmailStr
1212
from pydantic.fields import ModelField

ellar/socket_io/decorators/gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ellar.common.compatible import AttributeDict
66
from ellar.common.constants import CONTROLLER_CLASS_KEY
77
from ellar.common.exceptions import ImproperConfiguration
8-
from ellar.common.helper import get_name
8+
from ellar.common.utils import get_name
99
from ellar.di import RequestScope, injectable
1010
from ellar.reflect import REFLECT_TYPE, reflect
1111
from ellar.socket_io.constants import (

ellar/socket_io/decorators/subscribe_message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import typing as t
22

3-
from ellar.common.helper import get_name
3+
from ellar.common.utils import get_name
44
from ellar.reflect import reflect
55
from ellar.socket_io.constants import MESSAGE_MAPPING_METADATA, MESSAGE_METADATA
66

ellar/socket_io/gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
SCOPE_SERVICE_PROVIDER,
1616
)
1717
from ellar.common.exceptions import WebSocketRequestValidationError
18-
from ellar.common.helper import get_name
1918
from ellar.common.params import WebsocketEndpointArgsModel
19+
from ellar.common.utils import get_name
2020
from ellar.core import Config
2121
from ellar.di import EllarInjector
2222
from ellar.reflect import reflect

tests/test_application/test_application_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
template_filter,
1313
template_global,
1414
)
15-
from ellar.common.helper.importer import get_class_import
1615
from ellar.common.templating import Environment
16+
from ellar.common.utils.importer import get_class_import
1717
from ellar.core import Config, ModuleBase
1818
from ellar.core.connection import Request
1919
from ellar.core.modules import ModuleTemplateRef

0 commit comments

Comments
 (0)