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
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}
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]
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
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
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"
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()
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
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]
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()
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]
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 package(self, namespace, app): package = Package(name='Dog Bog', namespace=namespace) package.save() return package