Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
slint committed Feb 6, 2024
1 parent 17d18bf commit 3d312a7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def parse_pid(self, value):
return value
try:
return UUID(value)
except (TypeError, ValueError) as e:
except (TypeError, ValueError):
return value

def resolve(self, pid_value, registered_only=True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,13 @@ def __get__(self, record, owner=None):
if record is None:
return self._context_cls(self, owner)
return self.obj(record)

def post_dump(self, record, data, dumper=None):
"""Dump the communities field."""
comms = getattr(record, self.attr_name)
res = comms.to_dict()
res["entries"] = [
# TODO: Only keep fields we want to dump
comm.dumps() for comm in comms
]
data[self.key] = res
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ def __iter__(self):
# Iterate (sort by identifier to ensure consistent results)
return (self._communities_cache[c] for c in sorted(self._communities_ids))

def __getitem__(self, community_id):
"""Get a community by ID."""
if community_id in self._communities_cache:
return self._communities_cache[community_id]
return self._lookup_community(self._to_id(community_id))

@property
def ids(self):
"""Get communities ids."""
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,8 @@ def fake_communities(
community_type_record,
community_types,
):
"""Fake Communities."""
data = deepcopy(minimal_community)
"""Multiple community created and posted to test search functionality."""
data = deepcopy(minimal_community)
N = 4

for type_, ind in itertools.product(community_types, list(range(N))):
Expand Down

0 comments on commit 3d312a7

Please sign in to comment.