예제 #1
0
    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])
예제 #2
0
 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])
예제 #3
0
    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])
예제 #4
0
 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])
예제 #5
0
 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.')])
예제 #6
0
 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.')])
예제 #7
0
 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.')])
예제 #8
0
 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.')])