I've made it running with the following: - provide a runmode (via request.env) in shell when running the doctests - in admin/models/access.py assume being authorised when running in the given runmode - skip the direct redirects at the end of admin/models/access.py (the redirect is also done in the index function) - handle the redirect in admin/controllers/gae.py when not running on unix by just exiting when in the given runmode
There are two things that make running doctests on the admin app choke: [1] the original error was generated by the port not being properly set in the request.env (a default IS set for request.env.http_host = '127.0.0.1:8000'). The only reason the port is being looked up is because it needs the password, which is normally being stored in a file name containing the port number. Since we are running doctests from the commandline this hsould be fine to assume we are authorised to do so... [2] redirects in code that is being executed directly (not enclosed in a function) There seems to be no need to further enhance the request.env when running the doctests from the command line Since in admin special stuff is done and executed directly on calling the file, we need a way to detect if it is needed / must be done differently when running the doctest. This is the case for: - validating that running adminis allowed - redirecting to another url (currently needed for index -> site, and bouncing gae on windows) On Sun, Jul 19, 2009 at 12:06, Hans Donner<[email protected]> wrote: > Well, I'm going to find out what is missing first. > Based on that we can see what the best approach is. > > On Sun, Jul 19, 2009 at 11:13, mdipierro<[email protected]> wrote: >> >> Let's brainstrom this before you code it. How should the testing >> function know what is the environment you want to test? For example >> the env variables are different if you use wsgi or fcgi. The app may >> know what the expected env variables are (assuming the developer >> knows), but the testing function cannot know this. >> >> On Jul 19, 2:27 am, Hans Donner <[email protected]> wrote: >>> So, seeing from the code I should improve gluon.shell.test to setup a >>> request.env (I'd rather not do it in the app itself) >>> >>> On Sun, Jul 19, 2009 at 08:55, mdipierro<[email protected]> wrote: >>> >>> > We could but that is not so much the issue here. The issue here admin >>> > request an environment. A test does not provide a default environment. >>> >>> > If you want to test admin we should add >>> >>> > if not request.env: >>> > request.env=Storage({....}) >>> >>> > and fill the ... >>> >>> > Massimo >>> >>> > On Jul 19, 1:42 am, Hans Donner <[email protected]> wrote: >>> >> Perhaps we should have a setting indicatin if we are running in >>> >> doctest mode, like we now have a gae mode. >>> >> That way we can safely work around it. Or we can assume we are in such >>> >> mode if some paramaters are empty, but that does not feel right. >>> >>> >> On Sun, Jul 19, 2009 at 01:35, mdipierro<[email protected]> wrote: >>> >>> >> > admin cannot be tested this way because assumes a request.env. >>> >> > request.env is empty when testing. >>> >>> >> > On Jul 18, 5:57 pm, Hans Donner <[email protected]> wrote: >>> >> >> when running: >>> >>> >> >> > python web2y.py --test=admin >>> >>> >> >> I get the tollowing output: >>> >>> >> >> Traceback (most recent call last): >>> >> >> File "E:\dev\web2py\web2py\dev-tests\web2py\gluon\restricted.py", >>> >> >> line 178, in >>> >> >> restricted >>> >> >> exec ccode in environment >>> >> >> File "applications\admin\models/access.py", line 27, in <module> >>> >> >> port = int(request.env.server_port) >>> >> >> TypeError: int() argument must be a string or a number, not 'NoneType' >>> >>> >> >> also when I explictly give --port=8000 >>> >>> >> >> In the try..except I can try to catch it with except TypeError, but >>> >> >> then what? >>> >>> >> >> (welcome and examples are running fine like this) >> >> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" 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/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

