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