yea, i never go as far to check html either.
ill take some of your thoughts and blend it into my process

as far as the strings go. thanks a ton, it all makes sense since
strings are immutable.

=)

On May 6, 11:51 am, "Norman Harman" <[EMAIL PROTECTED]> wrote:
> phillc wrote:
>
>   > first:
>
> > ====
> > How does one develop tests for django web apps?
> > im having trouble writing tests.
> > i understand there are view tests, but those are so overly complex to
> > write.
> > i was just wondering how other people approach it, and if anyone can
> > point me to some open source application that uses tests properly.
> > i would love to give test driven development a try, but right now, i
> > feel that my code is too bound to code in my view, which im having
> > trouble making unit tests for. (id love to see a django project
> > somewhere that was test driven)
>
> TDD is very hard.  I rarely muster the discipline to do pure TDD.  But,
> TDD isn't required to have unittests, which are awesome by themselves.
>
> If you haven't already readhttp://www.djangoproject.com/documentation/testing/
>
> View tests don't have to be complex, the minimal test for a non-form
> view checks quite alot:
>
> urls.py
> urlpatterns = patterns("specials.views",
>      url(r"^$", "ads", name="ts_ads"))
>
> tests.py
>      def test_specials(self):
>          url = reverse("ts_ads")
>          response = self.client.get(url)
>          self.assertTemplateUsed(response, "specials/ads.html")
>
> Basically if I write it I test it.  Don't test that Django works or your
> database works.  They should have their own tests.
>
> For views I mostly don't check they return the expected html(it changes
> too often during development and I think that is better handled with a
> tool such as Selenium).  Instead I check that they use correct template,
> redirect to login page, don't raise exceptions, etc.  I also have
> written a custom UnitTest (extending Django's) that checks for empty
> template vars using TEMPLATE_STRING_IF_INVALID='test_oops_test'.
>
> I do POST to views that have forms and check they work as expected.
> Although, I usually check form validation in separate forms tests.
>
> I check forms with any custom validators or logic.
>
> I check every method I write for models and model managers including
> things like __unicode__ via str(modelinstance).
>
> Also, Every time I find a bug I first write a unittest that fails
> because of that bug.  Then I fix the bug and check unittest then passes.
>
> > fourth:
> > ====
> > i never understood this, why do people do
>
> > somevar = "blah blah %s" % anothervar
>
> > instead of "blah bla" + anothervar
> > ?
>
> Since python strings are immutable using + causes a lot of unnecessary
> copying.  It's probably not such a big deal in rarely executed code but
> is a real performance killer in loops.  For consistency and clarity,
> people tend to avoid using + with strings altogether.
>
> For example this is slow/unnecessary:
>    s = ""
>    for txt in somelist:
>      s += txt
>    print s
>
> The Pythonic way is to use a list:
>    s = list()
>    for txt in somelist:
>      s.append(txt)
>    print "".join(s)
>
> Joining a list of strings is neat because instead of "" you can use ", "
> or "\n", "\t" which are all fairly common and join takes care of not
> having a trailing ", ".
>
> For more seehttp://www.omahapython.org/IdiomaticPython.html
>
> > fifth:
> > ====
> > in my models, a model object is only aware of the objects above it,
> > and not below it.
> > in C, i remember i just declared all functions, with no body to it, at
> > the top of the file
> > then all functions were aware of all functions.
> > how do i do this in python?
>
> AFAIK you can't.  In some places with Django you can put names in quotes
> to have the same effect. 
> Seehttp://www.djangoproject.com/documentation/model-api/#relationships
>
> --
> Norman J. Harman Jr.  512 912-5939
> Technology Solutions Group, Austin American-Statesman
> ___________________________________________________________________________
> Get out and about this spring with the Statesman! In print and online,
> the Statesman has the area's Best Bets and recreation events.
> Pick up your copy today or go to statesman.com 24/7.
--~--~---------~--~----~------------~-------~--~----~
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