vintasend-sqlalchemy 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vintasend_sqlalchemy-0.1.0/LICENSE.txt +21 -0
- vintasend_sqlalchemy-0.1.0/PKG-INFO +23 -0
- vintasend_sqlalchemy-0.1.0/README.md +3 -0
- vintasend_sqlalchemy-0.1.0/pyproject.toml +153 -0
- vintasend_sqlalchemy-0.1.0/vintasend_sqlalchemy/__init__.py +0 -0
- vintasend_sqlalchemy-0.1.0/vintasend_sqlalchemy/alembic_initial_migration_ops.py +34 -0
- vintasend_sqlalchemy-0.1.0/vintasend_sqlalchemy/model_factory.py +115 -0
- vintasend_sqlalchemy-0.1.0/vintasend_sqlalchemy/py.typed +0 -0
- vintasend_sqlalchemy-0.1.0/vintasend_sqlalchemy/services/__init__.py +0 -0
- vintasend_sqlalchemy-0.1.0/vintasend_sqlalchemy/services/notification_backends/__init__.py +0 -0
- vintasend_sqlalchemy-0.1.0/vintasend_sqlalchemy/services/notification_backends/sqlalchemy_notification_backend.py +771 -0
- vintasend_sqlalchemy-0.1.0/vintasend_sqlalchemy/services/tests/__init__.py +0 -0
- vintasend_sqlalchemy-0.1.0/vintasend_sqlalchemy/services/tests/test_sqlalchemy_asyncio_notification_backend.py +525 -0
- vintasend_sqlalchemy-0.1.0/vintasend_sqlalchemy/services/tests/test_sqlalchemy_notification_backend.py +412 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Vinta Serviços e Soluções Tecnológicas Ltda
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: vintasend-sqlalchemy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: SQLAlchemy backend implementation for VintaSend
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Hugo bessa
|
|
7
|
+
Author-email: hugo@vinta.com.br
|
|
8
|
+
Requires-Python: >=3.10,<3.13
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Dist: alembic (>=1.14.0,<2.0.0)
|
|
15
|
+
Requires-Dist: greenlet (>=3.1.1,<4.0.0)
|
|
16
|
+
Requires-Dist: pytest-asyncio (>=0.24.0,<0.25.0)
|
|
17
|
+
Requires-Dist: sqlalchemy (>=2.0.36,<3.0.0)
|
|
18
|
+
Requires-Dist: vintasend
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# VintaSend SQLAlchemy
|
|
22
|
+
|
|
23
|
+
SQLAlchemy implementations for VintaSend
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "vintasend-sqlalchemy"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "SQLAlchemy backend implementation for VintaSend"
|
|
5
|
+
authors = ["Hugo bessa <hugo@vinta.com.br>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
|
|
9
|
+
[tool.poetry.dependencies]
|
|
10
|
+
python = "<3.13,>=3.10"
|
|
11
|
+
sqlalchemy = "^2.0.36"
|
|
12
|
+
vintasend = "*"
|
|
13
|
+
alembic = "^1.14.0"
|
|
14
|
+
pytest-asyncio = "^0.24.0"
|
|
15
|
+
greenlet = "^3.1.1"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
[tool.poetry.group.dev.dependencies]
|
|
19
|
+
aiosqlite = "^0.20.0"
|
|
20
|
+
freezegun = "^1.5.1"
|
|
21
|
+
coverage = "^7.6.4"
|
|
22
|
+
tox = "^4.23.2"
|
|
23
|
+
pytest = "^8.3.3"
|
|
24
|
+
pytest-xdist = {version = "^3.6.1", extras=["psutil"]}
|
|
25
|
+
coveralls = "^4.0.1"
|
|
26
|
+
pytest-cov = "^6.0.0"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
[build-system]
|
|
30
|
+
requires = ["poetry-core"]
|
|
31
|
+
build-backend = "poetry.core.masonry.api"
|
|
32
|
+
|
|
33
|
+
[tool.ruff]
|
|
34
|
+
select = [
|
|
35
|
+
# pycodestyle
|
|
36
|
+
"E",
|
|
37
|
+
# Pyflakes
|
|
38
|
+
"F",
|
|
39
|
+
# pep8-naming
|
|
40
|
+
"N",
|
|
41
|
+
# pyupgrade
|
|
42
|
+
"UP",
|
|
43
|
+
# flake8-bugbear
|
|
44
|
+
"B",
|
|
45
|
+
# flake8-bandit
|
|
46
|
+
"S",
|
|
47
|
+
# flake8-blind-except
|
|
48
|
+
"BLE",
|
|
49
|
+
# flake8-builtins
|
|
50
|
+
"DJ",
|
|
51
|
+
# isort
|
|
52
|
+
"I",
|
|
53
|
+
# flake8-logging-format
|
|
54
|
+
"G",
|
|
55
|
+
# flake8-no-pep420
|
|
56
|
+
"INP",
|
|
57
|
+
# Ruff-specific rules
|
|
58
|
+
"RUF",
|
|
59
|
+
]
|
|
60
|
+
exclude = [
|
|
61
|
+
".bzr",
|
|
62
|
+
".direnv",
|
|
63
|
+
".eggs",
|
|
64
|
+
".git",
|
|
65
|
+
".git-rewrite",
|
|
66
|
+
".hg",
|
|
67
|
+
".mypy_cache",
|
|
68
|
+
".nox",
|
|
69
|
+
".pants.d",
|
|
70
|
+
".pytype",
|
|
71
|
+
".ruff_cache",
|
|
72
|
+
".svn",
|
|
73
|
+
".tox",
|
|
74
|
+
".venv",
|
|
75
|
+
"__pypackages__",
|
|
76
|
+
"_build",
|
|
77
|
+
"buck-out",
|
|
78
|
+
"build",
|
|
79
|
+
"dist",
|
|
80
|
+
"node_modules",
|
|
81
|
+
"venv",
|
|
82
|
+
"virtualenvs",
|
|
83
|
+
"*/migrations/*",
|
|
84
|
+
]
|
|
85
|
+
ignore = [
|
|
86
|
+
# Disable eradicate (commented code removal)
|
|
87
|
+
"ERA001",
|
|
88
|
+
# Disable Conflicting lint rules,
|
|
89
|
+
# see https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
|
|
90
|
+
"W191",
|
|
91
|
+
"E501",
|
|
92
|
+
"E111",
|
|
93
|
+
"E117",
|
|
94
|
+
"D206",
|
|
95
|
+
"D300",
|
|
96
|
+
"Q000",
|
|
97
|
+
"Q001",
|
|
98
|
+
"Q002",
|
|
99
|
+
"Q003",
|
|
100
|
+
"COM812",
|
|
101
|
+
"COM819",
|
|
102
|
+
"ISC001",
|
|
103
|
+
"ISC002",
|
|
104
|
+
# Allow `except Exception`:
|
|
105
|
+
"BLE001",
|
|
106
|
+
# Disable unused `noqa` directive
|
|
107
|
+
"RUF100",
|
|
108
|
+
]
|
|
109
|
+
line-length = 100
|
|
110
|
+
indent-width = 4
|
|
111
|
+
target-version = "py312"
|
|
112
|
+
# Allow unused variables when underscore-prefixed:
|
|
113
|
+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
|
114
|
+
|
|
115
|
+
[tool.ruff.pycodestyle]
|
|
116
|
+
ignore-overlong-task-comments = true
|
|
117
|
+
|
|
118
|
+
[tool.ruff.lint.isort]
|
|
119
|
+
section-order = [
|
|
120
|
+
"future",
|
|
121
|
+
"standard-library",
|
|
122
|
+
"third-party",
|
|
123
|
+
"first-party",
|
|
124
|
+
"local-folder",
|
|
125
|
+
]
|
|
126
|
+
lines-after-imports = 2
|
|
127
|
+
|
|
128
|
+
[tool.ruff.per-file-ignores]
|
|
129
|
+
# Ignore "E402", "F403", "F405" (import violations) in __init__.py files.
|
|
130
|
+
# Ignore "S" (flake8-bandit) and "N802" (function name should be lowercase) in tests and docs.
|
|
131
|
+
# Ignore "RUF" (Ruff-specific rules) and "I" (isort) in migrations.
|
|
132
|
+
"__init__.py" = ["E402", "F403", "F405"]
|
|
133
|
+
"**/{tests,docs}/*" = ["E402", "F403", "F405", "S", "N802"]
|
|
134
|
+
"**/*test*.py" = ["E402", "F403", "F405", "S", "N802"]
|
|
135
|
+
"**/{settings}/*" = ["E402", "F403", "F405"]
|
|
136
|
+
"**/migrations/*" = ["RUF", "I"]
|
|
137
|
+
|
|
138
|
+
[tool.coverage.run]
|
|
139
|
+
branch = true
|
|
140
|
+
source = ["backend"]
|
|
141
|
+
omit = [
|
|
142
|
+
"**/venv/*",
|
|
143
|
+
"**/env/*",
|
|
144
|
+
"**/virtualenvs/*",
|
|
145
|
+
"**/node_modules/*",
|
|
146
|
+
"**/migrations/*",
|
|
147
|
+
"**/settings/*",
|
|
148
|
+
"**/tests/*",
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
[tool.pytest.ini_options]
|
|
152
|
+
python_files = ["test_*.py"]
|
|
153
|
+
addopts = "--dist=loadscope"
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
|
|
3
|
+
import sqlalchemy as sa
|
|
4
|
+
from alembic import op
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def create_notification_table(user_id_type: type):
|
|
8
|
+
return op.create_table('notifications',
|
|
9
|
+
sa.Column("id", sa.BigInteger().with_variant(sa.Integer, "sqlite"), primary_key=True),
|
|
10
|
+
sa.Column('notification_type', sa.String(50), nullable=False),
|
|
11
|
+
sa.Column('title', sa.String(255), nullable=False),
|
|
12
|
+
sa.Column('status', sa.String(50), nullable=False, default="PENDING_SEND"),
|
|
13
|
+
sa.Column('body_template', sa.String(255), nullable=False),
|
|
14
|
+
sa.Column(
|
|
15
|
+
'created', sa.DateTime, default=lambda: datetime.datetime.now(datetime.timezone.utc)
|
|
16
|
+
),
|
|
17
|
+
sa.Column(
|
|
18
|
+
'updated',
|
|
19
|
+
sa.DateTime,
|
|
20
|
+
default=lambda: datetime.datetime.now(datetime.timezone.utc),
|
|
21
|
+
onupdate=lambda: datetime.datetime.now(datetime.timezone.utc),
|
|
22
|
+
),
|
|
23
|
+
sa.Column('subject_template', sa.String(255), nullable=True, default=""),
|
|
24
|
+
sa.Column('preheader_template', sa.String(255), nullable=True, default=""),
|
|
25
|
+
sa.Column('context_name', sa.String(255), nullable=True, default=""),
|
|
26
|
+
sa.Column('context_kwargs', sa.JSON, default=dict),
|
|
27
|
+
sa.Column('context_used', sa.JSON, nullable=True),
|
|
28
|
+
sa.Column('adapter_used', sa.String(255), nullable=True),
|
|
29
|
+
sa.Column('adapter_extra_parameters', sa.JSON, nullable=True),
|
|
30
|
+
sa.Column('send_after', sa.DateTime(), nullable=True),
|
|
31
|
+
sa.Column('user_id', user_id_type(), nullable=False),
|
|
32
|
+
sa.PrimaryKeyConstraint('id'),
|
|
33
|
+
sa.ForeignKeyConstraint(['user_id'], ['users.id'])
|
|
34
|
+
)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import uuid
|
|
3
|
+
from typing import Any, Generic, TypeVar
|
|
4
|
+
|
|
5
|
+
from sqlalchemy import JSON, BigInteger, DateTime, ForeignKey, Integer, String, null
|
|
6
|
+
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
|
7
|
+
from sqlalchemy.orm.decl_api import DeclarativeAttributeIntercept
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Base(DeclarativeBase):
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class NotificationMixin(Base):
|
|
15
|
+
__abstract__ = True
|
|
16
|
+
id: Mapped[int] = mapped_column("id", BigInteger().with_variant(Integer, "sqlite"), primary_key=True) # noqa: A003
|
|
17
|
+
notification_type: Mapped[str] = mapped_column("notification_type", String(50), nullable=False)
|
|
18
|
+
title: Mapped[str] = mapped_column("title", String(255), nullable=False)
|
|
19
|
+
status: Mapped[str] = mapped_column("status", String(50), nullable=False, default="PENDING_SEND")
|
|
20
|
+
body_template: Mapped[str] = mapped_column("body_template", String(255), nullable=False)
|
|
21
|
+
created: Mapped[datetime.datetime] = mapped_column(
|
|
22
|
+
"created", DateTime, default=lambda: datetime.datetime.now(datetime.timezone.utc)
|
|
23
|
+
)
|
|
24
|
+
updated: Mapped[datetime.datetime] = mapped_column(
|
|
25
|
+
"updated",
|
|
26
|
+
DateTime,
|
|
27
|
+
default=lambda: datetime.datetime.now(datetime.timezone.utc),
|
|
28
|
+
onupdate=lambda: datetime.datetime.now(datetime.timezone.utc),
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
# Email specific fields
|
|
32
|
+
subject_template: Mapped[str] = mapped_column("subject_template", String(255), nullable=True, default="")
|
|
33
|
+
preheader_template: Mapped[str] = mapped_column("preheader_template", String(255), nullable=True, default="")
|
|
34
|
+
context_name: Mapped[str] = mapped_column("context_name", String(255), nullable=True, default="")
|
|
35
|
+
context_kwargs: Mapped[dict] = mapped_column("context_kwargs", JSON, default=dict)
|
|
36
|
+
adapter_used: Mapped[str] = mapped_column("adapter_used", String(255), nullable=True)
|
|
37
|
+
context_used: Mapped[dict | None] = mapped_column("context_used", JSON, nullable=True)
|
|
38
|
+
adapter_extra_parameters: Mapped[dict | None] = mapped_column("adapter_extra_parameters", JSON, nullable=True)
|
|
39
|
+
|
|
40
|
+
send_after = mapped_column("send_after", DateTime, nullable=True)
|
|
41
|
+
|
|
42
|
+
def __str__(self):
|
|
43
|
+
return f"{self.get_user()} - {self.notification_type} - {self.title} - {self.status}{f' (scheduled to {self.send_after})' if self.send_after else ''}"
|
|
44
|
+
|
|
45
|
+
def get_user(self) -> Any:
|
|
46
|
+
raise NotImplementedError
|
|
47
|
+
|
|
48
|
+
def get_user_id(self) -> Any:
|
|
49
|
+
raise NotImplementedError
|
|
50
|
+
|
|
51
|
+
def get_user_email(self) -> str:
|
|
52
|
+
raise NotImplementedError
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def get_user_id_attr_name() -> str:
|
|
56
|
+
raise NotImplementedError
|
|
57
|
+
|
|
58
|
+
@staticmethod
|
|
59
|
+
def get_user_attr_name() -> str:
|
|
60
|
+
raise NotImplementedError
|
|
61
|
+
|
|
62
|
+
def set_user_id(self, user_id: Any):
|
|
63
|
+
raise NotImplementedError
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
UserType = TypeVar('UserType', bound=DeclarativeBase)
|
|
67
|
+
UserPrimaryKeyType = TypeVar('UserPrimaryKeyType', int, str, uuid.UUID)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class NotificationMeta(DeclarativeAttributeIntercept):
|
|
71
|
+
def __new__(cls, name, bases, dct, user_model, user_primary_key_field_name, user_primary_key_field_type):
|
|
72
|
+
if user_primary_key_field_type == int:
|
|
73
|
+
dct['user_id'] = mapped_column(ForeignKey(getattr(user_model, user_primary_key_field_name)))
|
|
74
|
+
dct['set_user_id'] = lambda self, user_id: setattr(self, 'user_id', user_id)
|
|
75
|
+
elif user_primary_key_field_type == str:
|
|
76
|
+
dct['user_id'] = mapped_column(ForeignKey(getattr(user_model, user_primary_key_field_name)))
|
|
77
|
+
dct['set_user_id'] = lambda self, user_id: setattr(self, 'user_id', user_id)
|
|
78
|
+
elif user_primary_key_field_type == uuid.UUID:
|
|
79
|
+
dct['user_id'] = mapped_column(ForeignKey(getattr(user_model, user_primary_key_field_name)))
|
|
80
|
+
dct['set_user_id'] = lambda self, user_id: setattr(self, 'user_id', user_id)
|
|
81
|
+
|
|
82
|
+
dct['user'] = relationship(user_model, backref="notifications")
|
|
83
|
+
dct['get_user_id'] = lambda self: self.user_id
|
|
84
|
+
dct['get_user'] = lambda self: self.user
|
|
85
|
+
dct['__tablename__'] = "notifications"
|
|
86
|
+
dct['__tableargs__'] = {"extend_existing": True}
|
|
87
|
+
|
|
88
|
+
return super().__new__(cls, name, bases, dct)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class GenericNotification(
|
|
92
|
+
NotificationMixin,
|
|
93
|
+
Generic[UserType, UserPrimaryKeyType],
|
|
94
|
+
):
|
|
95
|
+
__abstract__ = True
|
|
96
|
+
|
|
97
|
+
user: Mapped[UserType]
|
|
98
|
+
user_id: Mapped[UserPrimaryKeyType]
|
|
99
|
+
|
|
100
|
+
def get_user_id(self) -> UserPrimaryKeyType:
|
|
101
|
+
raise NotImplementedError
|
|
102
|
+
|
|
103
|
+
def set_user_id(self, user_id: UserPrimaryKeyType) -> None:
|
|
104
|
+
raise NotImplementedError
|
|
105
|
+
|
|
106
|
+
def get_user(self) -> UserType:
|
|
107
|
+
raise NotImplementedError
|
|
108
|
+
|
|
109
|
+
@staticmethod
|
|
110
|
+
def get_user_id_attr_name() -> str:
|
|
111
|
+
return "user_id"
|
|
112
|
+
|
|
113
|
+
@staticmethod
|
|
114
|
+
def get_user_attr_name() -> str:
|
|
115
|
+
return "user"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|