Skip to content

Commit

Permalink
build: merge develop to master
Browse files Browse the repository at this point in the history
  • Loading branch information
piraz committed Apr 23, 2024
2 parents cb053b6 + ca71bf7 commit 4161972
Show file tree
Hide file tree
Showing 20 changed files with 285 additions and 258 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2015-2022 Flávio Gonçalves Garcia
Copyright 2015-2024 Flavio Garcia

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -57,7 +57,7 @@
# The short X.Y version.
version = '0.9'
# The full version, including alpha/beta/rc tags.
release = '0.9.4'
release = '0.9.5'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 2 additions & 0 deletions docs/releases.rst
Expand Up @@ -4,6 +4,8 @@ Release notes
.. toctree::
:maxdepth: 2

releases/v0.9.5
releases/v0.9.4
releases/v0.9.3
releases/v0.9.0
releases/v0.2.17
Expand Down
32 changes: 32 additions & 0 deletions docs/releases/v0.9.5.rst
@@ -0,0 +1,32 @@
What's new in Firenado 0.9.5
============================

Apr 23, 2024
------------

We are pleased to announce the release of Firenado 0.9.5.

This release fix the sqlalchemy connection ping rolling back transactions while
using 2.x style ORM.

It was also added a test case for Services to the project.

Here are the highlights:

Bug Fixes
~~~~~~~~~

* When creating a new sqlalchemy session, get default values from the data source configuration `#448 <https://github.com/candango/firenado/issues/448>`_
* Sqlalchemy data source ping connection will rollback every transaction `#449 <https://github.com/candango/firenado/issues/449>`_
* Fix requirements resolution while building distribution files `#451 <https://github.com/candango/firenado/issues/451>`_

Features
~~~~~~~~

* Create a test case for services `#450 <https://github.com/candango/firenado/issues/450>`_
* Disable sqlalchemy connection_ping by default `#452 <https://github.com/candango/firenado/issues/452>`_

Refactory
~~~~~~~~~

* Move isolation_level to the root of a sqlalchemy data source configuration `#447 <https://github.com/candango/firenado/issues/447>`_
19 changes: 11 additions & 8 deletions examples/testapp/app.py
Expand Up @@ -68,10 +68,10 @@ def initialize(self):
data_source_conf = {
'connector': "sqlalchemy",
'url': "mysql+pymysql://root@localhost:3306/test",
# 'isolation_level': 'REPEATABLE READ',
'pool': {
'size': 10,
'max_overflow': 10,
# 'isolation_level': 'REPEATABLE READ',
# 'pool_recycle': 400
}
}
Expand All @@ -83,19 +83,22 @@ def initialize(self):

@service.served_by(services.UserService)
def install(self):
from sqlalchemy.engine import Engine
""" Installing test database
"""
from firenado.util.sqlalchemy_util import Base
from testapp.models import Base
print('Installing Testapp App...')
print('Creating App ...')
engine = self.application.get_data_source(
engine: Engine = self.application.get_data_source(
'test').engine
engine.echo = True
# Dropping all
# TODO Not to drop all if something is installed right?
Base.metadata.drop_all(engine)
# Creating database
Base.metadata.create_all(engine)
with engine.connect() as conn:
# Dropping all
# TODO Not to drop all if something is installed right?
Base.metadata.drop_all(conn)
# Creating database
Base.metadata.create_all(conn)
conn.commit()
self.user_service.create({
'username': "Test",
'first_name': "Test",
Expand Down
12 changes: 9 additions & 3 deletions examples/testapp/handlers.py
@@ -1,6 +1,6 @@
# -*- coding: UTF-8 -*-
#
# Copyright 2015-2023 Flavio Garcia
# Copyright 2015-2024 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .services import LoginService, UserService

import firenado.conf
from firenado import security, service, tornadoweb
from firenado.util.sqlalchemy_util import base_to_dict
Expand Down Expand Up @@ -115,6 +117,9 @@ def get(self):

class LoginHandler(AuthHandler, tornadoweb.TornadoHandler):

login_service: LoginService
user_service: UserService

def get(self):
default_login = firenado.conf.app['login']['urls']['default']
errors = {}
Expand All @@ -126,8 +131,9 @@ def get(self):
self.render("login.html", errors=errors,
login_url=default_login)

@service.served_by("testapp.services.LoginService")
@service.served_by("testapp.services.UserService")
# you can user either the class rererence or string
@service.with_service(LoginService)
@service.with_service("testapp.services.UserService")
def post(self):
self.session.delete('login_errors')
default_login = firenado.conf.app['login']['urls']['default']
Expand Down
12 changes: 6 additions & 6 deletions examples/testapp/models.py
Expand Up @@ -13,8 +13,7 @@
# limitations under the License.

from datetime import datetime
from sqlalchemy import String
from sqlalchemy.types import DateTime
from sqlalchemy import DateTime, Integer, String
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from sqlalchemy.sql import text

Expand All @@ -25,11 +24,12 @@ class Base(DeclarativeBase):

class UserBase(Base):
__tablename__ = "users"
__table_args__ = {
'mysql_engine': "InnoDB",
'mysql_charset': "utf8",
}

mysql_engine = "MyISAM"
mysql_charset = "utf8"

id: Mapped[int] = mapped_column(primary_key=True)
id: Mapped[int] = mapped_column(Integer, primary_key=True)
username: Mapped[str] = mapped_column(String(150), nullable=False)
first_name: Mapped[str] = mapped_column(String(150), nullable=False)
last_name: Mapped[str] = mapped_column(String(150), nullable=False)
Expand Down
16 changes: 8 additions & 8 deletions examples/testapp/services.py
@@ -1,4 +1,4 @@
# Copyright 2015-2023 Flávio Gonçalves Garcia
# Copyright 2015-2024 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,16 +37,17 @@ def create(self, user_data, **kwargs):
user.last_name = user_data['last_name']
user.password = password_digest(user_data['password'])
user.email = user_data['email']
session = self.get_data_source('test').session
session.add(user)
session.commit()
with session.begin():
session.add(user)
return user

@with_session(data_source="test")
def by_username(self, username, **kwargs):
def by_username(self, username, **kwargs) -> UserBase:
session: Session = kwargs.get("session")
session.begin()
stmt = select(UserBase).where(UserBase.username == username)
user = session.scalars(stmt).one()
user = session.scalars(stmt).one_or_none()
session.flush()
return user


Expand All @@ -68,9 +69,8 @@ def is_valid(self, username, password):
"""
user = self.user_service.by_username(username)
print(user)
if user:
if user.password == password_digest(password):
return True
return False


2 changes: 1 addition & 1 deletion firenado/__init__.py
Expand Up @@ -18,7 +18,7 @@
"""The Firenado Framework"""

__author__ = "Flavio Garcia <piraz@candango.org>"
__version__ = (0, 9, 4)
__version__ = (0, 9, 5)
__licence__ = "Apache License V2.0"


Expand Down

0 comments on commit 4161972

Please sign in to comment.