[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r6913 - in trunk/gnue-appserver/samples/testing: . joins
From: |
johannes |
Subject: |
[gnue] r6913 - in trunk/gnue-appserver/samples/testing: . joins |
Date: |
Thu, 20 Jan 2005 08:23:04 -0600 (CST) |
Author: johannes
Date: 2005-01-20 08:23:03 -0600 (Thu, 20 Jan 2005)
New Revision: 6913
Added:
trunk/gnue-appserver/samples/testing/joins/dirty.py
Modified:
trunk/gnue-appserver/samples/testing/dirty.py
trunk/gnue-appserver/samples/testing/joins/struct.gcd
Log:
Updated test-cases
Modified: trunk/gnue-appserver/samples/testing/dirty.py
===================================================================
--- trunk/gnue-appserver/samples/testing/dirty.py 2005-01-20 14:22:33 UTC
(rev 6912)
+++ trunk/gnue-appserver/samples/testing/dirty.py 2005-01-20 14:23:03 UTC
(rev 6913)
@@ -21,35 +21,149 @@
#
# $Id$
+import sys
from gnue.appserver.language import App
+from gnue.common.apps import i18n
+def dump (seq):
+ print "-" * 79
+ slen = len (seq)
+ for ix in xrange (len (seq)):
+ item = seq [ix]
+ print o("%2d | %-35s | %-35s" % (ix+1, item.name, item.country.name))
+
+ print "-" * 79
+ print "Number of records: %d (pre), %d (post)" % (slen, len (seq))
+
+def getCountry (session, code):
+ res = session.find ('address_country', {'address_code': code})
+ return res and res [0] or None
+
if __name__ == "__main__":
app = App.App ()
- print "requesting new session ..."
session = app.newSession ('test', 'test')
session.setcontext ('address')
- persons = session.find ('person', [], ['address_name'],
- ['address_name', 'address_street'])
- for guy in persons:
- print "Guy:", guy.name, "lives in:", guy.street
+ country = session.find ('country', {'address_code': 'AT'})
+ austria = country [0]
- print "Adding new instance ..."
- new = session.new ('address_person')
- new.address_name = 'Foobar and the gang'
- new.address_street = "Don't know it"
+ # find with no condition and no sorting
+ print "Find () without condition and no sortorder:"
- print "New guy:", new.name, "lives in:", new.street
- new = session.new ('address_person')
- new.address_name = 'Bloody shit !'
- print "New guy:", new.name, "lives in:", repr (new.street)
+ persons = session.find ('person')
+ dump (persons)
- print "running new find ..."
- persons = session.find ('person', [], ['address_name'],
- ['address_name', 'address_street'])
+ print "Inserting new one"
+ new = session.new ('person')
+ new.name = 'Newly inserted'
+ new.street = 'New Street'
- for guy in persons:
- print "Guy:", guy.name, "lives in:", guy.street
+ print "Inserting second"
+ new = session.new ('person')
+ new.name = "You won't see me"
+ new.street = 'somewhere'
+
+ print "Removing the inserted record"
+ new.delete ()
+
+ if persons:
+ x = persons [0].name
+ print "Changing first instance", o(x)
+ persons [0].name = x + ' (changed)'
+
+ x = persons [-1]
+ print "Removing last instance", o(x.name)
+ x.delete ()
+
+
+ print "Running the same find again:"
+ persons = session.find ('person')
+ dump (persons)
+
+ session.rollback ()
+ print "End of first test. <Enter> to continue"
+ raw_input ()
+
+ #
+ order = [('address_name', True)]
+ print "Running find with order:", order
+ pers = session.find ('person', [], order)
+ dump (pers)
+
+ new = session.new ('person')
+ new.name = 'Newly inserted <--'
+ print "Adding person:", o(new.name)
+
+ new = session.new ('person')
+ new.name = 'Yet another new record <--'
+ print "Adding person:", o(new.name)
+
+ if pers:
+ p = pers [0]
+ print "Setting name to None for:", p.name
+ p.name = None
+
+ p = pers [-1]
+ print "Removing person:", p.name
+ p.delete ()
+
+
+ print "Running find () again:"
+ pers = session.find ('person', [], order)
+ dump (pers)
+
+ session.rollback ()
+ print "End of second test. <Enter> to continue"
+ raw_input ()
+
+ #
+ order= ['address_country.address_name']
+ cond = ['notnull', ['field', 'address_country.address_name']]
+ print "Running find with condtion and order:"
+ print "Order :", order
+ print "Condition:", cond
+ pers = session.find ('person', cond, order)
+ dump (pers)
+
+ new = session.new ('person')
+ new.name = 'Inserted to Austria <--'
+ new.country = getCountry (session, 'AT')
+ print "Added person", new.name, new.country.name
+
+ new = session.new ('person')
+ new.name = 'You should not see me <--'
+ print "Added person", new.name, new.country.name
+
+ if pers:
+ p = pers [0]
+ p.country = getCountry (session, 'GB')
+ print "Changed country for:", p.name, "to", p.country.name
+
+ if len (pers) > 1:
+ p = pers [1]
+ p.country = None
+ print "Changed country for:", p.name, "to None"
+
+ if len (pers) > 2:
+ p = pers [2]
+ print "Changing name of", p.name, "to 'Foobar, changed'"
+ p.name = 'Foobar, changed'
+
+ if len (pers) > 3:
+ p = pers [3]
+ print "Changing name and country for:", p.name, p.country.name
+ p.country = getCountry (session, 'FR')
+ p.name = 'Just to see it <--'
+ print "to:", p.name, p.country.name
+
+ print "Running same find () againg:"
+ pers = session.find ('person', cond, order)
+ dump (pers)
+
+ session.rollback ()
+ print "End of second test. <Enter> to continue"
+ raw_input ()
+
Added: trunk/gnue-appserver/samples/testing/joins/dirty.py
===================================================================
--- trunk/gnue-appserver/samples/testing/joins/dirty.py 2005-01-20 14:22:33 UTC
(rev 6912)
+++ trunk/gnue-appserver/samples/testing/joins/dirty.py 2005-01-20 14:23:03 UTC
(rev 6913)
@@ -0,0 +1,68 @@
+# GNU Enterprise Application Server - Testing unit - Dirty Reads
+#
+# Copyright 2003-2004 Free Software Foundation
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+import sys
+from gnue.appserver.language import App
+
+def getItem (session, itemcode):
+ items = session.find ('item', {'test_code': itemcode})
+ return items and items [0] or None
+
+
+
+if __name__ == "__main__":
+ app = App.App ()
+
+ print "Requesting new session ..."
+ session = app.newSession ('test', 'test')
+
+ session.setcontext ('test')
+
+ customers = session.find ('customer', {'test_name': 'Foobar'})
+ if not customers:
+ print "We don't have any customers"
+ sys.exit (0)
+
+ inv = session.new ('invoice')
+ inv.number = '1234'
+ inv.customer = customers [0]
+ inv.description = 'Just a test'
+
+ # Now add some line-items
+ print "adding some lineitems ..."
+
+ item = session.new ('lineitem')
+ item.invoice = inv
+ item.position = 1
+ item.item = getItem (session, 'G1')
+ item.quantity = 2
+
+ item = session.new ('lineitem')
+ item.invoice = inv
+ item.position = 2
+ item.item = getItem (session, 'G2')
+ item.quantity = 3
+
+ print "Ok"
+
+ print "value of the invoice:", inv.value
Property changes on: trunk/gnue-appserver/samples/testing/joins/dirty.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/gnue-appserver/samples/testing/joins/struct.gcd
===================================================================
--- trunk/gnue-appserver/samples/testing/joins/struct.gcd 2005-01-20
14:22:33 UTC (rev 6912)
+++ trunk/gnue-appserver/samples/testing/joins/struct.gcd 2005-01-20
14:23:03 UTC (rev 6913)
@@ -16,12 +16,30 @@
<property name="code" type="string(35)" nullable="False" />
<property name="description" type="string(70)" nullable="False" />
<property name="group" type="test_itemgroup" />
+ <property name="price" type="number(15,2)" />
</class>
<class name="invoice" >
<property name="number" type="number(6)" nullable="False" />
<property name="customer" type="test_customer" />
<property name="description" type="string(35)" />
+ <property name="value" type="number(19,2)" >
+ session.setcontext ('test')
+ result = 0.0
+ for line in session.find ('lineitem', {'test_invoice': self.gnue_id}):
+ qty = line.quantity or 0
+ price = line.item.price or 0
+ result += qty * price
+
+ return result
+ </property>
+
+ <procedure name="OnDelete" >
+ session.setcontext ('test')
+ lines = session.find ('lineitem', {'test_invoice': self.gnue_id})
+ for item in lines:
+ item.delete ()
+ </procedure>
</class>
<class name="lineitem" >
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r6913 - in trunk/gnue-appserver/samples/testing: . joins,
johannes <=