def test_empty(self): """Test empty value.""" fltr = filters.SimpleFilter('field', 'param', transformers=[lambda v: '1'], required=False) fltr.add(self.query, {'param': ''}) self.query.filter.assert_not_called()
def test_transform(self): """Test transform.""" fltr = filters.SimpleFilter('field', 'param', transformers=[lambda v: '1'], required=False) fltr.add(self.query, {'param': 'test'}) self.query.filter.assert_called_once_with('field', '1')
def test_empty_required(self): """Test required value.""" fltr = filters.SimpleFilter( 'field', 'param', transformers=[lambda v: '1'], required=True) with self.assertRaises(helpers.EarlyExitException) as cm: fltr.add(self.query, {'param': ''}) self.assertEqual("'param' is required.", cm.exception.message) self.assertEqual(400, cm.exception.status) self.query.filter.assert_not_called()