def test_prepare_not_top_level(self): ctx = mock_context() related = Mock(name='related') field = AggregateField('name.one.two', django.db.models.Count) with self.assertRaises(SavoryPieError) as cm: field.prepare(ctx, related) self.assertEqual( 'RelatedCountField can only be used on a top level ModelResource', str(cm.exception))
def test_prepare_not_top_level(self): ctx = mock_context() related = Mock(name='related') field = AggregateField('name.one.two', django.db.models.Count) with self.assertRaises(SavoryPieError) as cm: field.prepare(ctx, related) self.assertEqual( 'RelatedCountField can only be used on a top level ModelResource', str(cm.exception) )
def test_prepare(self): ctx = mock_context() ctx.peek.side_effect = IndexError related = Mock(name='related') field = AggregateField('name.one.two', django.db.models.Count) field.prepare(ctx, related) related.annotate.assert_called_with( django.db.models.Count, 'name__one__two', distinct=True, )