<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 4/8/09 4:07 PM, Uli Fouquet wrote:
<blockquote cite="mid:1239199629.7491.9.camel@pu" type="cite">
  <pre wrap="">Hi there,

Wichert Akkerman wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">How can you unittest a view? Trying to instantiate a view in a testcase
fails when the constructor tries to access self.__view_name__ and
self.module_info. 
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Maybe something like this?

:test-layer: unit

    &gt;&gt;&gt; import grok
    &gt;&gt;&gt; grok.testing.grok('sample')
  </pre>
</blockquote>
<br>
That groks the whole sample package, right? I do not want that, since
that can have all kinds of effects. What I am looking for is the very
minimal thing that allows me to instantiate a view so I can call
methods on it. Currently I use this:<br>
<br>
&nbsp;&nbsp;&nbsp; def setUp(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # grok makes unit testing extremely painful<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; View.__view_name__ = "iew"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; View.module_info=Mock()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
View.module_info.package_dotted_name="euphorie.content.model.View"<br>
<br>
&nbsp;&nbsp;&nbsp; def tearDown(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; del View.__view_name__<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; del View.module_info<br>
<br>
&nbsp;&nbsp;&nbsp; def testSomething(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; model=Model()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; view=View(model, None)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Do the tests here<br>
<br>
<br>
which works, but is not quite optimal<br>
<br>
Wichert.<br>
<br>
</body>
</html>