Module dexa_sdk.storage.records.tests.test_base_record
Expand source code
from asynctest import TestCase as AsyncTestCase
from asynctest import mock as async_mock
from aries_cloudagent.messaging.models.base import BaseModel, BaseModelSchema
from aries_cloudagent.storage.record import StorageRecord
from marshmallow import fields, EXCLUDE
from ..base_record import BaseRecord
class MockModel(BaseModel):
"""Mock model for testing."""
class Meta:
# Schema class
schema_class = "MockSchema"
def __init__(self, *, mock_field: str, **kwargs):
"""Initialise the mock model
Args:
mock_field (str): mock field description
"""
# Call the parent constructor
super().__init__(**kwargs)
# Set model attributes
self.mock_field = mock_field
class MockSchema(BaseModelSchema):
class Meta:
# Model class
model_class = "MockModel"
# Exclude unknown fields
unknown = EXCLUDE
# Mock field
mock_field = fields.Str()
class TestBaseRecord(AsyncTestCase):
"""Test base record"""
def setUp(self) -> None:
self.mock_model = MockModel(mock_field="mock field value")
def test_base_record_value(self) -> None:
"""Test base record value to be persisted in storage"""
base_record = BaseRecord(
record_model=self.mock_model,
record_type="mock",
record_tags={"mock tag": "mock tag value"},
)
assert base_record.value.get("mock_field") is not None
assert base_record.get_tag_map().get("mock tag") is not None
assert base_record.get_tag_map().get("mock tag") == "~mock tag"
assert (
base_record.prefix_tag_filter({"mock tag": "some value"}).get("~mock tag")
is not None
)
assert isinstance(base_record.storage_record, StorageRecord)
Classes
class MockModel (*, mock_field: str, **kwargs)
-
Mock model for testing.
Initialise the mock model
Args
mock_field
:str
- mock field description
Expand source code
class MockModel(BaseModel): """Mock model for testing.""" class Meta: # Schema class schema_class = "MockSchema" def __init__(self, *, mock_field: str, **kwargs): """Initialise the mock model Args: mock_field (str): mock field description """ # Call the parent constructor super().__init__(**kwargs) # Set model attributes self.mock_field = mock_field
Ancestors
- aries_cloudagent.messaging.models.base.BaseModel
- abc.ABC
Class variables
var Meta
class MockSchema (*args, **kwargs)
-
BaseModel schema.
Initialize BaseModelSchema.
Raises
TypeError
- If model_class is not set on Meta
Expand source code
class MockSchema(BaseModelSchema): class Meta: # Model class model_class = "MockModel" # Exclude unknown fields unknown = EXCLUDE # Mock field mock_field = fields.Str()
Ancestors
- aries_cloudagent.messaging.models.base.BaseModelSchema
- marshmallow.schema.Schema
- marshmallow.base.SchemaABC
Class variables
var Meta
var opts
class TestBaseRecord (methodName='runTest')
-
Test base record
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
Expand source code
class TestBaseRecord(AsyncTestCase): """Test base record""" def setUp(self) -> None: self.mock_model = MockModel(mock_field="mock field value") def test_base_record_value(self) -> None: """Test base record value to be persisted in storage""" base_record = BaseRecord( record_model=self.mock_model, record_type="mock", record_tags={"mock tag": "mock tag value"}, ) assert base_record.value.get("mock_field") is not None assert base_record.get_tag_map().get("mock tag") is not None assert base_record.get_tag_map().get("mock tag") == "~mock tag" assert ( base_record.prefix_tag_filter({"mock tag": "some value"}).get("~mock tag") is not None ) assert isinstance(base_record.storage_record, StorageRecord)
Ancestors
- asynctest.case.TestCase
- unittest.case.TestCase
Methods
def setUp(self) ‑> None
-
Hook method for setting up the test fixture before exercising it.
Expand source code
def setUp(self) -> None: self.mock_model = MockModel(mock_field="mock field value")
def test_base_record_value(self) ‑> None
-
Test base record value to be persisted in storage
Expand source code
def test_base_record_value(self) -> None: """Test base record value to be persisted in storage""" base_record = BaseRecord( record_model=self.mock_model, record_type="mock", record_tags={"mock tag": "mock tag value"}, ) assert base_record.value.get("mock_field") is not None assert base_record.get_tag_map().get("mock tag") is not None assert base_record.get_tag_map().get("mock tag") == "~mock tag" assert ( base_record.prefix_tag_filter({"mock tag": "some value"}).get("~mock tag") is not None ) assert isinstance(base_record.storage_record, StorageRecord)