def test_valid_filter(self): """ Tests the clean() method of a ContextFilter when the value_field and search_field are valid. """ context_filter = ContextFilter(context=self.context_w_filters, value_field='user.email', operator='regex', search_field='user.email') try: context_filter.clean() except ValidationError: self.fail('A ValidationError was raised unexpectedly')
def test_invalid_search_field(self): """ Tests the clean() method of a ContextFilter when the search_field is invalid. """ context_filter = ContextFilter(context=self.context_w_filters, value_field='user.email', operator='eq', search_field='host') msg = 'The search field "host" is not a field in the Container used '\ 'by the Related Distillery elasticsearch.test_index.test_docs.' with six.assertRaisesRegex(self, ValidationError, msg): context_filter.clean()
def test_invalid_value_field(self): """ Tests the clean() method of a ContextFilter when the value_field is invalid. """ context_filter = ContextFilter(context=self.context_w_filters, value_field='host', operator='eq', search_field='from') msg = 'The value field "host" is not a field in the Container used '\ 'by the Focal Distillery mongodb.test_database.test_posts.' with six.assertRaisesRegex(self, ValidationError, msg): context_filter.clean()
def test_create_fieldset(self): """ Tests the create_fieldset method of a ContextFilter. """ data = {'host': 'foo', 'message': 'bar'} context_filter = ContextFilter(context=self.context_w_filters, value_field='host', operator='eq', search_field='from') fieldset = context_filter.create_fieldset(data) self.assertEqual(type(fieldset), QueryFieldset) self.assertEqual(fieldset.field_name, 'from') self.assertEqual(fieldset.field_type, 'EmailField') self.assertEqual(fieldset.operator, 'eq') self.assertEqual(fieldset.value, 'foo')
def test_failed_operator_text(self): """ Tests that the operator value will be returned if it cannot find a match in the operator choices. """ context_filter = ContextFilter(context=self.context_w_filters, value_field='host', operator='meh', search_field='from') self.assertEqual(context_filter.operator_text, 'meh')
def test_operator_text(self): """ Tests that the property 'operator_text' returns a human readable version of operator. """ context_filter = ContextFilter(context=self.context_w_filters, value_field='host', operator='eq', search_field='from') self.assertEqual(context_filter.operator_text, 'equals')