Пример #1
0
    def test_namespace_list_packages(self, app):
        n = Namespace(name='Hello').save()
        assert n.packages.all() == []

        p = Package(name='Dog Bog', namespace=n)
        p.save()

        assert n.packages.all() == [p]
Пример #2
0
    def test_lookup_path(self, app):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog', namespace=n)
        p.save()

        expected_path = 'hello/dog-bog'

        assert Package.lookup_path(expected_path) == p
Пример #3
0
    def test_get_all_packages(self, app, client):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog', namespace=n)
        p.save()

        response = client.get(f"/api/v1/namespaces/{n.slug}/")
        assert response.status_code == 200
        assert response.json[0] == {"name": p.name, "path": p.path}
Пример #4
0
    def test_package_path(self, app):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog', namespace=n)

        expected_path = 'hello/dog-bog'

        assert p.path == expected_path
        p.save()
        assert p.path == expected_path
Пример #5
0
    def test_get_single_version_when_version_does_not_exist_returns_404(
            self, app, client):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog', namespace=n)
        p.save()

        response = client.get(f"/api/v1/namespaces/{n.slug}/{p.slug}/1.0.03")
        assert response.status_code == 404
        assert response.json['errors'][0]['status'] == 404
        assert response.json['errors'][0]['title'] == "Version Not Found"
Пример #6
0
    def test_suites_have_packages(self, app):
        n1 = Namespace(name='Hello')
        p1 = Package(name='Dog Bog', namespace=n1)

        n2 = Namespace(name='Bello')
        p2 = Package(name='Trog Mog', namespace=n2)
        s = Suite(name='Everything', packages=[p1, p2])
        s.save()

        assert set(s.packages) == set([p1, p2])
Пример #7
0
    def test_query_packages_belonging_to_suite(self, app):
        n1 = Namespace(name='Hello')
        p1 = Package(name='Dog Bog', namespace=n1)

        n2 = Namespace(name='Bello')
        p2 = Package(name='Trog Mog', namespace=n2)
        s = Suite(name='Everything', packages=[p1, p2])
        s.save()

        packages = Package.query.filter(Package.suites.contains(s)).all()
        assert set(packages) == set([p1, p2])
Пример #8
0
def route_create_package(namespace, package):
    match = get_namespace(namespace)

    existing = Package.get(namespace=match, name=package)

    if existing is not None:
        package_slug = slugify(package)
        raise PackageAlreadyExistsErrorResponse(f'{namespace}/{package_slug}')

    package = Package(namespace=match, name=package).save()

    return package_schema.jsonify(package, many=True)
Пример #9
0
    def test_packages_have_suites(self, app):
        """Packages belong to suites through a backref."""
        n1 = Namespace(name='Hello')
        p1 = Package(name='Dog Bog', namespace=n1)

        n2 = Namespace(name='Bello')
        p2 = Package(name='Trog Mog', namespace=n2)
        s = Suite(name='Everything', packages=[p1, p2])
        s.save()

        assert p1.suites == [s]
        assert p2.suites == [s]
Пример #10
0
    def test_delete_namespace(self, app, client):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog', namespace=n)
        p.save()

        v = PackageVersion(package=p, version='1.0.0', local='C:/dog-bog')
        v.save()

        assert Namespace.query.count() == 1
        response = client.delete(f"/api/v1/namespaces/{n.slug}/")
        assert response.status_code == 200
        assert Namespace.query.count() == 0
Пример #11
0
    def test_append_package_after_creation(self, app):
        n1 = Namespace(name='Hello')
        p1 = Package(name='Dog Bog', namespace=n1)

        n2 = Namespace(name='Bello')
        p2 = Package(name='Trog Mog', namespace=n2)
        s = Suite(name='Everything', packages=[p1])
        s.save()

        assert s.packages == [p1]

        s.packages.append(p2)
        s.save()

        assert s.packages == [p1, p2]
Пример #12
0
    def test_delete_single_version_200_deletes_s3_file(self, app, client,
                                                       test_media_directory):
        n = Namespace(name='Hello')
        p = Package.create(name='Dog Bog', namespace=n)

        version = '1.0.0'

        bytes1 = b'not a zip'
        response = client.put(
            f"/api/v1/namespaces/{n.slug}/{p.slug}/{version}",
            data={"file": (BytesIO(bytes1), "workstation.zip")})

        assert response.status_code == 200

        v = PackageVersion.query.first()

        assert v.cubby().exists() is True

        response = client.delete(
            f"/api/v1/namespaces/{n.slug}/{p.slug}/{v.version}")
        assert response.status_code == 200

        assert PackageVersion.query.count() == 0

        assert v.cubby().exists() is False
Пример #13
0
    def test_lookup_paths(self, app):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog', namespace=n)
        p.save()

        n2 = Namespace(name='Molten')
        n2.save()
        p2 = Package(name='Dog Bog', namespace=n2)
        p2.save()

        expected_path = 'hello/dog-bog'

        assert Package.lookup_paths([expected_path]) == [p]
Пример #14
0
def get_package(namespace_slug, package_slug):
    path = f'{namespace_slug}/{package_slug}'
    match = Package.lookup_path(path)

    if match is None:
        raise PackageNotFoundErrorResponse(path)

    return match
Пример #15
0
    def test_update_suite_packages_packages_must_exist(self, app, client):
        s = Suite(name="Suite", packages=[])
        s.save()

        n = Namespace(name='Hello')
        p1 = Package(name='Dog Bog', namespace=n)
        p1.save()

        response = client.put(f"/api/v1/suites/{s.slug}/packages", json=["hello/dog-bog", "hello/mog"])

        assert response.status_code == 400
        assert s.packages == []

        response = client.put(f"/api/v1/suites/{s.slug}/packages", json=["hello/dog-bog"])

        assert response.status_code == 200
        assert s.packages == [p1]
Пример #16
0
    def test_suites_have_packages_once(self, app):
        """A package can either belong to a suite or not; it cannot belong twice."""
        n1 = Namespace(name='Hello')
        p1 = Package(name='Dog Bog', namespace=n1)

        with pytest.raises(sqlalchemy.exc.IntegrityError):
            s = Suite(name='Everything', packages=[p1, p1])
            s.save()
Пример #17
0
    def test_delete_suite(self, app, client):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog', namespace=n)
        s = Suite(name="Suite", packages=[p])
        s.save()

        response = client.delete(f"/api/v1/suites/{s.slug}/")
        assert response.status_code == 200

        assert Suite.query.count() == 0
Пример #18
0
    def test_package_duplicates_allowed_in_seperate_namespaces(self, app):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog',
                    namespace=n)

        p.save()

        n2 = Namespace(name='Yellow')
        p2 = Package(name='Dog Bog',
                     namespace=n2)

        p2.save()
Пример #19
0
    def test_package_version_local_is_pathtype(self, app):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog',
                    namespace=n)
        v = PackageVersion(package=p, version='1.0.0',
                           local='C:/dog-bog')

        assert type(v.local) is str
        v.save()
        assert type(v.local) is PosixPath
Пример #20
0
    def test_get_single_suite(self, app, client):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog', namespace=n)
        s = Suite(name="Suite", packages=[p])
        s.save()

        response = client.get(f"/api/v1/suites/{s.slug}/")
        assert response.status_code == 200
        assert response.json['packages'] == packages_schema.dump([p]).data
        assert response.json['slug'] == s.slug
Пример #21
0
    def test_update_suite_packages(self, app, client):
        s = Suite(name="Suite", packages=[])
        s.save()

        n = Namespace(name='Hello')
        p1 = Package(name='Dog Bog', namespace=n)
        p2 = Package(name='Mog', namespace=n)
        app.db.session.add(p1)
        app.db.session.add(p2)
        app.db.session.add(n)
        app.db.session.commit()

        response = client.put(f"/api/v1/suites/{s.slug}/packages", json=["hello/dog-bog", "hello/mog"])

        assert response.status_code == 200
        assert response.json['packages'] == packages_schema.dump([p1, p2]).data

        assert p1.suites == [s]
        assert p2.suites == [s]
        assert set(s.packages) == set([p1, p2])
Пример #22
0
    def test_update_suite_remove_packages(self, app, client):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog', namespace=n)
        s = Suite(name="Suite", packages=[p])
        s.save()

        assert s.packages == [p]

        response = client.put(f"/api/v1/suites/{s.slug}/packages", json=[])

        assert response.status_code == 200
        assert s.packages == []
Пример #23
0
    def test_get_all_versions(self, app, client):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog', namespace=n)
        p.save()

        response = client.get(f"/api/v1/namespaces/{n.slug}/{p.slug}/")
        assert response.status_code == 200
        assert response.json == {
            "name": p.name,
            "path": p.path,
            "versions": []
        }

        v = PackageVersion(package=p, version='1.0.0', local='C:/dog-bog')
        v.save()

        response = client.get(f"/api/v1/namespaces/{n.slug}/{p.slug}/")
        print(response.json)
        assert response.status_code == 200
        assert response.json['versions'][0]['local'] == str(v.local)
        assert response.json['versions'][0]['version'] == str(v.version)
Пример #24
0
    def test_delete_single_version_200_with_no_s3_file(self, app, client):
        n = Namespace(name='Hello')
        p = Package.create(name='Dog Bog', namespace=n)
        v = PackageVersion.create(package=p,
                                  version='1.0.0',
                                  local='C:/dog-bog')

        response = client.delete(
            f"/api/v1/namespaces/{n.slug}/{p.slug}/{v.version}")
        assert response.status_code == 200

        assert PackageVersion.query.count() == 0
Пример #25
0
    def test_package_versions_are_versiontype(self, app):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog',
                    namespace=n)

        assert p.versions.all() == []

        v = PackageVersion(package=p, version='1.0.0',
                           local='C:/dog-bog')
        assert type(v.version) is str
        v.save()
        assert type(v.version) is LooseVersion
Пример #26
0
    def test_package_lookup(self, app):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog',
                    namespace=n)

        p.save()

        assert Package.lookup("Hello", "dog bog") == p
        assert Package.lookup("Hello sop", "dog bog") is None
        assert Package.lookup("Hello", "dog nope") is None
Пример #27
0
    def test_package_duplicates_not_allowed_in_same_namespace(self, app):
        n = Namespace(name='Hello')
        p = Package(name='Dog Bog',
                    namespace=n)

        p.save()

        p2 = Package(name='Dog Bog',
                     namespace=n)

        with pytest.raises(sqlalchemy.exc.IntegrityError):
            p2.save()

        app.db.session.rollback()
Пример #28
0
    def test_get_single_version_200(self, app, client):
        n = Namespace(name='Hello')
        p = Package.create(name='Dog Bog', namespace=n)
        v = PackageVersion.create(package=p,
                                  version='1.0.0',
                                  local='C:/dog-bog')

        response = client.get(
            f"/api/v1/namespaces/{n.slug}/{p.slug}/{v.version}")
        assert response.status_code == 200

        assert response.json['local'] == str(v.local)
        assert response.json['version'] == str(v.version)
Пример #29
0
    def test_post_twice_fails(self, app, client, test_media_directory):
        n = Namespace(name='Hello')
        p = Package.create(name='Dog Bog', namespace=n)

        version = '1.0.0'

        response = client.post(
            f"/api/v1/namespaces/{n.slug}/{p.slug}/{version}",
            data={"file": (BytesIO(b"not a zip!"), "workstation.zip")})
        assert response.status_code == 200

        response = client.post(
            f"/api/v1/namespaces/{n.slug}/{p.slug}/{version}",
            data={"file": (BytesIO(b"not a zip!"), "workstation.zip")})
        assert response.status_code == 400
        assert response.json['errors'][0]['title'] == 'Version Already Exists'
Пример #30
0
    def test_put_cannot_update_package_version_version(self, app, client,
                                                       test_media_directory):
        n = Namespace(name='Hello')
        p = Package.create(name='Dog Bog', namespace=n)

        version = '1.0.0'

        bytes1 = b'not a zip'
        response = client.put(
            f"/api/v1/namespaces/{n.slug}/{p.slug}/{version}",
            data={"file": (BytesIO(bytes1), "workstation.zip")})
        assert response.status_code == 200

        response = client.put(
            f"/api/v1/namespaces/{n.slug}/{p.slug}/{version}",
            json={"version": "C:/bobo/"})
        assert response.status_code == 400