Skip to content

Commit

Permalink
Better naming for some classes
Browse files Browse the repository at this point in the history
  • Loading branch information
pylover committed Jul 21, 2019
1 parent 2710342 commit d5cc3ec
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions restfulpy/application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .cli.main import EntryPoint
from ..authentication import Authenticator
from ..configuration import configure
from ..exceptions import SqlError
from ..exceptions import SQLError
from ..orm import init_model, create_engine, DBSession
from ..cryptography import AESCipher
from .. import logger
Expand Down Expand Up @@ -41,7 +41,7 @@ def __init__(self, name: str, root: Controller = None, root_path='.',

def _handle_exception(self, ex, start_response):
if isinstance(ex, SQLAlchemyError):
ex = SqlError(ex)
ex = SQLError(ex)
logger.error(ex)
if not isinstance(ex, HTTPStatus):
ex = HTTPInternalServerError('Internal server error')
Expand Down
2 changes: 1 addition & 1 deletion restfulpy/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#path: /
messaging:
# default_messenger: restfulpy.messaging.providers.SmtpProvider
# default_messenger: restfulpy.messaging.providers.SMTPProvider
default_messenger: restfulpy.messaging.ConsoleMessenger
default_sender: restfulpy
mako_modules_directory:
Expand Down
2 changes: 1 addition & 1 deletion restfulpy/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def metadata(self):



class JsonPatchControllerMixin:
class JSONPatchControllerMixin:

@action(content_type='application/json', prevent_empty_form=True)
def patch(self: Controller):
Expand Down
2 changes: 1 addition & 1 deletion restfulpy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UnsupportedError(Exception):
pass


class SqlError(HTTPStatus):
class SQLError(HTTPStatus):

def __init__(self, sqlalchemy_error):
super().__init__(self.map_exception(sqlalchemy_error))
Expand Down
2 changes: 1 addition & 1 deletion restfulpy/messaging/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

from .models import Email
from .providers import Messenger, create_messenger, SmtpProvider, \
from .providers import Messenger, create_messenger, SMTPProvider, \
ConsoleMessenger
4 changes: 2 additions & 2 deletions restfulpy/messaging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlalchemy import Integer, ForeignKey, Unicode
from sqlalchemy.ext.declarative import declared_attr

from ..orm import Field, FakeJson,synonym
from ..orm import Field, FakeJSON,synonym
from ..taskqueue import RestfulpyTask
from .providers import create_messenger

Expand All @@ -16,7 +16,7 @@ class Email(RestfulpyTask):
subject = Field(Unicode(254), json='subject')
cc = Field(Unicode(254), nullable=True, json='cc')
bcc = Field(Unicode(254), nullable=True, json='bcc')
_body = Field('body', FakeJson)
_body = Field('body', FakeJSON)

from_ = Field(
Unicode(254),
Expand Down
2 changes: 1 addition & 1 deletion restfulpy/messaging/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def send(self, to, subject, body, cc=None, bcc=None,
raise NotImplementedError


class SmtpProvider(Messenger):
class SMTPProvider(Messenger):

def send(self, to, subject, body, cc=None, bcc=None,
template_filename=None, from_=None, attachments=None):
Expand Down
2 changes: 1 addition & 1 deletion restfulpy/orm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
DeactivationMixin
from .models import BaseModel
from .fulltext_search import to_tsvector, fts_escape
from .types import FakeJson
from .types import FakeJSON

# Global session manager: DBSession() returns the Thread-local
# session object appropriate for the current web request.
Expand Down
2 changes: 1 addition & 1 deletion restfulpy/orm/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlalchemy import Unicode, TypeDecorator


class FakeJson(TypeDecorator):
class FakeJSON(TypeDecorator):
impl = Unicode

def process_bind_param(self, value, engine):
Expand Down
2 changes: 1 addition & 1 deletion restfulpy/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def logout(self):
self._authentication_token = None


class Uuid1Freeze:
class UUID1Freeze:
_original = None

def __init__(self, uuid_):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
DateTime
from sqlalchemy.ext.associationproxy import association_proxy

from restfulpy.controllers import JsonPatchControllerMixin, ModelRestController
from restfulpy.controllers import JSONPatchControllerMixin, ModelRestController
from restfulpy.orm import commit, DeclarativeBase, Field, DBSession, \
composite, FilteringMixin, PaginationMixin, OrderingMixin, relationship, \
ModifiedMixin, ActivationMixin, synonym
Expand Down Expand Up @@ -163,7 +163,7 @@ def _get_avatar(self): # pragma: no cover
)


class Root(JsonPatchControllerMixin, ModelRestController):
class Root(JSONPatchControllerMixin, ModelRestController):
__model__ = Member

@json
Expand Down
4 changes: 2 additions & 2 deletions tests/test_commit_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from nanohttp import json, RestController, context, HTTPStatus
from sqlalchemy import Unicode, Integer

from restfulpy.controllers import JsonPatchControllerMixin
from restfulpy.controllers import JSONPatchControllerMixin
from restfulpy.orm import commit, DeclarativeBase, Field, DBSession
from restfulpy.testing import ApplicableTestCase

Expand All @@ -13,7 +13,7 @@ class CommitCheckingModel(DeclarativeBase):
title = Field(Unicode(50), unique=True)


class Root(JsonPatchControllerMixin, RestController):
class Root(JSONPatchControllerMixin, RestController):

@json
@commit
Expand Down
2 changes: 1 addition & 1 deletion tests/test_console_messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
HERE = abspath(dirname(__file__))


class TestSmtpProvider:
class TestSMTPProvider:
__configuration__ = f'''
messaging:
mako_modules_directory: {join(HERE, '../../data', 'mako_modules')}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sqlalchemy import Integer, Date

from restfulpy.configuration import settings
from restfulpy.controllers import JsonPatchControllerMixin, ModelRestController
from restfulpy.controllers import JSONPatchControllerMixin, ModelRestController
from restfulpy.datetimehelpers import parse_datetime, format_datetime, \
parse_date, format_date
from restfulpy.mockup import mockup_localtimezone
Expand All @@ -21,7 +21,7 @@ class Party(DeclarativeBase):
when = Field(Date)


class Root(JsonPatchControllerMixin, ModelRestController):
class Root(JSONPatchControllerMixin, ModelRestController):
__model__ = 'party'

@json
Expand Down
4 changes: 2 additions & 2 deletions tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from freezegun import freeze_time
from restfulpy.configuration import settings
from restfulpy.controllers import JsonPatchControllerMixin, ModelRestController
from restfulpy.controllers import JSONPatchControllerMixin, ModelRestController
from restfulpy.datetimehelpers import parse_datetime, format_datetime, \
localnow, parse_time, localtimezone
from restfulpy.mockup import mockup_localtimezone
Expand All @@ -22,7 +22,7 @@ class Metting(DeclarativeBase):
when = Field(DateTime)


class Root(JsonPatchControllerMixin, ModelRestController):
class Root(JSONPatchControllerMixin, ModelRestController):
__model__ = 'metting'

@json
Expand Down
4 changes: 2 additions & 2 deletions tests/test_jsonpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from nanohttp import context, json, RestController, HTTPNotFound, HTTPStatus
from sqlalchemy import Unicode, Integer

from restfulpy.controllers import JsonPatchControllerMixin
from restfulpy.controllers import JSONPatchControllerMixin
from restfulpy.orm import commit, DeclarativeBase, Field, DBSession
from restfulpy.testing import ApplicableTestCase

Expand All @@ -21,7 +21,7 @@ class Person(DeclarativeBase):
)


class Root(JsonPatchControllerMixin, RestController):
class Root(JSONPatchControllerMixin, RestController):
__model__ = Person

@json(prevent_empty_form=True)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_messenger_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from nanohttp import settings, configure

from restfulpy.messaging.providers import create_messenger, ConsoleMessenger,\
SmtpProvider
SMTPProvider


HERE = abspath(dirname(__file__))
Expand All @@ -21,7 +21,7 @@ def test_messenger_factory():
assert isinstance(console_messenger, ConsoleMessenger)

settings.messaging.default_messenger =\
'restfulpy.messaging.providers.SmtpProvider'
'restfulpy.messaging.providers.SMTPProvider'
smtp_messenger = create_messenger()
assert isinstance(smtp_messenger, SmtpProvider)
assert isinstance(smtp_messenger, SMTPProvider)

8 changes: 4 additions & 4 deletions tests/test_smtp_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from nanohttp import settings, configure

from restfulpy.messaging.providers import SmtpProvider
from restfulpy.messaging.providers import SMTPProvider
from restfulpy.mockup import mockup_smtp_server


Expand Down Expand Up @@ -34,7 +34,7 @@ def test_smtp_provider():
settings.smtp.port = bind[1]

# Without templates
SmtpProvider().send(
SMTPProvider().send(
'test@example.com',
'test@example.com',
'Simple test body',
Expand All @@ -43,7 +43,7 @@ def test_smtp_provider():
)

# With template
SmtpProvider().send(
SMTPProvider().send(
'test@example.com',
'test@example.com',
{},
Expand All @@ -53,7 +53,7 @@ def test_smtp_provider():
# With attachments
attachment = io.BytesIO(b'This is test attachment file')
attachment.name = 'path/to/file.txt'
SmtpProvider().send(
SMTPProvider().send(
'test@example.com',
'test@example.com',
'email body with Attachment',
Expand Down
18 changes: 9 additions & 9 deletions tests/test_sql_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from nanohttp import json
from sqlalchemy import Unicode, Integer

from restfulpy.controllers import JsonPatchControllerMixin, ModelRestController
from restfulpy.controllers import JSONPatchControllerMixin, ModelRestController
from restfulpy.orm import commit, DeclarativeBase, Field, DBSession, \
FilteringMixin, PaginationMixin, OrderingMixin, ModifiedMixin
from restfulpy.testing import ApplicableTestCase
from restfulpy.exceptions import SqlError
from restfulpy.exceptions import SQLError


class SqlErrorCheckingModel(
class SQLErrorCheckingModel(
ModifiedMixin,
FilteringMixin,
PaginationMixin,
Expand All @@ -23,22 +23,22 @@ class SqlErrorCheckingModel(


class Root(ModelRestController):
__model__ = SqlErrorCheckingModel
__model__ = SQLErrorCheckingModel

@json
@commit
def post(self):
m = SqlErrorCheckingModel()
m = SQLErrorCheckingModel()
m.update_from_request()
DBSession.add(m)
return m

@json
@SqlErrorCheckingModel.expose
@SQLErrorCheckingModel.expose
def get(self, title: str=None):
query = SqlErrorCheckingModel.query
query = SQLErrorCheckingModel.query
if title:
return query.filter(SqlErrorCheckingModel.title == title)\
return query.filter(SQLErrorCheckingModel.title == title)\
.one_or_none()
return query

Expand All @@ -59,5 +59,5 @@ def test_sql_errors(self):
assert status == 409

def test_invalid_sql_error(self):
assert '500 Internal server error' == SqlError.map_exception(ValueError())
assert '500 Internal server error' == SQLError.map_exception(ValueError())

4 changes: 2 additions & 2 deletions tests/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sqlalchemy import Integer, Time

from restfulpy.configuration import settings
from restfulpy.controllers import JsonPatchControllerMixin, ModelRestController
from restfulpy.controllers import JSONPatchControllerMixin, ModelRestController
from restfulpy.datetimehelpers import parse_datetime, format_datetime, \
format_time
from restfulpy.mockup import mockup_localtimezone
Expand All @@ -21,7 +21,7 @@ class Azan(DeclarativeBase):
when = Field(Time)


class Root(JsonPatchControllerMixin, ModelRestController):
class Root(JSONPatchControllerMixin, ModelRestController):
__model__ = 'azan'

@json
Expand Down
8 changes: 4 additions & 4 deletions tests/test_uuidfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from nanohttp import json
from sqlalchemy.dialects.postgresql import UUID

from restfulpy.controllers import JsonPatchControllerMixin, ModelRestController
from restfulpy.controllers import JSONPatchControllerMixin, ModelRestController
from restfulpy.orm import commit, DeclarativeBase, Field, DBSession
from restfulpy.testing import ApplicableTestCase, Uuid1Freeze
from restfulpy.testing import ApplicableTestCase, UUID1Freeze


def new_uuid():
Expand All @@ -20,7 +20,7 @@ class Uuid1Model(DeclarativeBase):
id = Field(UUID(as_uuid=True), primary_key=True, default=new_uuid)


class Root(JsonPatchControllerMixin, ModelRestController):
class Root(JSONPatchControllerMixin, ModelRestController):
__model__ = Uuid1Model

@json
Expand All @@ -37,6 +37,6 @@ class TestUuidField(ApplicableTestCase):
def test_uuid1(self):
frozen_uuid_str = 'ce52b1ee602a11e9a721b06ebfbfaee7'
frozen_uuid = uuid.UUID(frozen_uuid_str)
with Uuid1Freeze(frozen_uuid), self.given('testing uuid'):
with UUID1Freeze(frozen_uuid), self.given('testing uuid'):
assert response.json['id'] == frozen_uuid_str

0 comments on commit d5cc3ec

Please sign in to comment.