First, I am using 'svn diff' for submitting my patches, let me know if
there is a preferred way... especially when posting to Trac.

First, I ran into an issue with runtests.py since I use MySQL. The DB
connection autocommit requires an integer value and the current code
throws a TypeError for me. So the real brain-dead way around this was:

Index: runtests.py
===================================================================
--- runtests.py (revision 647)
+++ runtests.py (working copy)
@@ -97,6 +97,8 @@
                 db.connection.autocommit()
             except AttributeError:
                 pass
+            except TypeError:   # For MySQL Users
+                db.connection.autocommit(1)
             self.output(1, "Creating test database")
             try:
                 cursor.execute("CREATE DATABASE %s" %
TEST_DATABASE_NAME)
@@ -183,6 +185,8 @@
                 db.connection.autocommit()
             except AttributeError:
                 pass
+            except TypeError:   # For MySQL Users
+                db.connection.autocommit(1)
             else:
                 time.sleep(1) # To avoid "database is being accessed
by other users" errors.
             cursor.execute("DROP DATABASE %s" % TEST_DATABASE_NAME)


Here are my modifications to one-to-one.py:

Index: one_to_one.py
===================================================================
--- one_to_one.py       (revision 647)
+++ one_to_one.py       (working copy)
@@ -23,6 +23,13 @@
     def __repr__(self):
         return "%s the restaurant" % self.get_place().name

+class Waiter(meta.Model):
+    restaurant = meta.ForeignKey(Restaurant)
+    name = meta.CharField(maxlength=50)
+
+    def __repr__(self):
+        return "%s the waiter at %s" % (self.name,
self.get_restaurant())
+
 API_TESTS = """
 # Create a couple of Places.
 >>> p1 = places.Place(name='Demon Dogs', address='944 W. Fullerton')
@@ -61,4 +68,10 @@
 Demon Dogs the restaurant
 >>> restaurants.get_object(pk=1)
 Demon Dogs the restaurant
+
+# Add Waiter to Restaurant.
+>>> w = r.add_waiter(name="Joe")
+>>> w.save()
+>>> w
+Joe the waiter at Demon Dogs the restaurant
 """

My tests failed spectacularly...

Running tests with database 'mysql'

'one_to_one' module: API test raised an exception
=================================================
Code: 'w = r.add_waiter(name="Joe")'
Line: 40
Exception:   File "C:\www\downloads\trunk\tests\doctest.py", line 1243,
in __run
    compileflags, 1) in test.globs
  File "<doctest one_to_one[13]>", line 1, in ?
    w = r.add_waiter(name="Joe")
  File "C:\www\django\utils\functional.py", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))
  File "C:\www\django\core\meta\__init__.py", line 944, in
method_add_related
    obj = rel_mod.Klass(**init_kwargs)
  File "C:\www\django\utils\functional.py", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))
  File "C:\www\django\core\meta\__init__.py", line 755, in method_init
    raise TypeError, "Invalid value: %r should be a %s instance, not a
%s" % (f.name, f.rel.to, type(rel_obj))
TypeError: Invalid value: 'restaurant' should be a <Options for
restaurants> instance, not a <class 'django.models.one_to_one.Rest
aurant'>


'one_to_one' module: API test raised an exception
=================================================
Code: 'w.save()'
Line: 41
Exception:   File "C:\www\downloads\trunk\tests\doctest.py", line 1243,
in __run
    compileflags, 1) in test.globs
  File "<doctest one_to_one[14]>", line 1, in ?
    w.save()
NameError: name 'w' is not defined


'one_to_one' module: API test raised an exception
=================================================
Code: 'w'
Line: 42
Exception:   File "C:\www\downloads\trunk\tests\doctest.py", line 1243,
in __run
    compileflags, 1) in test.globs
  File "<doctest one_to_one[15]>", line 1, in ?
    w
NameError: name 'w' is not defined

Let me know if I can improve on how I submit my future contributions...

regards,
Ian


Adrian Holovaty wrote:
> On 9/19/05, Ian Maurer <[EMAIL PROTECTED]> wrote:
> > But, I have a multitude of problems that I don't believe I had before
> > the recent model overhaul. Here are some example things I tried doing
> > with my Waiter class that I believe should work:
>
> Hey Ian,
>
> It'd be a huge help if you could add some unit tests to
> tests/testapp/models/one_to_one.py and post them back to the list.
>
> Adrian
>
> --
> Adrian Holovaty
> holovaty.com | djangoproject.com | chicagocrime.org

Reply via email to