Webware / MiddleKit / Tests / MKModelInh2.mkmodel / TestEmpty.py

def test(store):
    from Foo import Foo
    from MiscUtils.DataTable import DataTable

    dataSource = '''
b:int,i:int,l:long,f:float,s:string,x:int
0,0,0,0,0,0
0,0,0,0.0,0.0,0
1,1,1,1,a,1
0,-1,8589934592,-3.14,'x',3
'''

    data = DataTable()
    data.readString(dataSource)

    for values in data:
        print values

        t = Foo()
        for attr in list('bilfsx'):
            t.setValueForKey(attr, values[attr])

        store.addObject(t)
        store.saveChanges()

        # Try an immediate fetch
        results = store.fetchObjectsOfClass(Foo)
        assert len(results) == 1
        # This tests the uniquing feature of MiddleKit:
        assert id(results[0]) == id(t)

        # Clear the store's in memory objects and try a fetch again
        store.clear()
        results = store.fetchObjectsOfClass(Foo)
        assert len(results) == 1
        assert results[0].allAttrs() == t.allAttrs()

        # Make sure what we got from the store is what we put in
        for attr in list('bilsx'):
            assert results[0].valueForKey(attr) == values[attr]

        different = 0.000001 # @@ 2000-11-25 ce: more work needed on floats
        assert abs(results[0].valueForKey('f')-values['f']) < different

        # Insert the fetched attributes
        t2 = Foo()
        for attr in list('bilfsx'):
            t2.setValueForKey(attr, results[0].valueForKey(attr))
        store.addObject(t2)
        store.saveChanges()
        results = store.fetchObjectsOfClass(Foo)
        assert len(results) == 2, 'len=%r' % len(results)
        assert results[0].allAttrs() == results[1].allAttrs()

        # Reset
        store.clear()
        store.executeSQLTransaction('delete from Foo;')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.