Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
418fc48e
Commit
418fc48e
authored
3 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
v2.30.3
parent
b4ed382a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+1
-1
1 addition, 1 deletion
CHANGELOG.md
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/db.py
+9
-3
9 additions, 3 deletions
satella/db.py
tests/test_db.py
+41
-16
41 additions, 16 deletions
tests/test_db.py
with
52 additions
and
21 deletions
CHANGELOG.md
+
1
−
1
View file @
418fc48e
# v2.20.
3
# v2.20.
4
This diff is collapsed.
Click to expand it.
satella/__init__.py
+
1
−
1
View file @
418fc48e
__version__
=
'
2.20.
3
'
__version__
=
'
2.20.
4a1
'
This diff is collapsed.
Click to expand it.
satella/db.py
+
9
−
3
View file @
418fc48e
...
...
@@ -41,8 +41,14 @@ class transaction:
def
__call__
(
self
,
fun
):
@wraps
(
fun
)
def
inner
(
*
args
,
**
kwargs
):
with
self
:
return
fun
(
*
args
,
**
kwargs
)
with
self
as
cur
:
if
fun
.
__name__
==
fun
.
__qualname__
:
return
fun
(
cur
,
*
args
,
**
kwargs
)
else
:
if
not
len
(
args
):
return
fun
(
*
args
)
else
:
return
fun
(
*
args
[
0
],
cur
,
*
args
[
1
:],
**
kwargs
)
return
inner
def
__enter__
(
self
):
...
...
@@ -51,7 +57,7 @@ class transaction:
@property
def
connection
(
self
):
if
inspect
.
isfunction
(
self
.
connection
):
if
inspect
.
isfunction
(
self
.
_
connection
):
return
self
.
_connection
()
else
:
return
self
.
_connection
...
...
This diff is collapsed.
Click to expand it.
tests/test_db.py
+
41
−
16
View file @
418fc48e
...
...
@@ -4,28 +4,53 @@ from unittest.mock import Mock
from
satella.db
import
transaction
class
RealConnection
:
def
__init__
(
self
):
self
.
cursor_called
=
0
self
.
commit_called
=
0
self
.
rollback_called
=
0
self
.
close_called
=
0
def
cursor
(
self
):
self
.
cursor_called
+=
1
return
Mock
()
def
commit
(
self
):
self
.
commit_called
+=
1
def
rollback
(
self
):
self
.
rollback_called
+=
1
def
close
(
self
):
self
.
close_called
+=
1
class
TestDB
(
unittest
.
TestCase
):
def
test_something
(
self
):
class
RealConnection
:
def
__init__
(
self
):
self
.
cursor_called
=
0
self
.
commit_called
=
0
self
.
rollback_called
=
0
self
.
close_called
=
0
def
test_db
(
self
):
conn
=
RealConnection
()
@transaction
(
conn
)
def
test
(
cur
):
pass
test
()
def
cursor
(
self
):
self
.
cursor_called
+=
1
return
Mock
()
self
.
assertEqual
(
conn
.
cursor_called
,
1
)
self
.
assertEqual
(
conn
.
commit_called
,
1
)
def
test_db_imba
(
self
):
conn
=
RealConnection
()
def
commit
(
self
):
self
.
commit_called
+=
1
@transaction
(
conn
)
def
test
(
cur
):
raise
ValueError
()
def
rollback
(
self
):
self
.
rollback_called
+=
1
test
()
def
close
(
self
):
self
.
close
_called
+=
1
self
.
assertEqual
(
conn
.
cursor_called
,
1
)
self
.
assertEqual
(
conn
.
rollback
_called
,
1
)
def
test_db2
(
self
):
conn
=
RealConnection
()
a
=
transaction
(
conn
)
with
a
as
cur
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment