Hey Aroldo,<br><br>Two things:<br><br>1) Your latter test example is correct -- the URL you visit should not include the colon, so browser.open(&#39;<a href="http://localhost/app/foreigners/funnyname">http://localhost/app/foreigners/funnyname</a>&#39;) is the correct way.<br>

<br>2) I found that registering a view named &#39;index&#39; does not get treated as the default view.  Instead you need to name your view &#39;index.html&#39;.  I think this is a bug, but I didn&#39;t get far enough to figure out what layer the bug is in.  Alternatively, browser.open(&#39;<a href="http://localhost/app/foreigners/funnyname/@@index">http://localhost/app/foreigners/funnyname/@@index</a>&#39;) should work when your view is named &#39;index&#39;. <br>

<br>Hope this helps,<br>Ethan<br><br><div class="gmail_quote">On Mon, Jan 25, 2010 at 5:58 AM, Aroldo Souza-Leite <span dir="ltr">&lt;<a href="mailto:asouzaleite@gmx.de">asouzaleite@gmx.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Hi Martijn,<br>
<br>
<br>
am I wrong in the expectation that an object of a non-Grok class &#39;SomeForeignModel&#39;<br>
(see attachment) would be instantiated by &#39;factory&#39; in &#39;TrajectForSomeForeignModel&#39;<br>
as a result of the request defined in &#39;pattern&#39; and that this object (or some view of it) would<br>
be shown in the response?<br>
<br>
If this is what &#39;megrok.traject&#39; does to a non-Grok model, then I got stuck where<br>
think I should implement a view for the non-Grok class &#39;SomeForeignModel&#39;. How can I do this?<br>
<br>
Perhaps I just didn&#39;t get the basic idea of the &#39;megrok.traject&#39; usage for non-Grok classes?<br>
<br>
Regards,<br><font color="#888888">
<br>
Aroldo.</font><div><div></div><div class="h5"><br>
<br>
<br>
<br>
<br>
<br>
Martijn Faassen wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Spotlight on...<br>
<br>
megrok.traject is a package that allows a different way to publish your models than the traversal that is most commonly used in Zope applications. With megrok.traject you can define explicitly what kind of URLs you want to publish your models on, instead of having to construct an object hierarchy.<br>


<br>
A model can be anything that you want to have views for, and doesn&#39;t need to be a persistent ``grok.Model``. In fact megrok.traject is most suitable for objects that are not stored in the ZODB, as the ZODB makes traversal easy.<br>


<br>
What kind of models could you publish with megrok.traject then? It<br>
could be just Python objects you design yourself. In this case you can use ``traject.Model``. You tell it under what URL pattern it should appear and how it is to be constructed, and you&#39;re done. ``traject.Model`` is very lightweight: it&#39;s just a ``grok.Context`` that can be hooked up by a &quot;traject pattern&quot;.<br>


<br>
Alternatively you may want to treat your models even more lightly: you may wish to hook up models that are defined by a package that is not under your control at all. You could have for instance an ORM such as SQAlchemy define the models in an entirely different package that knows nothing about how these models should be presented on the web in your application. You can then use ``traject.Traject`` to associate such models with a URL pattern in your application.<br>


<br>
You can look at the megrok.traject documentation for more information:<br>
<br>
<a href="http://pypi.python.org/pypi/megrok.traject" target="_blank">http://pypi.python.org/pypi/megrok.traject</a><br>
<br>
The low-level implementation is a reusable library called ``traject``, and its documentation can give you more details:<br>
<br>
<a href="http://pypi.python.org/pypi/traject" target="_blank">http://pypi.python.org/pypi/traject</a><br>
<br>
If you still don&#39;t understand why megrok.traject would be useful for *you*, don&#39;t worry. Grok&#39;s traversal method of publishing objects isn&#39;t going anywhere, and megrok.traject is just an option. If you have questions, we&#39;d very much like to hear them on grok-dev however, so that we can improve megrok.traject and its documentation.<br>


<br>
Volunteers who would want to write a tutorial oriented towards beginners that uses megrok.traject would also be very welcome!<br>
<br>
<br>
_______________________________________________<br>
Grok-dev mailing list<br>
<a href="mailto:Grok-dev@zope.org" target="_blank">Grok-dev@zope.org</a><br>
<a href="https://mail.zope.org/mailman/listinfo/grok-dev" target="_blank">https://mail.zope.org/mailman/listinfo/grok-dev</a><br>
  <br>
</blockquote>
<br>
</div></div><br>Do a functional doctest test on the app.<br>
========================================<br>
<br>
:Test-Layer: functional<br>
<br>
Let&#39;s first create an instance of Trajectcave at the top level:<br>
<br>
   &gt;&gt;&gt; from trajectcave.app import TrajectCave<br>
   &gt;&gt;&gt; root = getRootFolder()<br>
   &gt;&gt;&gt; root[&#39;app&#39;] = TrajectCave()<br>
<br>
<br>
Run tests in the testbrowser<br>
----------------------------<br>
<br>
The zope.testbrowser.browser module exposes a Browser class that<br>
simulates a web browser similar to Mozilla Firefox or IE.  We use that<br>
to test how our application behaves in a browser.  For more<br>
information, see <a href="http://pypi.python.org/pypi/zope.testbrowser" target="_blank">http://pypi.python.org/pypi/zope.testbrowser</a>.<br>
<br>
Create a browser and visit the instance you just created:<br>
<br>
   &gt;&gt;&gt; from zope.testbrowser.testing import Browser<br>
   &gt;&gt;&gt; browser = Browser()<br>
   &gt;&gt;&gt; browser.open(&#39;<a href="http://localhost/app" target="_blank">http://localhost/app</a>&#39;)<br>
<br>
Check some basic information about the page you visit:<br>
<br>
   &gt;&gt;&gt; browser.url<br>
   &#39;<a href="http://localhost/app" target="_blank">http://localhost/app</a>&#39;<br>
   &gt;&gt;&gt; browser.headers.get(&#39;Status&#39;).upper()<br>
   &#39;200 OK&#39;<br>
<br>
Try to reach an instance of SomeForeignModel using the TrajectForSomeForeignModel Traject. THIS IS FAILING:<br>
<br>
    &gt;&gt;&lt; browser.open(&#39;<a href="http://localhost/app/foreigners/:funnyname" target="_blank">http://localhost/app/foreigners/:funnyname</a>&#39;)<br>
    &gt;&gt;&lt; browser.headers.get(&#39;Status&#39;).upper()<br>
    &#39;200 OK&#39;<br>
<br>
<br>
Perhaps because the url shouldn&#39;t include &#39;:&#39;?<br>
THIS IS FAILING:<br>
<br>
<br>
    &gt;&gt;&lt; browser.open(&#39;<a href="http://localhost/app/foreigners/funnyname" target="_blank">http://localhost/app/foreigners/funnyname</a>&#39;)<br>
    &gt;&gt;&lt; browser.headers.get(&#39;Status&#39;).upper()<br>
    &#39;200 OK&#39;<br>
<br>
Or perhaps simply because SomeForeignModel is not a view?<br>
<br>
<br>
<br>
<br>
<br>_______________________________________________<br>
Grok-dev mailing list<br>
<a href="mailto:Grok-dev@zope.org">Grok-dev@zope.org</a><br>
<a href="https://mail.zope.org/mailman/listinfo/grok-dev" target="_blank">https://mail.zope.org/mailman/listinfo/grok-dev</a><br>
<br></blockquote></div><br>