Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions henry/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@


class CollectionInstance(BaseModel):
collection_id: str | None

pass


Expand Down Expand Up @@ -159,7 +161,7 @@ def _upload(
return self.colleciton_id

if not skip_preflight:
# This runs _all_ preflight checks - for all connected collecitons and products.
# This runs _all_ preflight checks - for all connected collections and products.
self.preflight()

self.collection_id = collections.create(
Expand Down Expand Up @@ -295,7 +297,7 @@ def pull(
)

@classmethod
def read(cls, directory: Path | str, allow_incomplete: bool) -> "RemoteProduct":
def read(cls, directory: Path | str, allow_incomplete: bool) -> "RemoteCollection":
"""
Read a collection that was serialized to disk, usually with the
`henry collection download $ID` command.
Expand Down Expand Up @@ -493,7 +495,9 @@ def _upload(
)

product_ids_to_connect = [
p.id for p in self.products if p.id not in self.original_product_ids
p.product_id
for p in self.products
if p.product_id not in self.original_product_ids
]

for product_id in product_ids_to_connect:
Expand All @@ -515,7 +519,9 @@ def _upload(

# Recurse!
child_collection_ids_to_connect = [
c.id for c in self.collections if c.id not in self.original_collection_ids
c.collection_id
for c in self.collections
if c.collection_id not in self.original_collection_ids
]

for collection_id in child_collection_ids_to_connect:
Expand Down
8 changes: 5 additions & 3 deletions henry/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from hippometa import ALL_METADATA_TYPE

from .collection import CollectionInstance, LocalCollection, RemoteCollection
from .product import LocalProduct, ProductInstance, RemoteProduct
from .product import LocalProduct, ProductInstance, RemoteProduct, RevisionProduct


class Henry:
Expand Down Expand Up @@ -66,7 +66,9 @@ def new_collection(
)

def push(
self, item: LocalProduct | LocalCollection, skip_preflight: bool = False
self,
item: LocalProduct | LocalCollection | RevisionProduct | RemoteCollection,
skip_preflight: bool = False,
) -> str:
return item._upload(
client=self.client,
Expand Down Expand Up @@ -99,7 +101,7 @@ def pull_collection(
collection_id: str,
realize_sources: bool = True,
pull_children: bool = True,
) -> CollectionInstance:
) -> RemoteCollection:
return RemoteCollection.pull(
collection_id=collection_id,
client=self.client,
Expand Down
2 changes: 2 additions & 0 deletions henry/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@


class ProductInstance(BaseModel):
product_id: str | None

pass

def _upload(
Expand Down
2 changes: 1 addition & 1 deletion hippoclient/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ClientSettings(BaseSettings):
@classmethod
def settings_customise_sources(
cls,
settings_cls: BaseSettings,
settings_cls: type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ hipposerve = ["web/static/*.svg", "web/static/*.ico", "web/static/*.png", "web/t
[project]
name = "pyhippo"
description = "The Hierarchical Product Post Office, developed for the Simons Observatory."
version = "0.2.9"
version = "0.2.10"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
Expand Down
8 changes: 8 additions & 0 deletions tests/test_client/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytest

from henry.core import ClientSettings, Henry
from hippoclient.caching import Cache


Expand All @@ -19,3 +20,10 @@ def cache(tmp_path):

for id in cache.complete_id_list:
cache._remove(id)


@pytest.fixture
def client(server):
client = Henry(settings=ClientSettings(host=server["url"], verbose=True))

yield client
53 changes: 53 additions & 0 deletions tests/test_client/test_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
Tests for collection uploads.
"""

from pytest import fixture

from henry import Henry
from hippoclient.collections import delete as delete_collection
from hippoclient.product import delete as delete_product
from hippometa import SimpleMetadata


@fixture
def collection_id(client: Henry):
collection = client.new_collection(
name="Test Collection A", description="A test collection for you to use!"
)

client.push(collection)

yield collection.collection_id

delete_collection(id=str(collection.collection_id), client=client.client)


def test_create_collection(collection_id):
print(collection_id)


def test_add_product_to_existing_collection(collection_id, client: Henry):
coll = client.pull_collection(
collection_id, realize_sources=False, pull_children=True
)

product = client.new_product(
name="Test Product",
description="Test product to be added as a collection member after the fact",
metadata=SimpleMetadata(),
sources={},
)

coll.append(product)
client.push(coll)

product_id = str(product.product_id)

re_read_coll = client.pull_collection(
collection_id, realize_sources=True, pull_children=True
)

assert re_read_coll.products[0].product_id == product_id

delete_product(client=client.client, id=product_id)
Loading