예제 #1
0
  def test_fetch_one_http_file_invalid_name(self):
    requester = FakeHttp()
    with util.temporary_directory(prefix='glyco-fetch-test-') as tempdir:
      cache = os.path.join(tempdir, 'cache')
      location = 'https://a.random.host.com/invalid_name.whl'
      install_list = [{'location': location,
                       'location_type': 'http'}]
      with self.assertRaises(ValueError):
        install.fetch_packages(
          install_list, requester=requester, cache=cache, verbose=False)

      # Still nothing in the cache
      self.assertEqual(len(os.listdir(cache)), 0)
예제 #2
0
  def test_fetch_one_http_file_http_error(self):
    requester = FakeHttp()
    with util.temporary_directory(prefix='glyco-fetch-test-') as tempdir:
      cache = os.path.join(tempdir, 'cache')
      location = ('https://a.broken.host.com/'
                  'source_package_valid_sha1-0.0.1-0_'
                  '41128a9c3767ced3ec53b89b297e0268f1338b2b-py2-none-any.whl')
      install_list = [{'location': location,
                       'location_type': 'http'}]
      with self.assertRaises(ValueError):
        install.fetch_packages(
          install_list, requester=requester, cache=cache, verbose=False)

      # Still nothing in the cache
      self.assertEqual(len(os.listdir(cache)), 0)
예제 #3
0
  def test_fetch_one_http_file_invalid_sha1(self):
    requester = FakeHttp()
    with util.temporary_directory(prefix='glyco-fetch-test-') as tempdir:
      cache = os.path.join(tempdir, 'cache')
      location = ('https://a.random.host.com/'
                  'source_package_invalid_sha1-0.0.1-0_'
                  'deadbeef3767ced3ec53b89b297e0268f1338b2b-py2-none-any.whl')
      install_list = [{'location': location,
                       'location_type': 'http'}]
      with self.assertRaises(ValueError):
        install.fetch_packages(
          install_list, requester=requester, cache=cache, verbose=False)

      # An invalid file should be deleted from the cache.
      self.assertEqual(len(os.listdir(cache)), 0)
예제 #4
0
  def test_fetch_two_files(self):
    requester = None
    with util.temporary_directory(prefix='glyco-fetch-test-') as tempdir:
      cache = os.path.join(tempdir, 'cache')
      locations = [
        os.path.join(
          DATA_DIR,
          'wheels',
          'source_package_valid_sha1-0.0.1-0_'
          '41128a9c3767ced3ec53b89b297e0268f1338b2b-py2-none-any.whl'
        ),
        os.path.join(
          DATA_DIR,
          'wheels',
          'installed_package-0.0.1-0_'
          '58a752f45f35a07c7d94149511b3af04bab11740-py2-none-any.whl'
        )
      ]

      install_list = [{'location': 'file://' + location,
                       'location_type': 'file'}
                      for location in locations]
      paths = install.fetch_packages(
        install_list, requester=requester, cache=cache, verbose=False)

      self.assertEqual(len(paths), 2)
      self.assertEqual(paths[0], locations[0])
      self.assertEqual(paths[1], locations[1])

      # The file is readily available, nothing should be copied to the cache.
      self.assertEqual(len(os.listdir(cache)), 0)
예제 #5
0
  def test_fetch_one_invalid_file(self):
    requester = None
    with util.temporary_directory(prefix='glyco-fetch-test-') as tempdir:
      cache = os.path.join(tempdir, 'cache')
      location = os.path.join(
        DATA_DIR,
        'wheels',
        'source_package_invalid_sha1-0.0.1-0_'
        'deadbeef3767ced3ec53b89b297e0268f1338b2b-py2-none-any.whl'
      )
      install_list = [{'location': 'file://' + location,
                       'location_type': 'file'}]
      with self.assertRaises(ValueError):
        install.fetch_packages(
          install_list, requester=requester, cache=cache, verbose=False)

      # The file is readily available, nothing should be copied to the cache.
      self.assertEqual(len(os.listdir(cache)), 0)
예제 #6
0
  def test_fetch_one_http_file_good(self):
    requester = FakeHttp()
    with util.temporary_directory(prefix='glyco-fetch-test-') as tempdir:
      cache = os.path.join(tempdir, 'cache')
      location = ('https://a.random.host.com/'
                  'source_package_valid_sha1-0.0.1-0_'
                  '41128a9c3767ced3ec53b89b297e0268f1338b2b-py2-none-any.whl')
      install_list = [{'location': location,
                       'location_type': 'http'}]
      paths = install.fetch_packages(
        install_list, requester=requester, cache=cache, verbose=False)

      cache_files = [os.path.join(cache, filename)
                     for filename in os.listdir(cache)]
      self.assertEqual(len(cache_files), 1)
      self.assertEqual(paths[0], cache_files[0])