def test_cache_purge_cb_on_delete(self): setter = mock.MagicMock() deleter = mock.MagicMock() on_purge = mock.MagicMock() tested = aws_dict.AwsDict('KeyEl', 'ValEl', self.default_getter, setter, deleter, on_purge) tested.pop('val2') assert on_purge.called
def test_cache_purge_cb_on_update(self): setter = mock.MagicMock() deleter = mock.MagicMock() on_purge = mock.MagicMock() tested = aws_dict.AwsDict('KeyEl', 'ValEl', self.default_getter, setter, deleter, on_purge) tested['update_1.0'] = 'build_update_ctx1' assert on_purge.called
def test_handler_assigment(self): tested = aws_dict.AwsDict('KeyEl', 'ValEl', self.default_getter) setter = mock.MagicMock() deleter = mock.MagicMock() tested.setter(setter) tested.deleter(deleter) assert tested.full._deleter_fn is deleter assert tested.full._setter_fn is setter
def test_setter_create(self): setter = mock.MagicMock() tested = aws_dict.AwsDict('KeyEl', 'ValEl', self.default_getter, setter) tested['val-new'] = 'potato' assert unordered_equal(setter.call_args[0][0], [ { 'KeyEl': 'val-new', 'ValEl': 'potato' }, ])
def test_base(self): tested = aws_dict.AwsDict('KeyEl', 'ValEl', self.default_getter) assert tested['val1'] == 'TestAwsDict-val1' assert tested['val4'] == 'TestAwsDict-val4' assert tested.full['val2'] == { 'ValEl': 'TestAwsDict-val2', 'PropEl': 'TestAwsDict-prop2' } assert 'val3' in repr(tested) assert len(tested) == 4 assert set(iter(tested)) == set(['val1', 'val2', 'val3', 'val4'])
def test_delete(self): setter = mock.MagicMock() deleter = mock.MagicMock() tested = aws_dict.AwsDict('KeyEl', 'ValEl', self.default_getter, setter, deleter) del tested['val1'] assert not setter.called assert unordered_equal(deleter.call_args[0][0], [ { 'KeyEl': 'val1' }, ])
def test_setter_amend(self): setter = mock.MagicMock() tested = aws_dict.AwsDict('KeyEl', 'ValEl', self.default_getter, setter) tested['val3'] = 'potato' assert unordered_equal(setter.call_args[0][0], [ { 'KeyEl': 'val3', 'ValEl': 'potato', 'PropEl': 'TestAwsDict-prop3' }, ])
def test_bulk_update(self): setter = mock.MagicMock() tested = aws_dict.AwsDict('KeyEl', 'ValEl', self.default_getter, setter) with tested.bulk_update(): tested['val1'] = 'new-value' with tested.bulk_update(): tested.full['val1']['PropEl'] = 'new-prop-value' tested['val2'] = 'new-value-2' assert unordered_equal(setter.call_args[0][0], [ { 'KeyEl': 'val1', 'ValEl': 'new-value', 'PropEl': 'new-prop-value' }, { 'KeyEl': 'val2', 'ValEl': 'new-value-2', 'PropEl': 'TestAwsDict-prop2' }, ])