Exemple #1
0
    def test_missing_dynamic_restriction(self):
        """
        Test that compilation blows up if we did not include all restrictions in the mixin.
        """
        dynamic_item_2 = dynamic_restriction_mixin('item',
                                                   'item_metadata',
                                                   milk=MilkMetadata)

        class Breakfast2(dynamic_item_2):
            """
            What is the most important meal of the day?
            """
            _restrictions = {
                'item': R('milk', 'cereal'),
                'item_metadata': R(),
            }

        assert Breakfast2
Exemple #2
0
    def test_missing_independent_key_restriction(self):
        """
        Test the compilation check that validates if a restriction is missing.
        """
        dynamic_item_2 = dynamic_restriction_mixin('invalid',
                                                   'item_metadata',
                                                   milk=MilkMetadata,
                                                   cereal=CerealMetadata)

        class Breakfast2(dynamic_item_2):
            """
            What is the most important meal of the day?
            """
            _restrictions = {
                'item': R('milk', 'cereal'),
                'item_metadata': R(),
            }

        assert Breakfast2
Exemple #3
0
class MilkMetadata(DataObject):
    """
    Full of vitamins and minerals
    """
    _restrictions = {'flavor': R('chocolate', 'normal')}


class CerealMetadata(DataObject):
    """
    Delicious.
    """
    _restrictions = {'brand': R('frosted-flakes', 'cheerios')}


dynamic_item = dynamic_restriction_mixin('item',
                                         'item_metadata',
                                         milk=MilkMetadata,
                                         cereal=CerealMetadata)


class Breakfast(dynamic_item):
    """
    What is the most important meal of the day?
    """
    _restrictions = {
        'item': R('milk', 'cereal'),
        'item_metadata': R(),
    }


class TestDynamicDataObject(object):
    """