__init__.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. #
  3. # This file is part of Radicale Server - Calendar Server
  4. # Copyright © 2012 Guillaume Ayoub
  5. #
  6. # This library is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. Tests for Radicale.
  20. """
  21. import os
  22. import sys
  23. sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
  24. import radicale
  25. class BaseTest(object):
  26. """Base class for tests."""
  27. def setup(self):
  28. """Setup function for each test."""
  29. self.application = radicale.Application()
  30. def teardown(self):
  31. """Teardown function for each test."""
  32. def request(self, method, path, **args):
  33. """Send a request."""
  34. self.application._status = None
  35. self.application._headers = None
  36. self.application._answer = None
  37. for key in args:
  38. args[key.upper()] = args[key]
  39. args["REQUEST_METHOD"] = method.upper()
  40. args["PATH_INFO"] = path
  41. self.application._answer = self.application(args, self.start_response)
  42. return (
  43. int(self.application._status.split()[0]),
  44. dict(self.application._headers),
  45. self.application._answer[0].decode("utf-8"))
  46. def start_response(self, status, headers):
  47. """Put the response values into the current application."""
  48. self.application._status = status
  49. self.application._headers = headers