resources.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright 2008, 2011 Canonical Ltd.
  2. # This file is part of launchpadlib.
  3. #
  4. # launchpadlib is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Lesser General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # launchpadlib is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public
  15. # License along with launchpadlib. If not, see
  16. # <http://www.gnu.org/licenses/>.
  17. """Resources for use in unit tests with the C{testresources} module."""
  18. from pkg_resources import resource_string
  19. from testresources import TestResource
  20. from wadllib.application import Application
  21. from launchpadlib.testing.launchpad import FakeLaunchpad
  22. launchpad_testing_application = None
  23. def get_application():
  24. """Get or create a WADL application for testing Launchpad.
  25. Note that this uses the Launchpad v1.0 WADL bundled with launchpadlib for
  26. testing purposes. For your own application, you might want to construct
  27. an L{Application} object directly, giving it your own WADL.
  28. """
  29. global launchpad_testing_application
  30. if launchpad_testing_application is None:
  31. markup_url = "https://api.launchpad.net/1.0/"
  32. markup = resource_string("launchpadlib.testing", "launchpad-wadl.xml")
  33. launchpad_testing_application = Application(markup_url, markup)
  34. return launchpad_testing_application
  35. class FakeLaunchpadResource(TestResource):
  36. def make(self, dependency_resources):
  37. return FakeLaunchpad(
  38. application=Application(
  39. "https://api.example.com/testing/",
  40. resource_string("launchpadlib.testing", "testing-wadl.xml"),
  41. )
  42. )