Hi!

Thanks for your answers

>
> I didn't read the link, but I can see what you're saying.  Here are a
> couple tricks I can suggest:
>
> * To test your controllers somewhat in isolation, instead of calling
> render_response, call my_render_response which you write yourself.  In
> my_render_response, in testing mode, you can simply return JSON, and,
> in real mode, you can return a real page.  Then, you can test the data
> in the JSON--i.e. the page model.

Thinking last night about this particular issue, I found that building
a "page model layer" of queries or classes, that generates the
specific JSON or python data is a good way to insulate the testing,
without touching the controller implementation

>
> * Alternatively, in your site-wide layout, take the entire "c" object,
> serialize it and shove it in an HTML comment.  Then, write a script
> that can look for the HTML comment and deserialize it.  Wham--you
> suddenly have a way to grab the entire "c" object from the HTML of any
> generated page.  Of course this doesn't work for redirects or when
> you're generating something other than HTML, but I think that's okay.
>
> * I've seen a real test-driven development shop in action using Ruby
> on Rails.  The way they did it was to use pre-arranged data in the
> database and then test for the presence of data at specific places in
> the HTML DOM like.  For instance, "#name 'Charlie Tuna'" asserts that
> there must be a name element which contains the known string "Charlie
> Tuna".  This kind of testing is fully automated, of course.

Mmmm, this kind of behaviour can be reproduced with a test-dburi in
test.ini, and
specific test-data in the test DB....

Since I just arrived to pylons, I'm so intrigued about calling
controller tests "functional", where "unit" testing is also required.

I'm exploring a solution for unit testing controllers in the next way,
mocking the "page model layer" to return only expected data (I'm using
python-mock, by the way)

Here is my "dreamed code"

from my_page_model import MyPageModel
from mock import Mock

class TestMyPageController(TestController):
   originalPageModel = None

   def setUp(self):
       expectedData = {....}
       # this line creates a mock object that return expected Data
       # and fulfills the MyPageModel interface
       pageModelMock = Mock({getData : expectedData}, MyPageModel)

      # dreamed code: replaces de "production" pageModel with my
pageModelMock
      # ensuring that  MyPageController uses this model instead the
production one
      self.originalPageModel = getPageModel()
      setPageModel(pageModelMock)

  def testMyPage(self):
     # common test controller code, but this time this code
     # assumes that the data is provided by the pageModelMock object
   ....

  def tearDown(self):
     setPageModel(self.originalPageModel)


Any hint to do this?

Thanks!
  Agustin



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

Reply via email to