コード例 #1
0
ファイル: TestEmpty2.py プロジェクト: Cito/w4py-olde-docs
def test(store):
    """Bug report from Stefan Karlsson <*****@*****.**> on Dec 3 2001.

    Obj refs can be incorrectly stored to the database as zeroes for newly created objects.

    """

    from Bar import Bar
    from Foo import Foo
    from BarReq import BarReq

    # Since we're the second empty test, double check that the db is really empty
    assert len(store.fetchObjectsOfClass(Bar)) == 0
    assert len(store.fetchObjectsOfClass(Foo)) == 0

    bar = Bar()
    foo = Foo()
    store.addObject(bar)
    store.addObject(foo)
    bar.setFoo(foo)

    store.saveChanges()

    bars = store.fetchObjectsOfClass(Bar)
    assert len(bars) == 1
    bar2 = bars[0]
    assert bar2 is bar
    assert bar.foo() is not None # the sign of the bug in question
    assert bar.foo() is foo # what we should expect

    store.clear()
    bar = store.fetchObjectsOfClass(Bar)[0]
    assert bar.foo() is not None
コード例 #2
0
ファイル: TestEmpty2.py プロジェクト: techeye220/w4py
def test(store):
    """Bug report from Stefan Karlsson <*****@*****.**> on Dec 3 2001.

    Obj refs can be incorrectly stored to the database as zeroes for newly created objects.
    """

    from Bar import Bar
    from Foo import Foo
    from BarReq import BarReq

    # Since we're the second empty test, double check that the db is really empty
    assert len(store.fetchObjectsOfClass(Bar)) == 0
    assert len(store.fetchObjectsOfClass(Foo)) == 0

    bar = Bar()
    foo = Foo()
    store.addObject(bar)
    store.addObject(foo)
    bar.setFoo(foo)

    store.saveChanges()

    bars = store.fetchObjectsOfClass(Bar)
    assert len(bars) == 1
    bar2 = bars[0]
    assert bar2 is bar
    assert bar.foo() is not None  # the sign of the bug in question
    assert bar.foo() is foo  # what we should expect

    store.clear()
    bar = store.fetchObjectsOfClass(Bar)[0]
    assert bar.foo() is not None
コード例 #3
0
ファイル: TestEmpty.py プロジェクト: techeye220/w4py
def test(store):
    # We invoke testAddToBars twice on purpose, just to see that
    # the second time around, things are stable enough to pass again
    testAddToBars(store)
    testAddToBars(store)

    # Test 2: do not use addToBars()
    f = Foo()
    store.addObject(f)
    b = Bar()
    b.setFoo(f)
    b.setX(7)
    store.addObject(b)
    store.saveChanges()
    store.clear()

    f = store.fetchObjectsOfClass(Foo)[0]
    assert f._mk_store
    assert f._mk_inStore
    bars = f.bars()
    assert isinstance(bars, list)
    assert len(bars) == 1, 'bars=%r' % bars
    assert bars[0].x() == 7

    # Test addToXYZ() method
    bar = Bar()
    bar.setX(42)
    f.addToBars(bar)
    assert bar.foo() == f
    store.saveChanges()
    store.clear()

    f = store.fetchObjectsOfClass(Foo)[0]
    bars = f.bars()
    assert isinstance(bars, list)
    assert len(bars) == 2, 'bars=%r' % bars
    assert bars[0].x() == 7
    assert bars[1].x() == 42

    # Test the assertion checking in addToXYZ()
    try:
        f.addToBars(None)
    except Exception:
        pass
    else:
        NoException('f.addToBars(None)  # None not allowed')

    try:
        f.addToBars(5)
    except Exception:
        pass
    else:
        NoException('f.addToBars(5)  # not an object')

    try:
        f.addToBars(f)
    except Exception:
        pass
    else:
        NoException('f.addToBars(f)  # wrong class')

    try:
        f.addToBars(bar)
    except Exception:
        pass
    else:
        NoException('f.addToBars(bar)  # already added')

    # Test delFromXYZ() method
    bar = bars[1]
    f.delFromBars(bar)
    assert len(bars) == 1
    assert bar.foo() is None
    store.saveChanges()
    store.clear()

    f = store.fetchObjectsOfClass(Foo)[0]
    bars = f.bars()
    assert isinstance(bars, list)
    assert len(bars) == 1, 'bars=%r' % bars
    assert bars[0].x() == 7

    # Test the assertion checking in delFromXYZ()
    try:
        f.delFromBars(None)
    except Exception:
        pass
    else:
        NoException('f.delFromBars(None)  # None not allowed')

    try:
        f.delFromBars(5)
    except Exception:
        pass
    else:
        NoException('f.delFromBars(5)  # not an object')

    try:
        f.delFromBars(f)
    except Exception:
        pass
    else:
        NoException('f.delFromBars(f)  # wrong class')

    try:
        f.delFromBars(bar)
    except Exception:
        pass
    else:
        NoException('f.delFromBars(bar)  # already deleted')
コード例 #4
0
ファイル: TestEmpty1.py プロジェクト: Cito/w4py-olde-docs
def test(store):
    from Foo import Foo
    from Bar import Bar
    from BarReq import BarReq

    # Create a Foo and a Bar that refers to it
    f = Foo()
    f.setX(3)

    store.addObject(f)
    store.saveChanges()

    b = Bar()
    b.setFoo(f)
    store.addObject(b)
    store.saveChanges()

    # Test fetching
    store.clear()
    results = store.fetchObjectsOfClass(Bar)
    assert len(results)
    b = results[0]
    f1 = b.foo()
    f2 = b.foo()
    assert f1 is not None, 'got None instead of a Foo'
    assert f1 is f2 # test uniqueness
    assert b.foo().x() == 3

    # Fetch in reverse order
    store.clear()
    f = store.fetchObjectsOfClass(Foo)[0]
    b = store.fetchObjectsOfClass(Bar)[0]
    assert b.foo() is f

    # Test None, set, save and retrieve
    b.setFoo(None)
    store.saveChanges()
    store.clear()
    b = store.fetchObjectsOfClass(Bar)[0]
    assert b.foo() is None

    # Test the assertions in setFoo()
    b = BarReq()
    try:
        b.setFoo(None)
    except Exception:
        pass
    else:
        NoException('b.setFoo(None) # None not allowed')

    try:
        b.setFoo('x')
    except Exception:
        pass
    else:
        NoException('b.setFoo("x") # wrong type not allowed')

    try:
        b.setFoo(Bar())
    except Exception:
        pass
    else:
        NoException('b.setFoo(Bar()) # wrong class not allowed')
コード例 #5
0
def test(store):
    from Foo import Foo
    from Bar import Bar
    from BarReq import BarReq

    # Create a Foo and a Bar that refers to it
    f = Foo()
    f.setX(3)

    store.addObject(f)
    store.saveChanges()

    b = Bar()
    b.setFoo(f)
    store.addObject(b)
    store.saveChanges()

    # Test fetching
    store.clear()
    results = store.fetchObjectsOfClass(Bar)
    assert len(results)
    b = results[0]
    f1 = b.foo()
    f2 = b.foo()
    assert f1 is f2  # test uniqueness
    assert b.foo().x() == 3

    # Fetch in reverse order
    store.clear()
    f = store.fetchObjectsOfClass(Foo)[0]
    b = store.fetchObjectsOfClass(Bar)[0]
    assert b.foo() is f

    # Test None, set, save and retrieve
    b.setFoo(None)
    store.saveChanges()
    store.clear()
    b = store.fetchObjectsOfClass(Bar)[0]
    assert b.foo() is None

    # Test the assertions in setFoo()
    b = BarReq()
    try:
        b.setFoo(None)
    except:
        pass
    else:
        NoException('b.setFoo(None) # None not allowed')

    try:
        b.setFoo('x')
    except:
        pass
    else:
        NoException('b.setFoo("x") # wrong type not allowed')

    try:
        b.setFoo(Bar())
    except:
        pass
    else:
        NoException('b.setFoo(Bar()) # wrong class not allowed')
コード例 #6
0
def test(store):
    # We invoke testAddToBars twice on purpose, just to see that
    # the second time around, things are stable enough to pass again
    testAddToBars(store)
    testAddToBars(store)

    # Test 2: do not use addToBars()
    # @@ 2001-02-11 ce: this is probably not a valid test in the long run
    f = Foo()
    f.setX(
        0
    )  # @@ 2000-11-25 ce: take out after fixing default value bug in gen py code
    store.addObject(f)
    b = Bar()
    b.setFoo(f)
    b.setX(7)
    store.addObject(b)
    store.saveChanges()
    store.clear()

    f = store.fetchObjectsOfClass(Foo)[0]
    assert f._mk_store
    assert f._mk_inStore
    bars = f.bars()
    assert type(bars) is ListType
    assert len(bars) == 1, 'bars=%r' % bars
    assert bars[0].x() == 7

    # Test addToXYZ() method
    bar = Bar()
    bar.setX(7)
    f.addToBars(bar)
    assert bar.foo() == f
    store.saveChanges()
    store.clear()

    f = store.fetchObjectsOfClass(Foo)[0]
    bars = f.bars()
    assert type(bars) is ListType
    assert len(bars) == 2, 'bars=%r' % bars
    assert bars[0].x() == 7
    assert bars[1].x() == 7

    # Test the assertion checking in addToXYZ()
    try:
        f.addToBars(None)
    except:
        pass
    else:
        NoException('f.addToBars(None) # None not allowed')

    try:
        f.addToBars(5)
    except:
        pass
    else:
        NoException('f.addToBars(5) # not an object')

    try:
        f.addToBars(f)
    except:
        pass
    else:
        NoException('f.addToBars(f) # wrong class')

    try:
        f.addToBars(bar)
    except:
        pass
    else:
        NoException('f.addToBars(bar) # already added')