Skip to content

Commit

Permalink
fix: record value after save
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Nov 8, 2023
1 parent de9e7ae commit 8b7e59a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 17 deletions.
19 changes: 19 additions & 0 deletions oid4vci/oid4vci/v1_0/models/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ def exchange_id(self) -> str:
"""Accessor for the ID associated with this exchange record."""
return self._id

@property
def record_value(self) -> dict:
"""Return dict representation of the exchange record for storage."""
return {
prop: getattr(self, prop)
for prop in (
"supported_cred_id",
"credential_subject",
"nonce",
"pin",
"code",
"token",
)
}


class OID4VCIExchangeRecordSchema(BaseRecordSchema):
"""OID4VCI Exchange Record Schema."""
Expand All @@ -58,6 +73,10 @@ class Meta:

model_class = OID4VCIExchangeRecord

exchange_id = fields.Str(
required=False,
description="Exchange identifier",
)
supported_cred_id = fields.Str(
required=True,
metadata={
Expand Down
8 changes: 8 additions & 0 deletions oid4vci/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

from aries_cloudagent.core.in_memory import InMemoryProfile


@pytest.fixture
async def profile():
yield InMemoryProfile.test_profile()
17 changes: 0 additions & 17 deletions oid4vci/tests/models/test_cred_ex_record.py

This file was deleted.

29 changes: 29 additions & 0 deletions oid4vci/tests/models/test_exchange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from aries_cloudagent.core.profile import Profile
import pytest
from oid4vci.v1_0.models.exchange import OID4VCIExchangeRecord


@pytest.fixture
def record():
yield OID4VCIExchangeRecord(
supported_cred_id="456",
credential_subject={"name": "alice"},
nonce="789",
pin="000",
code="111",
token="222",
)


def test_serde(record: OID4VCIExchangeRecord):
serialized = record.serialize()
deserialized = OID4VCIExchangeRecord.deserialize(serialized)
assert record == deserialized


@pytest.mark.asyncio
async def test_save(profile: Profile, record: OID4VCIExchangeRecord):
async with profile.session() as session:
await record.save(session)
loaded = await OID4VCIExchangeRecord.retrieve_by_id(session, record.exchange_id)
assert loaded == record

0 comments on commit 8b7e59a

Please sign in to comment.