| 1 | """ |
|---|
| 2 | test class for ComponentDependencyPlugin |
|---|
| 3 | """ |
|---|
| 4 | |
|---|
| 5 | from trac.core import * |
|---|
| 6 | from trac.web import IRequestHandler |
|---|
| 7 | |
|---|
| 8 | from componentdependencies import IRequireComponents |
|---|
| 9 | |
|---|
| 10 | __all__ = [ 'FooBarTest', 'TestDependencyPlugin', ] |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | class FooBarTest(Component): |
|---|
| 14 | |
|---|
| 15 | def foobar(self): |
|---|
| 16 | return "hello world" |
|---|
| 17 | |
|---|
| 18 | class TestDependencyPlugin(Component): |
|---|
| 19 | |
|---|
| 20 | implements(IRequestHandler, IRequireComponents) |
|---|
| 21 | |
|---|
| 22 | ### methods for IRequestHandler |
|---|
| 23 | |
|---|
| 24 | def match_request(self, req): |
|---|
| 25 | """Return whether the handler wants to process the given request.""" |
|---|
| 26 | return req.path_info == '/hello-world' |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | def process_request(self, req): |
|---|
| 30 | """Process the request. For ClearSilver, return a (template_name, |
|---|
| 31 | content_type) tuple, where `template` is the ClearSilver template to use |
|---|
| 32 | (either a `neo_cs.CS` object, or the file name of the template), and |
|---|
| 33 | `content_type` is the MIME type of the content. For Genshi, return a |
|---|
| 34 | (template_name, data, content_type) tuple, where `data` is a dictionary |
|---|
| 35 | of substitutions for the template. |
|---|
| 36 | |
|---|
| 37 | For both templating systems, "text/html" is assumed if `content_type` is |
|---|
| 38 | `None`. |
|---|
| 39 | |
|---|
| 40 | Note that if template processing should not occur, this method can |
|---|
| 41 | simply send the response itself and not return anything. |
|---|
| 42 | """ |
|---|
| 43 | foobar = FooBarTest(self.env) |
|---|
| 44 | req.send(foobar.foobar(), "text/plain") |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | ### methods for IRequireComponents |
|---|
| 48 | |
|---|
| 49 | def requires(self): |
|---|
| 50 | return [ FooBarTest ] |
|---|