Example #1
0
 def test_restricted_getURLForDownload(self):
     # The RestrictedLibrarianClient should use the
     # restricted_download_host and restricted_download_port, but is
     # otherwise identical to the behaviour of the LibrarianClient discussed
     # and demonstrated above.
     #
     # (Set up:)
     client = RestrictedLibrarianClient()
     alias_id = client.addFile('sample.txt', 6, StringIO('sample'),
                               'text/plain')
     config.push(
         'test config',
         textwrap.dedent('''\
             [librarian]
             restricted_download_host: example.com
             restricted_download_port: 5678
             '''))
     try:
         # (Test:)
         # The LibrarianClient should use the download_host and
         # download_port.
         expected_host = 'http://example.com:5678/'
         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
             RestrictedLibrarianClient._getURLForDownload)
         self.assertEqual(call(client, alias_id), None)
     finally:
         # (Tear down:)
         config.pop('test config')
Example #2
0
 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')
Example #3
0
 def test_restricted_getURLForDownload(self):
     # The RestrictedLibrarianClient should use the
     # restricted_download_host and restricted_download_port, but is
     # otherwise identical to the behavior of the LibrarianClient discussed
     # and demonstrated above.
     #
     # (Set up:)
     client = RestrictedLibrarianClient()
     alias_id = client.addFile("sample.txt", 6, StringIO("sample"), "text/plain")
     config.push(
         "test config",
         textwrap.dedent(
             """\
             [librarian]
             restricted_download_host: example.com
             restricted_download_port: 5678
             """
         ),
     )
     try:
         # (Test:)
         # The LibrarianClient should use the download_host and
         # download_port.
         expected_host = "http://example.com:5678/"
         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(RestrictedLibrarianClient._getURLForDownload)  # Prevent a ProgrammingError
         self.assertEqual(call(client, alias_id), None)
     finally:
         # (Tear down:)
         config.pop("test config")
Example #4
0
 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")