def test_add_package_exists(): pkg1 = Package("test-0.0.1", ["foo"]) pkg2 = Package("test-0.0.1", ["bar"]) index = Index([pkg1]) with pytest.raises(gcspypiError): index.add_package(pkg2)
def test_add_package(): pkg1 = Package("test-0.0.1", ["foo"]) pkg2 = Package("test-0.0.2", ["bar"]) index = Index([pkg1]) index.add_package(pkg2) assert index.packages == {pkg1, pkg2}
def test_add_package_force(): pkg1 = Package("test-0.0.1", ["foo"]) pkg2 = Package("test-0.0.1", ["bar"]) index = Index([pkg1]) index.add_package(pkg2, force=True) assert len(index.packages) == 1 assert next(iter(index.packages)).files == {"foo", "bar"}
def create_and_upload_package(args): package = Package.create(args.wheel, args.sdist, args.dist_path) storage = GCSStorage( args.bucket, args.secret, args.bare, args.private, args.profile ) index = storage.get_index(package) index.add_package(package, args.force) storage.put_package(package, args.dist_path) storage.put_index(package, index)
def test_secret_in_gcs_key(secret): from google.cloud import storage storage_client = mock.create_autospec(storage.Client) mock_bucket = mock.create_autospec(storage.Bucket) mock_blob = mock.create_autospec(storage.Blob) mock_bucket.return_value = mock_blob bucket_mock = MagicMock(spec=mock_bucket) name = PropertyMock(return_value="gcs_pypi-test") type(bucket_mock).name = name bucket_mock.get_blob.return_value = MagicMock(key=[secret]) storage_client.get_bucket.return_value = bucket_mock bucket_mock.reload = MagicMock() mock_bucket.get_blob.return_value = mock_blob with patch("google.cloud.storage.Client", return_value=storage_client): storage = GCSStorage("appstrakt-pypi", secret) package = Package("test-0.1.0", []) assert secret in storage._object(package, "index.html").key assert storage.acl == "publicRead"
def test_find_wheel_name(bdist_wheel_output): stdout, expected_name = bdist_wheel_output assert Package._find_wheel_name(stdout) == expected_name
def test_directory_normalize_package_name(): pkg = Package("company.test-0.0.1", ["foo"]) assert pkg.directory == "company-test"
def test_find_name_from_wheel_metadata(wheel_metadata): metadata, expected_name = wheel_metadata assert Package._find_name_from_wheel_metadata(metadata) == expected_name
@pytest.fixture(scope="function", params=["hello-world-0.1.0"]) def wheel_metadata(request): with open(os.path.join("tests", "data", "wheel_metadata", request.param)) as f: yield f.read(), request.param @pytest.fixture( scope="function", params=[( "gcs_pypi", { Package( "gcs_pypi-" + v, {"gcs_pypi-%s.tar.gz" % v, "gcs_pypi-%s-py2-none-any.whl" % v}, ) for v in ( "0", "0!0", "0+local", "0.0", "0.1.1", "0.1.2", "0.dev0", "0.post0", "0a0", "0rc0", ) },