I'm trying to use mock to test parts of my trac plug-in.

If I try something like:

    def test_process_request(self):
        """ Test the process_request method """

        with patch('trac.web.api.Request', return_value=None) as mock_req:
            mock_req.method = 'POST'
            mock_req.args.base_path = 'mybasepath:port'
            mock_req.args.project = 'proj'
            mock_req.args.milestone = 'ms1'

            with patch('trac.web.api.Request.redirect') as mock_redirect:
                mock_redirect.return_value = '?project=proj&milestone=ms1'

self.assertEqual(MyPluginClass.process_request(ComponentManager(),
trac.web.api.Request(EnvironmentStub(), None)),
                                 'mybasepath:port?project=proj&milestone=ms1',
                                 'POST triggers redirect')

I get the error message:
TypeError: unbound method process_request() must be called with
MyPluginClass instance as first argument (got ComponentManager
instance instead)

If I change the assertion to:


self.assertEqual(MyPluginClass.process_request(MyPluginClass(),
trac.web.api.Request(EnvironmentStub(), None)),
                                 'mybasepath:port?project=proj&milestone=ms1',
                                 'POST triggers redirect')

I get:
AssertionError: First argument must be a ComponentManager instance

How can I do this?

Regards

Jeff

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/d/optout.

Reply via email to