def ensure_proxy_checks_if_package_is_already_cached(temp_dir): temp_dir.create_directory("packages") proxy_package_index = ProxyPackageIndex( "cached", temp_dir.join("packages"), "http://pypi.python.org") proxy_package_index._package_index = mock() when(proxy_package_index._package_index).contains( any_value(), any_value()).thenReturn(True) proxy_package_index.get_package_content("pyassert", "0.2.5") verify(proxy_package_index._package_index).contains("pyassert", "0.2.5")
def ensure_proxy_gets_package_content_from_pypi_if_it_is_not_cached(temp_dir): temp_dir.create_directory("packages") proxy_package_index = ProxyPackageIndex( "cached", temp_dir.join("packages"), "http://pypi.python.org") proxy_package_index._package_index = mock() package_content = mock() when(proxy_package_index)._fetch_url( any_value(), raw=any_value()).thenReturn(package_content) when(proxy_package_index._package_index).contains( any_value(), any_value()).thenReturn(False) when(proxy_package_index._package_index).get_package_content( any_value(), any_value()).thenReturn(package_content) actual_package = proxy_package_index.get_package_content( "pyassert", "0.2.5") assert_that(actual_package).is_equal_to(package_content) verify(proxy_package_index)._fetch_url( "http://pypi.python.org/packages/source/p/pyassert/pyassert-0.2.5.tar.gz", raw=True) verify(proxy_package_index._package_index).add_package( "pyassert", "0.2.5", package_content) verify(proxy_package_index._package_index).get_package_content( "pyassert", "0.2.5")