예제 #1
0
def upload_package():
    account = get_account()

    package_name = get_formatted_package_name()

    package = Package.find_by_name(package_name)
    if package is None:
        package = Package(package_name, False, False)
        account.packages.append(package)
        account.save()
    elif package.account != account:
        abort(403, "Invalid credentials. Please ensure that you have the right credentials")

    folder = current_app.config['PACKAGE_FOLDER']
    return PostHandler(folder, package_name).upload_package(package.allow_override)
    def render_package_information(self, package_name: str):
        package = Package.find_by_name(package_name)
        if package is None:
            return abort(404, "package does not exist in repository")

        folder = self.package_folder.joinpath(package_name)
        payload = {
            "name": package_name,
            "packages": [],
            "use_prompt": package.private and not self.is_pip,
        }

        if self.is_pip and package.private and not package.is_valid_token(
                self.token):
            return render_template('package-info.html', **payload)

        for path in folder.iterdir():
            filename = path.name
            if path.is_file() and (filename.endswith('.whl')
                                   or filename.endswith('.tar.gz')):
                filepath = path.as_posix()
                info = pkginfo.Wheel(filepath) if filename.endswith(
                    '.whl') else pkginfo.SDist(filepath)

                payload["packages"].append({
                    "link":
                    f"/simple/{package_name}/{path.name}",
                    "title":
                    path.name,
                    "requires_python":
                    info.requires_python
                })

        return render_template('package-info.html', **payload)
예제 #3
0
def test_update_package(db_session):
    pkg = Package.find_by_name(pkg1.name)
    pkg.update(allow_override=True, private=True)

    assert pkg.to_dict() == {
        "name": pkg1.name,
        "allow_override": True,
        "private": True
    }
    def send_package(self, package_name: str, filename: str):
        package = Package.find_by_name(package_name)
        if package.private and not package.is_valid_token(self.token):
            abort(
                403,
                "Not allowed to download private package without valid credentials"
            )

        return send_file(self.package_folder.joinpath(package_name,
                                                      filename).as_posix(),
                         attachment_filename=filename)
예제 #5
0
def get_project_details(project):
    p = Package.find_by_name(project)
    if p is None:
        abort(404, f"Package/project '{project}' does not exist")
    folder = PackageFolder(project)

    return {
        "name": project,
        "latest_version": folder.latest_version,
        "private": p.private,
        "projects": folder.version_info_list
    }
예제 #6
0
def _package_details(p: Package):
    folder = PackageFolder(p.name)
    return {
        **p.to_dict(True),
        "version_details": [{
            "version": v["version"],
            "release_date": v["release_date"],
            "files": v["files"],
            "count": v["count"],
        } for v in folder.version_info_list],
        "summary":
        folder.package_summary,
        "release_date":
        folder.last_upload_date,
    }
예제 #7
0
def test_add_lock():
    pkg = Package.find_by_name(pkg1.name)
    pkg.add_package_lock("random description for token")

    assert len(pkg.to_dict(True)["locks"]) == 1
예제 #8
0
def test_find_package(db_session, name, is_none):
    pkg = Package.find_by_name(name)
    if is_none:
        assert pkg is None
    else:
        assert pkg is not None
예제 #9
0
def test_delete_package_cascades(db_session):
    pkg = Package.find_by_name(pkg1.name)
    pkg.delete()

    assert len(PackageLock.query.all()
               ) == 0, "all package locks should have been removed"
예제 #10
0
import pytest
from sqlalchemy.exc import IntegrityError

from application.models import Account, Package, PackageLock

user1 = Account("test_user1", "password", "*****@*****.**")
user2 = Account("test_user2", "password", "*****@*****.**")
pkg1 = Package("package1", False, False)
pkg2 = Package("package2", False, True)


def test_create_account(db_session):
    user1.save()
    user2.save()

    assert user1.to_dict() == {
        "username": user1.username,
        "email": user1.email
    }
    assert user2.to_dict() == {
        "username": user2.username,
        "email": user2.email
    }


@pytest.mark.parametrize("username, password, email, exc", [
    ("test_user1", "password", "*****@*****.**", IntegrityError),
    ("test_user3", "password", "*****@*****.**", IntegrityError),
    ("", "password", "*****@*****.**", ValueError),
    ("test_user3", "", "*****@*****.**", ValueError),
    ("test_user3", "password", "", ValueError),
예제 #11
0
def get_project_list():
    return jsonify([p.name for p in Package.list()])