def test__getURLForDownload(self): # This protected method is used by getFileByAlias. It is supposed to # use the internal host and port rather than the external, proxied # host and port. This is to provide relief for our own issues with the # problems reported in bug 317482. # # (Set up:) client = LibrarianClient() alias_id = client.addFile('sample.txt', 6, StringIO('sample'), 'text/plain') config.push( 'test config', textwrap.dedent('''\ [librarian] download_host: example.org download_port: 1234 ''')) try: # (Test:) # The LibrarianClient should use the download_host and # download_port. expected_host = 'http://example.org:1234/' download_url = client._getURLForDownload(alias_id) self.assertTrue( download_url.startswith(expected_host), 'expected %s to start with %s' % (download_url, expected_host)) # If the alias has been deleted, _getURLForDownload returns None. lfa = LibraryFileAlias.get(alias_id) lfa.content = None call = block_implicit_flushes( # Prevent a ProgrammingError LibrarianClient._getURLForDownload) self.assertEqual(call(client, alias_id), None) finally: # (Tear down:) config.pop('test config')
def test__getURLForDownload(self): # This protected method is used by getFileByAlias. It is supposed to # use the internal host and port rather than the external, proxied # host and port. This is to provide relief for our own issues with the # problems reported in bug 317482. # # (Set up:) client = LibrarianClient() alias_id = client.addFile("sample.txt", 6, StringIO("sample"), "text/plain") config.push( "test config", textwrap.dedent( """\ [librarian] download_host: example.org download_port: 1234 """ ), ) try: # (Test:) # The LibrarianClient should use the download_host and # download_port. expected_host = "http://example.org:1234/" download_url = client._getURLForDownload(alias_id) self.failUnless( download_url.startswith(expected_host), "expected %s to start with %s" % (download_url, expected_host) ) # If the alias has been deleted, _getURLForDownload returns None. lfa = LibraryFileAlias.get(alias_id) lfa.content = None call = block_implicit_flushes(LibrarianClient._getURLForDownload) # Prevent a ProgrammingError self.assertEqual(call(client, alias_id), None) finally: # (Tear down:) config.pop("test config")
def _getURLForDownload(self, aliasID): self.called_getURLForDownload = True return LibrarianClient._getURLForDownload(self, aliasID)