|
Revision 453
(checked in by fumanchu, 5 years ago)
|
MAJOR REFACTOR: moved Arena from assumed root of storage graph to arbitrary node. Still lots of dark corners to finish migrating, but the core works. This now means users can bind Sandboxes to any store, and can mediate multiple stores at any point in the SM graph.
|
- Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 |
"""Test for sandbox-as-context-manager in Python 2.5+.""" |
|---|
| 2 |
|
|---|
| 3 |
from __future__ import with_statement |
|---|
| 4 |
|
|---|
| 5 |
import datetime |
|---|
| 6 |
import dejavu |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
def test_with_context(store): |
|---|
| 10 |
Zoo = store.class_by_name('Zoo') |
|---|
| 11 |
|
|---|
| 12 |
def commit_test(): |
|---|
| 13 |
"""Test transaction commit.""" |
|---|
| 14 |
with store.new_sandbox() as box: |
|---|
| 15 |
WAP = box.unit(Zoo, Name='Wild Animal Park') |
|---|
| 16 |
WAP.Opens = now |
|---|
| 17 |
|
|---|
| 18 |
def rollback_test(): |
|---|
| 19 |
"""Test transaction rollback on error.""" |
|---|
| 20 |
with store.new_sandbox() as box: |
|---|
| 21 |
SDZ = box.unit(Zoo, Name='San Diego Zoo') |
|---|
| 22 |
SDZ.Name = 'The One and Only San Diego Zoo' |
|---|
| 23 |
SDZ.Founded = datetime.date(2039, 9, 13) |
|---|
| 24 |
a = 3/0 |
|---|
| 25 |
|
|---|
| 26 |
now = datetime.time(5, 38, 24) |
|---|
| 27 |
commit_test() |
|---|
| 28 |
WAP = store.new_sandbox().unit(Zoo, Name='Wild Animal Park') |
|---|
| 29 |
assert WAP.Opens == now |
|---|
| 30 |
|
|---|
| 31 |
try: |
|---|
| 32 |
rollback_test() |
|---|
| 33 |
except ZeroDivisionError: |
|---|
| 34 |
pass |
|---|
| 35 |
else: |
|---|
| 36 |
raise AssertionError("ZeroDivisionError not raised.") |
|---|
| 37 |
SDZ = store.new_sandbox().unit(Zoo, Name='San Diego Zoo') |
|---|
| 38 |
assert SDZ.Name == 'San Diego Zoo' |
|---|
| 39 |
assert SDZ.Founded == datetime.date(1835, 9, 13) |
|---|
| 40 |
|
|---|