def test_validation_query_returns_bugzilla_error(self): """ The form is invalid if given a query that returns any errors """ data = {'query': 'http://www.example.com?x=y', 'description': 'foo'} with patch('oneanddone.tasks.forms.BugzillaUtils') as BugzillaUtils: request_bugcount = BugzillaUtils().request_bugcount message = ('Sorry. we cannot retrieve any data from Bugzilla at ' 'this time. Please report this to the ' 'One and Done team.') request_bugcount.side_effect = RuntimeError form = TaskImportBatchForm(data=data) self.assertFalse(form.is_valid()) eq_(form.non_field_errors(), [message]) request_bugcount.side_effect = RequestException form = TaskImportBatchForm(data=data) self.assertFalse(form.is_valid()) eq_(form.non_field_errors(), [message])
def test_validation_query_returns_external_error(self): """ The form is invalid if given a query that returns any errors """ data = {'query': 'http://www.example.com?x=y', 'description': 'foo'} with patch('oneanddone.tasks.forms.BugzillaUtils') as BugzillaUtils: message = 'bar' BugzillaUtils().request_bugcount.side_effect = ValueError(message) form = TaskImportBatchForm(data=data) self.assertFalse(form.is_valid()) eq_(form.non_field_errors(), ['External error: ' + message])
def test_validation_invalid_query(self): """ The form is invalid when the query has no URL parameters. """ data = {'query': 'http://www.example.com', 'description': 'foo'} form = TaskImportBatchForm(data=data) self.assertFalse(form.is_valid()) eq_(form.non_field_errors(), [('For the query URL, please provide ' 'a full URL that includes search ' 'parameters.')])
def test_validation_no_query_results(self): """ The form is invalid when given a query that returns 0 results. """ data = {'query': 'http://www.example.com?x=y', 'description': 'foo'} with patch('oneanddone.tasks.forms.BugzillaUtils') as BugzillaUtils: BugzillaUtils().request_bugcount.return_value = 0 form = TaskImportBatchForm(data=data) self.assertFalse(form.is_valid()) eq_(form.non_field_errors(), [('Your query does not return' ' any results.')])