def test_getitem_returns_empty_upsert_context_if_missing_group( self, pyramid_request, GroupRoot, GroupUpsertContext): root = GroupUpsertRoot(pyramid_request) GroupRoot.return_value.__getitem__.side_effect = KeyError('bang') context = root['whatever'] GroupRoot.return_value.__getitem__.assert_called_once_with('whatever') assert context == GroupUpsertContext.return_value GroupUpsertContext.assert_called_once_with(group=None, request=pyramid_request)
def test_getitem_returns_populated_upsert_context_if_group_found( self, pyramid_request, GroupRoot, GroupUpsertContext, factories): group = factories.Group() root = GroupUpsertRoot(pyramid_request) GroupRoot.return_value.__getitem__.return_value = group context = root['agroup'] GroupRoot.return_value.__getitem__.assert_called_once_with('agroup') assert context == GroupUpsertContext.return_value GroupUpsertContext.assert_called_once_with(group=group, request=pyramid_request)