Example #1
0
def route_create_namespace(namespace):
    namespace_slug = slugify(namespace)
    existing = Namespace.get(namespace_slug)

    if existing is not None:
        raise NamespaceAlreadyExistsErrorResponse(namespace)

    namespace = Namespace(name=namespace).save()

    return namespace_schema.jsonify(namespace)
Example #2
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])
Example #3
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])
Example #4
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]
Example #5
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()
Example #6
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]
Example #7
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]
Example #8
0
def get_namespace(namespace_slug):
    match = Namespace.get(namespace_slug)

    if match is None:
        raise NamespaceNotFoundErrorResponse(namespace_slug)

    return match
Example #9
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
Example #10
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]
Example #11
0
    def test_create_namespace(self, app, client):
        name = "Dog Gone Shame"
        response = client.post(f"/api/v1/namespaces/{name}/")
        assert response.status_code == 200

        match = Namespace.get(name=name)
        assert match is not None
        assert match.slug == 'dog-gone-shame'
Example #12
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}
Example #13
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
Example #14
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()
Example #15
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
Example #16
0
def route_delete_namespace(namespace):
    match = Namespace.get(namespace)

    if match is None:
        raise NamespaceNotFoundErrorResponse(namespace)

    match.delete(commit=True)

    return success()
Example #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
Example #18
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"
Example #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
Example #20
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
Example #21
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
Example #22
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
Example #23
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
Example #24
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 == []
Example #25
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
Example #26
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)
Example #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()
Example #28
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'
Example #29
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]
Example #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