ncoronado / tracshell

Automatically exported from code.google.com/p/tracshell
1 stars 0 forks source link

Testunits: Trac server mock #28

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
We need test units, dearly. The code will quickly get to a point where fixing a 
bug introduces, or re-
introduce (even worse), two new ones.

However, before coding the first test, some upfront work has to be done, 
namely, mock a Trac 
server. Once we have that, it will be easy to just send some commands and test 
the output. I 
haven't given deep thoughts about how to create the mock server (should we use 
a mock library? 
which one?), but I open this ticket so a dicussion can be started.

Original issue reported on code.google.com by hsoft@hardcoded.net on 6 Apr 2009 at 3:50

GoogleCodeExporter commented 8 years ago

Original comment by hsoft@hardcoded.net on 6 Apr 2009 at 3:51

GoogleCodeExporter commented 8 years ago
Granted, TDD should've been the first concern but I've had problems mocking 
xml-rpc
servers from the start.

However, I've recently found an alpha-stage project on the cheeseshop called,
"dingus" which I've used to much success with other projects.

It might be worthwhile to share some updates in the server interface design 
I've been
tinkering with and possibly working on a re-write starting with a TDD 
methodology.

I'm cool w/ adding tests but I'm just throwing the idea out there.

Original comment by j.kennet...@gmail.com on 7 Apr 2009 at 1:09

GoogleCodeExporter commented 8 years ago

Original comment by j.kennet...@gmail.com on 17 Apr 2009 at 3:04

GoogleCodeExporter commented 8 years ago
Just to let you all know, I've added a functional test environment and tests to 
the trac xml-rpc plugin itself 
(based on the Trac functional suite). It will create a Trac environment with 
default data, users and 
authentication, enable xmlrpc plugin, and start a web server that answers 
requests.

You'll need both Trac and XML-RPC plugin installed from source ('python 
setup.py develop' for instance), and 
then in your own tests can just do: from tracrpc.tests import rpc_testenv

See latest trunk of xmlrpc plugin 'tests' directory - __init__.py and the 
various .py unittest files for examples.

Original comment by oddsim...@gmail.com on 27 Jun 2009 at 12:26

GoogleCodeExporter commented 8 years ago
That will be super-useful. I'll start looking into that.

Original comment by j.kennet...@gmail.com on 17 Sep 2010 at 6:51

GoogleCodeExporter commented 8 years ago
oddsimons, the RpcTestEnvironment class seems to do some hard-coded relative 
imports... any way we can work around that? I'm having trouble just importing 
the object in my environment (using virtualenv).

Original comment by j.kennet...@gmail.com on 18 Sep 2010 at 2:18

GoogleCodeExporter commented 8 years ago
I'm using virtualenv too, and it works for me in any context. You need to 
install both Trac and TracRPC in your virtualenv using 'python setup.py 
develop' so that all test classes from both of those packages are importable in 
your virtualenv.

Then you can just import it to have TracRPC create a test environment and start 
the server, and you can fire off requests as you like:

$ $VENV/bin/python
....
>>> from tracrpc.tests import rpc_testenv
...
Starting web server: http://127.0.0.1:8765

Original comment by oddsim...@gmail.com on 18 Sep 2010 at 6:46

GoogleCodeExporter commented 8 years ago
Created a fresh virtualenv, activated it, downloaded latest stable Trac 0.12 
tarball, extracted it, ran `python setup.py develop`, downloaded latest tracrpc 
from svn trunk, ran `python setup.py develop`.

Env directory looks like this:

{{{
bin/
include/
lib/
Trac-0.12/
tracshell/
xmlrpcplugin/
}}}

I fire up $VENV/bin/python and try the import:

{{{
>>> from tracrpc.tests import rpc_testenv

Found Trac source: /home/jking/Projects/Python/Environments/tshell/Trac-0.12
Enabling RPC plugin and permissions...
Created test environment: 
/home/jking/Projects/Python/Environments/tshell/xmlrpcplugin/rpctestenv
Starting web server: http://127.0.0.1:8765
'NoneType' object has no attribute 'go'
Trac test infrastructure not available.
Install Trac as 'python setup.py develop' (run Trac from source).

Stopping web server...

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name rpc_testenv
>>>
}}}

I'm assuming that I'm missing something and am hoping you could enlighten me. 
I've tried Trac from latest svn head on 0.13, svn head on 0.12, stable 
tarballs.. I keep getting the same exception.

Original comment by j.kennet...@gmail.com on 19 Sep 2010 at 4:48

GoogleCodeExporter commented 8 years ago
Ah. You need 'twill' package. In the RPC plugin setup.py, we have this code:

try :
  import crypt
except ImportError :
  test_deps = ['twill', 'fcrypt']
else :
  test_deps = ['twill']

Those dependencies will of course not be evaluated when others (like you) reuse 
the test infrastructure. We need twill at the core of the testenv as it is 
inherited from Trac.

Original comment by oddsim...@gmail.com on 19 Sep 2010 at 8:57