コード例 #1
0
 def test_group_by_type_models_passed(self, mock_eng):
     doc1 = Mock(_type='Foo')
     doc2 = Mock(_type='Bar')
     FooModel = Mock(__name__='Foo')
     BarModel = Mock(__name__='Bar')
     grouped = acl_utils._group_by_type(
         [doc1, doc2], [FooModel, BarModel])
     assert not mock_eng.get_document_cls.called
     assert set(grouped.keys()) == {FooModel, BarModel}
     assert set(grouped[FooModel]) == {doc1}
     assert set(grouped[BarModel]) == {doc2}
コード例 #2
0
 def test_group_by_type(self, mock_eng):
     doc1 = Mock(_type='Foo')
     doc2 = Mock(_type='Bar')
     doc3 = Mock(_type='Foo')
     mock_eng.get_document_cls.side_effect = lambda x: x
     grouped = acl_utils._group_by_type([doc1, doc2, doc3])
     mock_eng.get_document_cls.assert_has_calls([
         call('Foo'), call('Bar')])
     assert mock_eng.get_document_cls.call_count == 2
     assert set(grouped.keys()) == {'Foo', 'Bar'}
     assert set(grouped['Foo']) == {doc1, doc3}
     assert set(grouped['Bar']) == {doc2}