<!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
>>> import grok
>>> 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>
def setUp(self):<br>
# grok makes unit testing extremely painful<br>
View.__view_name__ = "iew"<br>
View.module_info=Mock()<br>
View.module_info.package_dotted_name="euphorie.content.model.View"<br>
<br>
def tearDown(self):<br>
del View.__view_name__<br>
del View.module_info<br>
<br>
def testSomething(self):<br>
model=Model()<br>
view=View(model, None)<br>
# Do the tests here<br>
<br>
<br>
which works, but is not quite optimal<br>
<br>
Wichert.<br>
<br>
</body>
</html>