Example #1
0
 def test_ensure_rate_is_unique_ok(self, monkeypatch, request_,
                                   context, subject):
     from adhocracy_core.sheets.rate import RateSchema
     from adhocracy_core.sheets import rate
     mock_find_catalog = Mock(return_value={'reference': DummyIndex(),
                                            'path': DummyIndex()})
     monkeypatch.setattr(rate, 'find_catalog', mock_find_catalog)
     schema = RateSchema().bind(request=request_, context=context)
     object = _make_rateable()
     node = Mock()
     value = {'subject': subject, 'object': object, 'rate': '1'}
     result = schema._ensure_rate_is_unique(node, value, request_)
     assert result is None
Example #2
0
 def test_ensure_rate_is_unique_error(self, monkeypatch, request_,
                                      context, subject):
     from adhocracy_core.sheets.rate import RateSchema
     from adhocracy_core.sheets import rate
     from adhocracy_core.utils import named_object
     mock_find_catalog = Mock(
         return_value={'reference': DummyIndex(['dummy']),
                       'path': DummyIndex()})
     monkeypatch.setattr(rate, 'find_catalog', mock_find_catalog)
     schema = RateSchema().bind(request=request_, context=context)
     object = _make_rateable()
     node = Mock()
     node.children = [named_object('object')]
     value = {'subject': subject, 'object': object, 'rate': '1'}
     with raises(colander.Invalid):
         schema._ensure_rate_is_unique(node, value, request_)
Example #3
0
 def schema_with_mock_ensure_rate(self, request_, context):
     from adhocracy_core.sheets.rate import RateSchema
     schema = RateSchema().bind(request=request_, context=context)
     schema._ensure_rate_is_unique = Mock()
     return schema