/tests/web/test_web_task.py

https://bitbucket.org/prologic/circuits/ · Python · 30 lines · 18 code · 10 blank · 2 comment · 0 complexity · 3a5750992c3a5c3e0e7b57f05860973a MD5 · raw file

  1. #!/usr/bin/env python
  2. import os
  3. from circuits.web import Controller
  4. from circuits import Event, Component
  5. from .helpers import urlopen
  6. class Hello(Event):
  7. """Hello Event"""
  8. class Root(Controller):
  9. def index(self):
  10. return self.fire(Hello(os.getpid()))
  11. class Task(Component):
  12. def hello(self, pid):
  13. return "Hello %d i'm %d" % (pid, os.getpid())
  14. def test(webapp):
  15. t = Task()
  16. t.start(link=webapp, process=True)
  17. f = urlopen(webapp.server.base)
  18. s = f.read()
  19. assert s.decode() == "Hello %d i'm %d" % (os.getpid(), t._proc.pid)
  20. t.stop()