On Aug 9, 7:55 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 8/9/07, Chris Green <[EMAIL PROTECTED]> wrote:

> >  1)  initial_data has bitten me not realizing it was synced in
> > production each time.

> There is an argument to be made that initial_data for a model should
> only be loaded once - when the model is added to the database. I can't
> say I've been bitten by this problem myself, but I'm happy to
> entertain discussion/patches that address the issue.

I'll look into creating such a patch. The test case was having some
"basic templates" to choose from but then allowing users to edit those
templates to meet their own prefs.  The syncdb to add additional apps
killed the modified templates.


> > 2) Setting up users/groups/users manually in the runner gets blown
> > away by the TestCase architecture.  Works as documented.  However, I'm
> > not sure where I should put things that should happen post-each syncdb
> > for testing only.  Should there be a testrunner function that gets
> > called post each sync or should I create a single TestCase derived
> > from django.test.TestCase that does the "pre-setup"?
>
> I'm not sure I follow. TestCase goes out of its way to avoid
> interfering with setUp/tearDown methods, and in a TestCase, there is a
> complete flush after each test, so any setup would need to be rerun on
> a per-test basis, not a per-sync basis. Can you provide an example of
> the problem?

Sure: My runner simplified

The suggestion is I need to move setup_auth() to my test methods.
That does seem to be the right way to do it so I can have different
perms across each item.

def permission_finder(s):
    """ Given a string in the format app_label.codename, return the
exact permission """
    parts = s.split('.')
    if len(parts) != 2:
        raise UnknownPermission, "Unable to parse permission string
%s"%  s

    m,c = parts

    model_perms =
Permission.objects.filter(content_type__app_label__exact=m)

    if not model_perms:
        raise UnknownPermission, "No such model permissions: %s" % m

    perms = model_perms.filter(codename__exact=c)

    if not perms:
        raise UnknownPermission, "No permissions found for %s.%s" %
(m,c)

    return perms

def setup_auth():
         # Helpdesk Perms
         helpdesk_perms = permission_finder('helpdesk.view_logs')

         # Level 2 Perms
         l2_perms = (helpdesk_perms,
 
permission_finder('helpdesk.reset_passwords'))

        l1group = Group(name='Level1 Support')
        l1group.save()

        l2group = Group(name='Level2 Support')
        l2group.save()

        for each in l2_perms:
            assert(each)
            for p in each:
                print "adding %s to %s" % (p,g1)
                g1.permissions.add(p)

        u1 = User.objects.create_user('level1user', '[EMAIL PROTECTED]',
'password')
        u1.save()
        u1.groups.add(g1)

def run_tests(...):
    setup_middleware() # get rid of cas for Unit Testing
    setup_test_environment()
    [ Build the test suite ]
    old_name = settings.DATABASE_NAME
    create_test_db(verbosity,autoclobber=True)
    setup_auth()
    unittest.TextTestRunner(verbosity=verbosity).run(suite)
    destroy_test_db(old_name, verbosity)
    teardown_test_environment()





>
> > 3) DateTime serialization won't work if the date is before 1901 - I
> > have a bug/real life data set where I get some bogus dates out of
> > another system.   This is really a python problem.
>
> Again, if you can provide an example, it would help. However, if the
> problem is with Python itself, there's not a great deal we can do.
>

class DateModel(models.Model):
         time = models.DateTime()

dm = DateModel(time=datetime.datetime(1,1,1))

Since strptime() breaks with dates before 1901, it gets serialized out
with dumpdata but fails on a loaddata()


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to