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])
def test_package_versions_are_unique(self, app): n = Namespace(name='Hello') p = Package(name='Dog Bog', namespace=n) assert p.versions.all() == [] v1 = PackageVersion(package=p, version='1.0.0', local='C:/dog-bog') v1.save() assert p.versions.all() == [v1] with pytest.raises(sqlalchemy.exc.IntegrityError): v2 = PackageVersion(package=p, version='1.0.0', local='C:/dog-bog') v2.save() app.db.session.rollback() assert p.versions.all() == [v1]
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)
def test_packages_get_slug(self, app): n = Namespace(name='Hello') p = Package(name='Dog Bog', namespace=n) assert p.slug == 'dog-bog' # slug is set BEFORE commit p.save() assert p.slug == 'dog-bog' # slug is set AFTER commit
def namespace(self, app): return Namespace(name='Hello').save()