Compare commits

...

12 commits

Author SHA1 Message Date
0e25cca0ba fix: refactor some more for tests + pylint 2025-08-31 18:39:43 -05:00
b89684cfc0 docs: add badge for black code style 2025-08-31 13:29:33 -05:00
1b01df79e2 fix: format all code with black
and from now on should not deviate from that...
2025-08-31 12:45:58 -05:00
e20ef31ff7 docs: update intersphinx doc links per server migration 2025-02-18 12:13:48 -06:00
39dc66df40 bump: version 0.1.1 → 0.2.0 2024-12-07 23:48:31 -06:00
6baca8c6b1 feat: convert all uuid fields from str to proper UUID
ugh had to rewrite alembic migrations instead of just adding a new
one..  will be good to be past this hiccup
2024-12-07 23:48:16 -06:00
bec16f4de2 docs: update author, url info 2024-12-05 08:38:09 -06:00
77d1b58160 docs: fix project description 2024-12-05 08:37:55 -06:00
Lance Edgar
94a554ebc9 fix: add User.prevent_edit to schema 2024-11-24 17:40:42 -06:00
Lance Edgar
2a6dbfacd3 bump: version 0.1.0 → 0.1.1 2024-08-27 21:23:18 -05:00
Lance Edgar
7dd4eb587b fix: fix nullable flags for initial version tables
hm gonna have to get to the bottom of this
2024-08-27 21:22:54 -05:00
Lance Edgar
8e78cd3253 build: add release task 2024-08-27 19:25:58 -05:00
16 changed files with 416 additions and 155 deletions

4
.pylintrc Normal file
View file

@ -0,0 +1,4 @@
# -*- mode: conf; -*-
[MESSAGES CONTROL]
disable=fixme

View file

@ -5,6 +5,22 @@ All notable changes to Wutta-Continuum will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## v0.2.0 (2024-12-07)
### Feat
- convert all uuid fields from str to proper UUID
### Fix
- add `User.prevent_edit` to schema
## v0.1.1 (2024-08-27)
### Fix
- fix nullable flags for initial version tables
## v0.1.0 (2024-08-27)
### Feat

View file

@ -1,6 +1,6 @@
# Wutta-Continuum
SQLAlchemy-Continuum versioning for WuttJamaican
SQLAlchemy-Continuum versioning for Wutta Framework
See docs at https://rattailproject.org/docs/wutta-continuum/

View file

@ -8,32 +8,35 @@
from importlib.metadata import version as get_version
project = 'Wutta-Continuum'
copyright = '2024, Lance Edgar'
author = 'Lance Edgar'
release = get_version('Wutta-Continuum')
project = "Wutta-Continuum"
copyright = "2024, Lance Edgar"
author = "Lance Edgar"
release = get_version("Wutta-Continuum")
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
'sphinx.ext.todo',
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
"sphinx.ext.todo",
]
templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
intersphinx_mapping = {
'sqlalchemy-continuum': ('https://sqlalchemy-continuum.readthedocs.io/en/latest/', None),
'wuttjamaican': ('https://rattailproject.org/docs/wuttjamaican/', None),
"sqlalchemy-continuum": (
"https://sqlalchemy-continuum.readthedocs.io/en/latest/",
None,
),
"wuttjamaican": ("https://docs.wuttaproject.org/wuttjamaican/", None),
}
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = 'furo'
html_static_path = ['_static']
html_theme = "furo"
html_static_path = ["_static"]

View file

@ -9,6 +9,12 @@ This package adds data versioning/history for `WuttJamaican`_, using
.. _SQLAlchemy-Continuum: https://sqlalchemy-continuum.readthedocs.io/en/latest/
.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen
:target: https://github.com/pylint-dev/pylint
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
.. toctree::
:maxdepth: 2

View file

@ -6,10 +6,10 @@ build-backend = "hatchling.build"
[project]
name = "Wutta-Continuum"
version = "0.1.0"
description = "SQLAlchemy-Continuum versioning for WuttJamaican"
version = "0.2.0"
description = "SQLAlchemy-Continuum versioning for Wutta Framework"
readme = "README.md"
authors = [{name = "Lance Edgar", email = "lance@edbob.org"}]
authors = [{name = "Lance Edgar", email = "lance@wuttaproject.org"}]
license = {text = "GNU GPL v3+"}
classifiers = [
"Development Status :: 4 - Beta",
@ -27,13 +27,13 @@ classifiers = [
requires-python = ">= 3.8"
dependencies = [
"SQLAlchemy-Continuum",
"WuttJamaican[db]",
"WuttJamaican[db]>=0.17.0",
]
[project.optional-dependencies]
docs = ["Sphinx", "furo"]
tests = ["pytest-cov", "tox"]
tests = ["pylint", "pytest", "pytest-cov", "tox"]
[project.entry-points."wutta.app.providers"]
@ -47,6 +47,7 @@ wutta_continuum = "wutta_continuum.conf:WuttaContinuumConfigExtension"
[project.urls]
Homepage = "https://wuttaproject.org/"
Repository = "https://forgejo.wuttaproject.org/wutta/wutta-continuum"
Issues = "https://forgejo.wuttaproject.org/wutta/wutta-continuum/issues"
Changelog = "https://forgejo.wuttaproject.org/wutta/wutta-continuum/src/branch/master/CHANGELOG.md"

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Wutta-Continuum -- SQLAlchemy Versioning for WuttJamaican
# Wutta-Continuum -- SQLAlchemy Versioning for Wutta Framework
# Copyright © 2024 Lance Edgar
#
# This file is part of Wutta Framework.
@ -21,7 +21,7 @@
#
################################################################################
"""
Wutta-Continuum -- SQLAlchemy-Continuum versioning for WuttJamaican
Wutta-Continuum -- SQLAlchemy-Continuum versioning for Wutta Framework
"""
from ._version import __version__

View file

@ -1,6 +1,9 @@
# -*- coding: utf-8; -*-
"""
Package Version
"""
from importlib.metadata import version
__version__ = version('Wutta-Continuum')
__version__ = version("Wutta-Continuum")

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Wutta-Continuum -- SQLAlchemy Versioning for WuttJamaican
# Wutta-Continuum -- SQLAlchemy Versioning for Wutta Framework
# Copyright © 2024 Lance Edgar
#
# This file is part of Wutta Framework.
@ -40,5 +40,6 @@ class WuttaContinuumAppProvider(AppProvider):
This checks the config value as described in
:doc:`/narr/install`; default will be ``False``.
"""
return self.config.get_bool('wutta_continuum.enable_versioning',
usedb=False, default=False)
return self.config.get_bool(
"wutta_continuum.enable_versioning", usedb=False, default=False
)

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Wutta-Continuum -- SQLAlchemy Versioning for WuttJamaican
# Copyright © 2024 Lance Edgar
# Wutta-Continuum -- SQLAlchemy Versioning for Wutta Framework
# Copyright © 2024-2025 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -24,7 +24,6 @@
App Configuration
"""
import datetime
import socket
from sqlalchemy.orm import configure_mappers
@ -42,27 +41,31 @@ class WuttaContinuumConfigExtension(WuttaConfigExtension):
This adds a startup hook, which can optionally turn on the
SQLAlchemy-Continuum versioning features for the main app DB.
"""
key = 'wutta_continuum'
def startup(self, config):
key = "wutta_continuum"
def startup(self, config): # pylint: disable=empty-docstring
""" """
# only do this if config enables it
if not config.get_bool('wutta_continuum.enable_versioning',
usedb=False, default=False):
if not config.get_bool(
"wutta_continuum.enable_versioning", usedb=False, default=False
):
return
# create wutta plugin, to assign user and ip address
spec = config.get('wutta_continuum.wutta_plugin_spec',
usedb=False,
default='wutta_continuum.conf:WuttaContinuumPlugin')
WuttaPlugin = load_object(spec)
spec = config.get(
"wutta_continuum.wutta_plugin_spec",
usedb=False,
default="wutta_continuum.conf:WuttaContinuumPlugin",
)
plugin = load_object(spec)
# tell sqlalchemy-continuum to do its thing
make_versioned(plugins=[WuttaPlugin()])
make_versioned(plugins=[plugin()])
# nb. must load the model before configuring mappers
app = config.get_app()
model = app.model
model = app.model # pylint: disable=unused-variable
# tell sqlalchemy to do its thing
configure_mappers()
@ -95,24 +98,29 @@ class WuttaContinuumPlugin(Plugin):
:doc:`sqlalchemy-continuum:plugins`.
"""
def get_remote_addr(self, uow, session):
def get_remote_addr( # pylint: disable=empty-docstring,unused-argument
self, uow, session
):
""" """
host = socket.gethostname()
return socket.gethostbyname(host)
def get_user_id(self, uow, session):
def get_user_id( # pylint: disable=empty-docstring,unused-argument
self, uow, session
):
""" """
return None
def transaction_args(self, uow, session):
def transaction_args(self, uow, session): # pylint: disable=empty-docstring
""" """
kwargs = {}
remote_addr = self.get_remote_addr(uow, session)
if remote_addr:
kwargs['remote_addr'] = remote_addr
kwargs["remote_addr"] = remote_addr
user_id = self.get_user_id(uow, session)
user_id = self.get_user_id(uow, session) # pylint: disable=assignment-from-none
if user_id:
kwargs['user_id'] = user_id
kwargs["user_id"] = user_id
return kwargs

View file

@ -0,0 +1,34 @@
"""add user.prevent_edit
Revision ID: 0a5f8ac0cd06
Revises: 71406251b8e7
Create Date: 2024-11-24 17:39:57.415425
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = "0a5f8ac0cd06"
down_revision: Union[str, None] = "71406251b8e7"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# user
op.add_column(
"user_version",
sa.Column("prevent_edit", sa.Boolean(), autoincrement=False, nullable=True),
)
def downgrade() -> None:
# user
op.drop_column("user_version", "prevent_edit")

View file

@ -1,142 +1,296 @@
"""first versioning tables
Revision ID: 71406251b8e7
Revises:
Revises:
Create Date: 2024-08-27 18:28:31.488291
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import wuttjamaican.db.util
# revision identifiers, used by Alembic.
revision: str = '71406251b8e7'
revision: str = "71406251b8e7"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = ('wutta_continuum',)
branch_labels: Union[str, Sequence[str], None] = ("wutta_continuum",)
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# transaction
op.create_table('transaction',
sa.Column('issued_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
sa.Column('remote_addr', sa.String(length=50), nullable=True),
sa.Column('user_id', sa.String(length=32), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['user.uuid'], name=op.f('fk_transaction_user_id_user')),
sa.PrimaryKeyConstraint('id', name=op.f('pk_transaction'))
)
op.create_index(op.f('ix_transaction_user_id'), 'transaction', ['user_id'], unique=False)
op.create_table(
"transaction",
sa.Column("issued_at", sa.DateTime(), nullable=True),
sa.Column("id", sa.BigInteger(), autoincrement=True, nullable=False),
sa.Column("remote_addr", sa.String(length=50), nullable=True),
sa.Column("user_id", wuttjamaican.db.util.UUID(), nullable=True),
sa.ForeignKeyConstraint(
["user_id"], ["user.uuid"], name=op.f("fk_transaction_user_id_user")
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_transaction")),
)
op.create_index(
op.f("ix_transaction_user_id"), "transaction", ["user_id"], unique=False
)
# person
op.create_table('person_version',
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
sa.Column('full_name', sa.String(length=100), autoincrement=False, nullable=False),
sa.Column('first_name', sa.String(length=50), autoincrement=False, nullable=True),
sa.Column('middle_name', sa.String(length=50), autoincrement=False, nullable=True),
sa.Column('last_name', sa.String(length=50), autoincrement=False, nullable=True),
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('uuid', 'transaction_id', name=op.f('pk_person_version'))
)
op.create_index(op.f('ix_person_version_end_transaction_id'), 'person_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_person_version_operation_type'), 'person_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_person_version_transaction_id'), 'person_version', ['transaction_id'], unique=False)
op.create_table(
"person_version",
sa.Column(
"uuid", wuttjamaican.db.util.UUID(), autoincrement=False, nullable=False
),
sa.Column(
"full_name", sa.String(length=100), autoincrement=False, nullable=True
),
sa.Column(
"first_name", sa.String(length=50), autoincrement=False, nullable=True
),
sa.Column(
"middle_name", sa.String(length=50), autoincrement=False, nullable=True
),
sa.Column(
"last_name", sa.String(length=50), autoincrement=False, nullable=True
),
sa.Column(
"transaction_id", sa.BigInteger(), autoincrement=False, nullable=False
),
sa.Column("end_transaction_id", sa.BigInteger(), nullable=True),
sa.Column("operation_type", sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint(
"uuid", "transaction_id", name=op.f("pk_person_version")
),
)
op.create_index(
op.f("ix_person_version_end_transaction_id"),
"person_version",
["end_transaction_id"],
unique=False,
)
op.create_index(
op.f("ix_person_version_operation_type"),
"person_version",
["operation_type"],
unique=False,
)
op.create_index(
op.f("ix_person_version_transaction_id"),
"person_version",
["transaction_id"],
unique=False,
)
# user
op.create_table('user_version',
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
sa.Column('username', sa.String(length=25), autoincrement=False, nullable=False),
sa.Column('password', sa.String(length=60), autoincrement=False, nullable=True),
sa.Column('person_uuid', sa.String(length=32), autoincrement=False, nullable=True),
sa.Column('active', sa.Boolean(), autoincrement=False, nullable=False),
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('uuid', 'transaction_id', name=op.f('pk_user_version'))
)
op.create_index(op.f('ix_user_version_end_transaction_id'), 'user_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_user_version_operation_type'), 'user_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_user_version_transaction_id'), 'user_version', ['transaction_id'], unique=False)
op.create_table(
"user_version",
sa.Column(
"uuid", wuttjamaican.db.util.UUID(), autoincrement=False, nullable=False
),
sa.Column("username", sa.String(length=25), autoincrement=False, nullable=True),
sa.Column("password", sa.String(length=60), autoincrement=False, nullable=True),
sa.Column(
"person_uuid",
wuttjamaican.db.util.UUID(),
autoincrement=False,
nullable=True,
),
sa.Column("active", sa.Boolean(), autoincrement=False, nullable=True),
sa.Column(
"transaction_id", sa.BigInteger(), autoincrement=False, nullable=False
),
sa.Column("end_transaction_id", sa.BigInteger(), nullable=True),
sa.Column("operation_type", sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint("uuid", "transaction_id", name=op.f("pk_user_version")),
)
op.create_index(
op.f("ix_user_version_end_transaction_id"),
"user_version",
["end_transaction_id"],
unique=False,
)
op.create_index(
op.f("ix_user_version_operation_type"),
"user_version",
["operation_type"],
unique=False,
)
op.create_index(
op.f("ix_user_version_transaction_id"),
"user_version",
["transaction_id"],
unique=False,
)
# role
op.create_table('role_version',
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
sa.Column('name', sa.String(length=100), autoincrement=False, nullable=False),
sa.Column('notes', sa.Text(), autoincrement=False, nullable=True),
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('uuid', 'transaction_id', name=op.f('pk_role_version'))
)
op.create_index(op.f('ix_role_version_end_transaction_id'), 'role_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_role_version_operation_type'), 'role_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_role_version_transaction_id'), 'role_version', ['transaction_id'], unique=False)
op.create_table(
"role_version",
sa.Column(
"uuid", wuttjamaican.db.util.UUID(), autoincrement=False, nullable=False
),
sa.Column("name", sa.String(length=100), autoincrement=False, nullable=True),
sa.Column("notes", sa.Text(), autoincrement=False, nullable=True),
sa.Column(
"transaction_id", sa.BigInteger(), autoincrement=False, nullable=False
),
sa.Column("end_transaction_id", sa.BigInteger(), nullable=True),
sa.Column("operation_type", sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint("uuid", "transaction_id", name=op.f("pk_role_version")),
)
op.create_index(
op.f("ix_role_version_end_transaction_id"),
"role_version",
["end_transaction_id"],
unique=False,
)
op.create_index(
op.f("ix_role_version_operation_type"),
"role_version",
["operation_type"],
unique=False,
)
op.create_index(
op.f("ix_role_version_transaction_id"),
"role_version",
["transaction_id"],
unique=False,
)
# user_x_role
op.create_table('user_x_role_version',
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
sa.Column('user_uuid', sa.String(length=32), autoincrement=False, nullable=False),
sa.Column('role_uuid', sa.String(length=32), autoincrement=False, nullable=False),
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('uuid', 'transaction_id', name=op.f('pk_user_x_role_version'))
)
op.create_index(op.f('ix_user_x_role_version_end_transaction_id'), 'user_x_role_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_user_x_role_version_operation_type'), 'user_x_role_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_user_x_role_version_transaction_id'), 'user_x_role_version', ['transaction_id'], unique=False)
op.create_table(
"user_x_role_version",
sa.Column(
"uuid", wuttjamaican.db.util.UUID(), autoincrement=False, nullable=False
),
sa.Column(
"user_uuid", wuttjamaican.db.util.UUID(), autoincrement=False, nullable=True
),
sa.Column(
"role_uuid", wuttjamaican.db.util.UUID(), autoincrement=False, nullable=True
),
sa.Column(
"transaction_id", sa.BigInteger(), autoincrement=False, nullable=False
),
sa.Column("end_transaction_id", sa.BigInteger(), nullable=True),
sa.Column("operation_type", sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint(
"uuid", "transaction_id", name=op.f("pk_user_x_role_version")
),
)
op.create_index(
op.f("ix_user_x_role_version_end_transaction_id"),
"user_x_role_version",
["end_transaction_id"],
unique=False,
)
op.create_index(
op.f("ix_user_x_role_version_operation_type"),
"user_x_role_version",
["operation_type"],
unique=False,
)
op.create_index(
op.f("ix_user_x_role_version_transaction_id"),
"user_x_role_version",
["transaction_id"],
unique=False,
)
# permission
op.create_table('permission_version',
sa.Column('role_uuid', sa.String(length=32), autoincrement=False, nullable=False),
sa.Column('permission', sa.String(length=254), autoincrement=False, nullable=False),
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('role_uuid', 'permission', 'transaction_id', name=op.f('pk_permission_version'))
)
op.create_index(op.f('ix_permission_version_end_transaction_id'), 'permission_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_permission_version_operation_type'), 'permission_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_permission_version_transaction_id'), 'permission_version', ['transaction_id'], unique=False)
op.create_table(
"permission_version",
sa.Column(
"role_uuid",
wuttjamaican.db.util.UUID(),
autoincrement=False,
nullable=False,
),
sa.Column(
"permission", sa.String(length=254), autoincrement=False, nullable=False
),
sa.Column(
"transaction_id", sa.BigInteger(), autoincrement=False, nullable=False
),
sa.Column("end_transaction_id", sa.BigInteger(), nullable=True),
sa.Column("operation_type", sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint(
"role_uuid",
"permission",
"transaction_id",
name=op.f("pk_permission_version"),
),
)
op.create_index(
op.f("ix_permission_version_end_transaction_id"),
"permission_version",
["end_transaction_id"],
unique=False,
)
op.create_index(
op.f("ix_permission_version_operation_type"),
"permission_version",
["operation_type"],
unique=False,
)
op.create_index(
op.f("ix_permission_version_transaction_id"),
"permission_version",
["transaction_id"],
unique=False,
)
def downgrade() -> None:
# permission
op.drop_index(op.f('ix_permission_version_transaction_id'), table_name='permission_version')
op.drop_index(op.f('ix_permission_version_operation_type'), table_name='permission_version')
op.drop_index(op.f('ix_permission_version_end_transaction_id'), table_name='permission_version')
op.drop_table('permission_version')
op.drop_index(
op.f("ix_permission_version_transaction_id"), table_name="permission_version"
)
op.drop_index(
op.f("ix_permission_version_operation_type"), table_name="permission_version"
)
op.drop_index(
op.f("ix_permission_version_end_transaction_id"),
table_name="permission_version",
)
op.drop_table("permission_version")
# user_x_role
op.drop_index(op.f('ix_user_x_role_version_transaction_id'), table_name='user_x_role_version')
op.drop_index(op.f('ix_user_x_role_version_operation_type'), table_name='user_x_role_version')
op.drop_index(op.f('ix_user_x_role_version_end_transaction_id'), table_name='user_x_role_version')
op.drop_table('user_x_role_version')
op.drop_index(
op.f("ix_user_x_role_version_transaction_id"), table_name="user_x_role_version"
)
op.drop_index(
op.f("ix_user_x_role_version_operation_type"), table_name="user_x_role_version"
)
op.drop_index(
op.f("ix_user_x_role_version_end_transaction_id"),
table_name="user_x_role_version",
)
op.drop_table("user_x_role_version")
# role
op.drop_index(op.f('ix_role_version_transaction_id'), table_name='role_version')
op.drop_index(op.f('ix_role_version_operation_type'), table_name='role_version')
op.drop_index(op.f('ix_role_version_end_transaction_id'), table_name='role_version')
op.drop_table('role_version')
op.drop_index(op.f("ix_role_version_transaction_id"), table_name="role_version")
op.drop_index(op.f("ix_role_version_operation_type"), table_name="role_version")
op.drop_index(op.f("ix_role_version_end_transaction_id"), table_name="role_version")
op.drop_table("role_version")
# user
op.drop_index(op.f('ix_user_version_transaction_id'), table_name='user_version')
op.drop_index(op.f('ix_user_version_operation_type'), table_name='user_version')
op.drop_index(op.f('ix_user_version_end_transaction_id'), table_name='user_version')
op.drop_table('user_version')
op.drop_index(op.f("ix_user_version_transaction_id"), table_name="user_version")
op.drop_index(op.f("ix_user_version_operation_type"), table_name="user_version")
op.drop_index(op.f("ix_user_version_end_transaction_id"), table_name="user_version")
op.drop_table("user_version")
# person
op.drop_index(op.f('ix_person_version_transaction_id'), table_name='person_version')
op.drop_index(op.f('ix_person_version_operation_type'), table_name='person_version')
op.drop_index(op.f('ix_person_version_end_transaction_id'), table_name='person_version')
op.drop_table('person_version')
op.drop_index(op.f("ix_person_version_transaction_id"), table_name="person_version")
op.drop_index(op.f("ix_person_version_operation_type"), table_name="person_version")
op.drop_index(
op.f("ix_person_version_end_transaction_id"), table_name="person_version"
)
op.drop_table("person_version")
# transaction
op.drop_index(op.f('ix_transaction_user_id'), table_name='transaction')
op.drop_table('transaction')
op.drop_index(op.f("ix_transaction_user_id"), table_name="transaction")
op.drop_table("transaction")

24
tasks.py Normal file
View file

@ -0,0 +1,24 @@
# -*- coding: utf-8; -*-
"""
Tasks for Wutta-Continuum
"""
import os
import shutil
from invoke import task
@task
def release(c, skip_tests=False):
"""
Release a new version of Wutta-Continuum
"""
if not skip_tests:
c.run("pytest")
if os.path.exists("dist"):
shutil.rmtree("dist")
c.run("python -m build --sdist")
c.run("twine upload dist/*")

View file

@ -17,5 +17,5 @@ class TestWuttaContinuumAppProvider(DataTestCase):
self.assertFalse(provider.continuum_is_enabled())
# but can be turned on
self.config.setdefault('wutta_continuum.enable_versioning', 'true')
self.config.setdefault("wutta_continuum.enable_versioning", "true")
self.assertTrue(provider.continuum_is_enabled())

View file

@ -17,8 +17,8 @@ class TestWuttaContinuumConfigExtension(DataTestCase):
def test_startup(self):
ext = self.make_extension()
with patch.object(mod, 'make_versioned') as make_versioned:
with patch.object(mod, 'configure_mappers') as configure_mappers:
with patch.object(mod, "make_versioned") as make_versioned:
with patch.object(mod, "configure_mappers") as configure_mappers:
# nothing happens by default
ext.startup(self.config)
@ -26,7 +26,7 @@ class TestWuttaContinuumConfigExtension(DataTestCase):
configure_mappers.assert_not_called()
# but will if we enable it in config
self.config.setdefault('wutta_continuum.enable_versioning', 'true')
self.config.setdefault("wutta_continuum.enable_versioning", "true")
ext.startup(self.config)
make_versioned.assert_called_once()
configure_mappers.assert_called_once_with()
@ -39,8 +39,8 @@ class TestWuttaContinuumPlugin(DataTestCase):
def test_remote_addr(self):
plugin = self.make_plugin()
with patch.object(socket, 'gethostbyname', return_value='127.0.0.1'):
self.assertEqual(plugin.get_remote_addr(None, self.session), '127.0.0.1')
with patch.object(socket, "gethostbyname", return_value="127.0.0.1"):
self.assertEqual(plugin.get_remote_addr(None, self.session), "127.0.0.1")
def test_user_id(self):
plugin = self.make_plugin()
@ -48,11 +48,14 @@ class TestWuttaContinuumPlugin(DataTestCase):
def test_transaction_args(self):
plugin = self.make_plugin()
with patch.object(socket, 'gethostbyname', return_value='127.0.0.1'):
self.assertEqual(plugin.transaction_args(None, self.session),
{'remote_addr': '127.0.0.1'})
with patch.object(socket, "gethostbyname", return_value="127.0.0.1"):
self.assertEqual(
plugin.transaction_args(None, self.session),
{"remote_addr": "127.0.0.1"},
)
with patch.object(plugin, 'get_user_id', return_value='some-random-uuid'):
self.assertEqual(plugin.transaction_args(None, self.session),
{'remote_addr': '127.0.0.1',
'user_id': 'some-random-uuid'})
with patch.object(plugin, "get_user_id", return_value="some-random-uuid"):
self.assertEqual(
plugin.transaction_args(None, self.session),
{"remote_addr": "127.0.0.1", "user_id": "some-random-uuid"},
)

View file

@ -6,6 +6,10 @@ envlist = py38, py39, py310, py311
extras = tests
commands = pytest {posargs}
[testenv:pylint]
basepython = python3.11
commands = pylint wutta_continuum
[testenv:coverage]
basepython = python3.11
commands = pytest --cov=wutta_continuum --cov-report=html --cov-fail-under=100