Exemplo n.º 1
0
 def test_invalid_return_code(self, fake_requests_obj):
     """Test fetch_bugs invalid status code exception."""
     request = requests.Request()
     request.status_code = 500
     request.text = 'Foobar'
     (fake_requests_obj.expects_call().returns(request))
     fetch_bugs()
Exemplo n.º 2
0
 def test_connection_error(self, fake_requests_obj):
     """Test fetch_bugs connection error exception."""
     if (not getattr(settings, 'REMOZILLA_USERNAME', None)
             or not getattr(settings, 'REMOZILLA_PASSWORD', None)):
         raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME '
                        'or REMOZILLA_PASSWORD.')
     (fake_requests_obj.expects_call().raises(requests.ConnectionError))
     fetch_bugs()
Exemplo n.º 3
0
 def test_connection_error(self, fake_requests_obj):
     """Test fetch_bugs connection error exception."""
     if (not getattr(settings, 'REMOZILLA_USERNAME', None) or
         not getattr(settings, 'REMOZILLA_PASSWORD', None)):
         raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME '
                        'or REMOZILLA_PASSWORD.')
     (fake_requests_obj.expects_call().raises(requests.ConnectionError))
     fetch_bugs()
Exemplo n.º 4
0
 def test_connection_error(self, fake_get):
     """Test fetch_bugs connection error exception."""
     if ((not getattr(settings, 'REMOZILLA_USERNAME', None) or
          not getattr(settings, 'REMOZILLA_PASSWORD', None))):
         raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME '
                        'or REMOZILLA_PASSWORD.')
     fake_get.side_effect = requests.ConnectionError()
     fetch_bugs()
     fake_get.assert_called_with(ANY)
Exemplo n.º 5
0
 def test_connection_error(self, fake_get):
     """Test fetch_bugs connection error exception."""
     if ((not getattr(settings, 'REMOZILLA_USERNAME', None) or
          not getattr(settings, 'REMOZILLA_PASSWORD', None))):
         raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME '
                        'or REMOZILLA_PASSWORD.')
     fake_get.side_effect = requests.ConnectionError()
     fetch_bugs()
     fake_get.assert_called_with(ANY)
Exemplo n.º 6
0
 def test_invalid_return_code(self, mocked_request):
     """Test fetch_bugs invalid status code exception."""
     if ((not getattr(settings, 'REMOZILLA_USERNAME', None) or
          not getattr(settings, 'REMOZILLA_PASSWORD', None))):
         raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME '
                        'or REMOZILLA_PASSWORD.')
     mocked_obj = Mock()
     mocked_request.get.return_value = mocked_obj
     mocked_response = mocked_obj
     mocked_response.json.return_value = {'error': 'Invalid login'}
     fetch_bugs()
Exemplo n.º 7
0
 def test_invalid_return_code(self, mocked_request):
     """Test fetch_bugs invalid status code exception."""
     if ((not getattr(settings, 'REMOZILLA_USERNAME', None) or
          not getattr(settings, 'REMOZILLA_PASSWORD', None))):
         raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME '
                        'or REMOZILLA_PASSWORD.')
     mocked_obj = Mock()
     mocked_request.get.return_value = mocked_obj
     mocked_response = mocked_obj
     mocked_response.json.return_value = {'error': 'Invalid login'}
     fetch_bugs()
Exemplo n.º 8
0
 def test_invalid_return_code(self, fake_requests_obj):
     """Test fetch_bugs invalid status code exception."""
     if (not getattr(settings, 'REMOZILLA_USERNAME', None) or
         not getattr(settings, 'REMOZILLA_PASSWORD', None)):
         raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME '
                        'or REMOZILLA_PASSWORD.')
     request = requests.Request()
     request.status_code = 500
     request.text = 'Foobar'
     (fake_requests_obj.expects_call().returns(request))
     fetch_bugs()
Exemplo n.º 9
0
 def test_invalid_return_code(self, fake_requests_obj):
     """Test fetch_bugs invalid status code exception."""
     if (not getattr(settings, 'REMOZILLA_USERNAME', None)
             or not getattr(settings, 'REMOZILLA_PASSWORD', None)):
         raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME '
                        'or REMOZILLA_PASSWORD.')
     request = requests.Request()
     request.status_code = 500
     request.text = 'Foobar'
     (fake_requests_obj.expects_call().returns(request))
     fetch_bugs()
Exemplo n.º 10
0
 def test_invalid_return_code(self, fake_get):
     """Test fetch_bugs invalid status code exception."""
     if ((not getattr(settings, 'REMOZILLA_USERNAME', None)
          or not getattr(settings, 'REMOZILLA_PASSWORD', None))):
         raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME '
                        'or REMOZILLA_PASSWORD.')
     request = requests.Request()
     request.status_code = 500
     request.text = 'Foobar'
     fake_get.return_value = request
     fetch_bugs()
     fake_get.assert_called_with(ANY)
Exemplo n.º 11
0
 def test_invalid_return_code(self, fake_get):
     """Test fetch_bugs invalid status code exception."""
     if ((not getattr(settings, 'REMOZILLA_USERNAME', None) or
          not getattr(settings, 'REMOZILLA_PASSWORD', None))):
         raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME '
                        'or REMOZILLA_PASSWORD.')
     request = requests.Request()
     request.status_code = 500
     request.text = 'Foobar'
     fake_get.return_value = request
     fetch_bugs()
     fake_get.assert_called_with(ANY)
Exemplo n.º 12
0
    def test_with_valid_data(self, fake_requests_obj):
        """Test fetch_bugs valid bug data processing."""
        if (not getattr(settings, 'REMOZILLA_USERNAME', None) or
            not getattr(settings, 'REMOZILLA_PASSWORD', None)):
            raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME.')

        previous_last_updated_time = get_last_updated_date()

        request = requests.Request()
        request.status_code = 200
        bug_data = {'bugs': [{'id': 7788,
                              'summary':'This is summary',
                              'creator': {'name': '*****@*****.**'},
                              'creation_time': '2010-10-5T13:45:23Z',
                              'component':'Swag Requests',
                              'whiteboard':'This is whiteboard',
                              'cc': [{'name': '*****@*****.**'},
                                     {'name': '*****@*****.**'}],
                              'assigned_to':{'name':'*****@*****.**'},
                              'status':'resolved',
                              'resolution':'invalid',
                              'cf_due_date': None},
                             {'id': 1199,
                              'summary':'New summary',
                              'creator': {'name': '*****@*****.**'},
                              'creation_time': '2012-12-5T11:30:23Z',
                              'component':'Budget Requests',
                              'cc': [{'name': '*****@*****.**'},
                                     {'name': '*****@*****.**'}],
                              'assigned_to':{'name':'*****@*****.**'},
                              'status':'resolved',
                              'resolution':'invalid',
                              'cf_due_date': None}]}

        request.text = json.dumps(bug_data)
        (fake_requests_obj.expects_call().returns(request))
        fetch_bugs()

        eq_(Bug.objects.all().count(), len(bug_data['bugs']))

        # refresh status_obj
        self.assertGreater(get_last_updated_date(), previous_last_updated_time)

        bug = Bug.objects.get(bug_id=7788)
        eq_(bug.cc.all().count(), 1)
        eq_(bug.assigned_to.email, '*****@*****.**')
        eq_(bug.due_date, None)
        eq_(bug.resolution, 'INVALID')

        bug = Bug.objects.get(bug_id=1199)
        eq_(bug.creator, None)
        eq_(bug.cc.all().count(), 1)
Exemplo n.º 13
0
 def handle(self, *args, **options):
     """Command handler."""
     try:
         fetch_bugs(days=options['days'])
     except Exception:
         # Make sure to email admins on error
         import traceback
         import StringIO
         tb = StringIO.StringIO()
         traceback.print_exc(file=tb)
         tb.seek(0)
         mail_admins('Fetch bugs error', tb.read())
         raise
Exemplo n.º 14
0
 def handle(self, *args, **options):
     """Command handler."""
     try:
         fetch_bugs(days=options['days'])
     except Exception:
         # Make sure to email admins on error
         import traceback
         import StringIO
         tb = StringIO.StringIO()
         traceback.print_exc(file=tb)
         tb.seek(0)
         mail_admins('Fetch bugs error', tb.read())
         raise
Exemplo n.º 15
0
    def test_with_valid_data(self, fake_get, switch_is_active_mock):
        """Test fetch_bugs valid bug data processing."""
        UserFactory.create(username='******')
        if ((not getattr(settings, 'REMOZILLA_USERNAME', None) or
             not getattr(settings, 'REMOZILLA_PASSWORD', None))):
            raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME.')

        switch_is_active_mock.return_value = True
        previous_last_updated_time = get_last_updated_date()

        first_request = requests.Request()
        first_request.status_code = 200
        user = UserFactory.create(groups=['Rep'], email='*****@*****.**')
        bug_data = {'bugs': [{'id': 7788,
                              'summary': 'This is summary',
                              'creator': {'name': '*****@*****.**'},
                              'creation_time': '2010-10-5T13:45:23Z',
                              'component': 'Budget Requests',
                              'whiteboard': 'This is whiteboard',
                              'cc': [{'name': '*****@*****.**'},
                                     {'name': '*****@*****.**'}],
                              'assigned_to': {'name': '*****@*****.**'},
                              'status': 'resolved',
                              'flags': [
                                  {'status': '?',
                                   'name': 'remo-approval'},
                                  {'status': '?',
                                   'name': 'needinfo',
                                   'requestee': {
                                       'name': settings.REPS_COUNCIL_ALIAS}},
                                  {'status': '?',
                                   'name': 'needinfo',
                                   'requestee': {
                                       'name': '*****@*****.**'}}
                              ],
                              'resolution': 'invalid'},
                             {'id': 1199,
                              'summary': 'New summary',
                              'creator': {'name': '*****@*****.**'},
                              'creation_time': '2012-12-5T11:30:23Z',
                              'component': 'Budget Requests',
                              'whiteboard': 'Council Reviewer Assigned',
                              'cc': [{'name': '*****@*****.**'},
                                     {'name': '*****@*****.**'}],
                              'flags': [{'status': '?',
                                         'name': 'remo-approval'},
                                        {'status': '?',
                                         'name': 'remo-review'}],
                              'assigned_to': {'name': '*****@*****.**'},
                              'status': 'resolved',
                              'resolution': 'invalid'}]}

        first_request.text = json.dumps(bug_data)

        second_request = requests.Request()
        second_request.status_code = 200
        bug_data['bugs'][0]['component'] = 'Planning'
        bug_data['bugs'][0]['id'] = 7789
        bug_data['bugs'][1]['component'] = 'Planning'
        bug_data['bugs'][1]['id'] = 1200
        second_request.text = json.dumps(bug_data)

        empty_request = requests.Request()
        empty_request.status_code = 200
        empty_request.text = json.dumps({'bugs': []})

        values = [first_request, empty_request, second_request, empty_request]
        fake_get.side_effect = values

        fetch_bugs(components=['Planning', 'Budget Requests'])

        eq_(Bug.objects.all().count(), 4)
        eq_(Bug.objects.filter(component='Planning').count(), 2)
        eq_(Bug.objects.filter(component='Budget Requests').count(), 2)

        # refresh status_obj
        self.assertGreater(get_last_updated_date(), previous_last_updated_time)

        bug = Bug.objects.get(bug_id=7788)
        eq_(bug.cc.all().count(), 1)
        eq_(bug.assigned_to.email, '*****@*****.**')
        eq_(bug.resolution, 'INVALID')
        ok_(bug.council_vote_requested)
        ok_(user in bug.budget_needinfo.all())

        bug = Bug.objects.get(bug_id=1199)
        eq_(bug.creator, None)
        eq_(bug.cc.all().count(), 1)
        ok_(not bug.council_vote_requested)
        ok_(bug.pending_mentor_validation)
        ok_(bug.council_member_assigned)
Exemplo n.º 16
0
 def handle(self, *args, **options):
     """Command handler."""
     fetch_bugs(days=options['days'])
Exemplo n.º 17
0
    def test_with_valid_data(self, fake_get, switch_is_active_mock):
        """Test fetch_bugs valid bug data processing."""
        UserFactory.create(username='******')
        if ((not getattr(settings, 'REMOZILLA_USERNAME', None)
             or not getattr(settings, 'REMOZILLA_PASSWORD', None))):
            raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME.')

        switch_is_active_mock.return_value = True
        previous_last_updated_time = get_last_updated_date()

        first_request = requests.Request()
        first_request.status_code = 200
        bug_data = {
            'bugs': [{
                'id':
                7788,
                'summary':
                'This is summary',
                'creator': {
                    'name': '*****@*****.**'
                },
                'creation_time':
                '2010-10-5T13:45:23Z',
                'component':
                'Swag Requests',
                'whiteboard':
                'This is whiteboard',
                'cc': [{
                    'name': '*****@*****.**'
                }, {
                    'name': '*****@*****.**'
                }],
                'assigned_to': {
                    'name': '*****@*****.**'
                },
                'status':
                'resolved',
                'flags': [{
                    'status': '?',
                    'name': 'remo-approval'
                }, {
                    'status': '?',
                    'name': 'needinfo',
                    'requestee': {
                        'name': settings.REPS_COUNCIL_ALIAS
                    }
                }],
                'resolution':
                'invalid'
            }, {
                'id':
                1199,
                'summary':
                'New summary',
                'creator': {
                    'name': '*****@*****.**'
                },
                'creation_time':
                '2012-12-5T11:30:23Z',
                'component':
                'Swag requests',
                'cc': [{
                    'name': '*****@*****.**'
                }, {
                    'name': '*****@*****.**'
                }],
                'assigned_to': {
                    'name': '*****@*****.**'
                },
                'status':
                'resolved',
                'resolution':
                'invalid'
            }]
        }

        first_request.text = json.dumps(bug_data)

        second_request = requests.Request()
        second_request.status_code = 200
        bug_data['bugs'][0]['component'] = 'Planning'
        bug_data['bugs'][0]['id'] = 7789
        bug_data['bugs'][1]['component'] = 'Planning'
        bug_data['bugs'][1]['id'] = 1200
        second_request.text = json.dumps(bug_data)

        empty_request = requests.Request()
        empty_request.status_code = 200
        empty_request.text = json.dumps({'bugs': []})

        values = [first_request, empty_request, second_request, empty_request]
        fake_get.side_effect = values

        fetch_bugs(components=['Planning', 'Swag Requests'])

        eq_(Bug.objects.all().count(), 4)
        eq_(Bug.objects.filter(component='Planning').count(), 2)
        eq_(Bug.objects.filter(component='Swag Requests').count(), 2)

        # refresh status_obj
        self.assertGreater(get_last_updated_date(), previous_last_updated_time)

        bug = Bug.objects.get(bug_id=7788)
        eq_(bug.cc.all().count(), 1)
        eq_(bug.assigned_to.email, '*****@*****.**')
        eq_(bug.resolution, 'INVALID')
        ok_(bug.council_vote_requested)

        bug = Bug.objects.get(bug_id=1199)
        eq_(bug.creator, None)
        eq_(bug.cc.all().count(), 1)
        ok_(not bug.council_vote_requested)
Exemplo n.º 18
0
 def test_connection_error(self, fake_requests_obj):
     """Test fetch_bugs connection error exception."""
     (fake_requests_obj.expects_call().raises(requests.ConnectionError))
     fetch_bugs()
Exemplo n.º 19
0
    def test_with_valid_data(self, mocked_request, switch_is_active_mock):
        """Test fetch_bugs valid bug data processing."""
        UserFactory.create(username='******')
        if ((not getattr(settings, 'REMOZILLA_USERNAME', None) or
             not getattr(settings, 'REMOZILLA_PASSWORD', None))):
            raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME.')

        switch_is_active_mock.return_value = True
        previous_last_updated_time = get_last_updated_date()

        mentor = UserFactory.create()
        user = UserFactory.create(groups=['Rep'], email='*****@*****.**',
                                  userprofile__mentor=mentor)
        login_data = {u'token': u'bugzilla_token',
                      u'id': 12345}
        bug_data = [{'id': 7788,
                     'summary': 'This is summary',
                     'creator': '*****@*****.**',
                     'creation_time': '2010-10-5T13:45:23Z',
                     'component': 'Budget Requests',
                     'whiteboard': 'This is whiteboard',
                     'cc': ['*****@*****.**', '*****@*****.**'],
                     'assigned_to': '*****@*****.**',
                     'status': 'resolved',
                     'flags': [{'status': '?',
                                'name': 'remo-approval'},
                               {'status': '?',
                                'name': 'needinfo',
                                'requestee': settings.REPS_REVIEW_ALIAS},
                               {'status': '?',
                                'name': 'needinfo',
                                'requestee': '*****@*****.**'}],
                     'resolution': 'invalid'},
                    {'id': 1199,
                     'summary': 'New summary',
                     'creator': '*****@*****.**',
                     'creation_time': '2012-12-5T11:30:23Z',
                     'component': 'Budget Requests',
                     'whiteboard': 'Review Team approval needed',
                     'cc': ['*****@*****.**', '*****@*****.**'],
                     'flags': [{'status': '?',
                                'name': 'remo-approval'},
                               {'status': '?',
                                'name': 'remo-review'}],
                     'assigned_to': '*****@*****.**',
                     'status': 'resolved',
                     'resolution': 'invalid'}]

        def mocked_get(url, *args, **kwargs):
            mocked_response = Mock()

            if 'login' in url:
                mocked_response.json.return_value = login_data
                return mocked_response
            elif 'comment' in url:
                comments = {
                    'bugs': {
                        '7788': {
                            'comments': [{'text': 'foo'}, {'text': 'bar'}]
                        },
                        '1199': {
                            'comments': [{'text': 'bar'}, {'text': 'foo'}]
                        }
                    }
                }
                mocked_response.json.return_value = comments
                return mocked_response
            else:
                mocked_response.json.return_value = {'bugs': bug_data}
                url_params = parse_qs(urlparse(url).query)
                offset = url_params.get('offset')
                if offset and int(offset[0]) > 0:
                    mocked_response.json.return_value = {'bugs': []}
                return mocked_response

        mocked_request.side_effect = mocked_get
        fetch_bugs()

        eq_(Bug.objects.all().count(), 2)
        eq_(Bug.objects.filter(component='Budget Requests').count(), 2)

        # refresh status_obj
        self.assertGreater(get_last_updated_date(), previous_last_updated_time)

        bug = Bug.objects.get(bug_id=7788)
        eq_(bug.cc.all().count(), 1)
        eq_(bug.assigned_to.email, '*****@*****.**')
        eq_(bug.resolution, 'INVALID')
        eq_(bug.creator, User.objects.get(email='*****@*****.**'))
        ok_(bug.council_vote_requested)
        ok_(user in bug.budget_needinfo.all())
        eq_(bug.first_comment, 'foo')

        bug = Bug.objects.get(bug_id=1199)
        eq_(bug.creator, None)
        eq_(bug.cc.all().count(), 1)
        ok_(not bug.council_vote_requested)
        ok_(bug.pending_mentor_validation)
        ok_(bug.council_member_assigned)
        eq_(bug.first_comment, 'bar')
Exemplo n.º 20
0
    def test_with_valid_data(self, mocked_request, switch_is_active_mock):
        """Test fetch_bugs valid bug data processing."""
        UserFactory.create(username='******')
        if ((not getattr(settings, 'REMOZILLA_USERNAME', None) or
             not getattr(settings, 'REMOZILLA_PASSWORD', None))):
            raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME.')

        switch_is_active_mock.return_value = True
        previous_last_updated_time = get_last_updated_date()

        mentor = UserFactory.create()
        user = UserFactory.create(groups=['Rep'], email='*****@*****.**',
                                  userprofile__mentor=mentor)
        login_data = {u'token': u'bugzilla_token',
                      u'id': 12345}
        bug_data = [{'id': 7788,
                     'summary': 'This is summary',
                     'creator': '*****@*****.**',
                     'creation_time': '2010-10-5T13:45:23Z',
                     'component': 'Budget Requests',
                     'whiteboard': 'This is whiteboard',
                     'cc': ['*****@*****.**', '*****@*****.**'],
                     'assigned_to': '*****@*****.**',
                     'status': 'resolved',
                     'flags': [{'status': '?',
                                'name': 'remo-approval'},
                               {'status': '?',
                                'name': 'needinfo',
                                'requestee': settings.REPS_COUNCIL_ALIAS},
                               {'status': '?',
                                'name': 'needinfo',
                                'requestee': '*****@*****.**'}],
                     'resolution': 'invalid'},
                    {'id': 1199,
                     'summary': 'New summary',
                     'creator': '*****@*****.**',
                     'creation_time': '2012-12-5T11:30:23Z',
                     'component': 'Budget Requests',
                     'whiteboard': 'Council Reviewer Assigned',
                     'cc': ['*****@*****.**', '*****@*****.**'],
                     'flags': [{'status': '?',
                                'name': 'remo-approval'},
                               {'status': '?',
                                'name': 'remo-review'}],
                     'assigned_to': '*****@*****.**',
                     'status': 'resolved',
                     'resolution': 'invalid'}]

        def mocked_get(url, *args, **kwargs):
            mocked_response = Mock()

            if 'login' in url:
                mocked_response.json.return_value = login_data
                return mocked_response
            elif 'comment' in url:
                comments = {
                    'bugs': {
                        '7788': {
                            'comments': [{'text': 'foo'}, {'text': 'bar'}]
                        },
                        '1199': {
                            'comments': [{'text': 'bar'}, {'text': 'foo'}]
                        }
                    }
                }
                mocked_response.json.return_value = comments
                return mocked_response
            else:
                mocked_response.json.return_value = {'bugs': bug_data}
                url_params = parse_qs(urlparse(url).query)
                offset = url_params.get('offset')
                if offset and int(offset[0]) > 0:
                    mocked_response.json.return_value = {'bugs': []}
                return mocked_response

        mocked_request.side_effect = mocked_get
        fetch_bugs()

        eq_(Bug.objects.all().count(), 2)
        eq_(Bug.objects.filter(component='Budget Requests').count(), 2)

        # refresh status_obj
        self.assertGreater(get_last_updated_date(), previous_last_updated_time)

        bug = Bug.objects.get(bug_id=7788)
        eq_(bug.cc.all().count(), 1)
        eq_(bug.assigned_to.email, '*****@*****.**')
        eq_(bug.resolution, 'INVALID')
        eq_(bug.creator, User.objects.get(email='*****@*****.**'))
        ok_(bug.council_vote_requested)
        ok_(user in bug.budget_needinfo.all())
        eq_(bug.first_comment, 'foo')

        bug = Bug.objects.get(bug_id=1199)
        eq_(bug.creator, None)
        eq_(bug.cc.all().count(), 1)
        ok_(not bug.council_vote_requested)
        ok_(bug.pending_mentor_validation)
        ok_(bug.council_member_assigned)
        eq_(bug.first_comment, 'bar')
Exemplo n.º 21
0
    def test_with_valid_data(self, fake_requests_obj):
        """Test fetch_bugs valid bug data processing."""
        if ((not getattr(settings, 'REMOZILLA_USERNAME', None) or
             not getattr(settings, 'REMOZILLA_PASSWORD', None))):
            raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME.')

        previous_last_updated_time = get_last_updated_date()

        first_request = requests.Request()
        first_request.status_code = 200
        bug_data = {'bugs': [{'id': 7788,
                              'summary': 'This is summary',
                              'creator': {'name': '*****@*****.**'},
                              'creation_time': '2010-10-5T13:45:23Z',
                              'component': 'Swag Requests',
                              'whiteboard': 'This is whiteboard',
                              'cc': [{'name': '*****@*****.**'},
                                     {'name': '*****@*****.**'}],
                              'assigned_to': {'name': '*****@*****.**'},
                              'status': 'resolved',
                              'flags': [
                                  {'requestee': {
                                      'ref': '',
                                      'name': '*****@*****.**'},
                                   'status': '?',
                                   'name': 'remo-review'}],
                              'resolution': 'invalid'},
                             {'id': 1199,
                              'summary': 'New summary',
                              'creator': {'name': '*****@*****.**'},
                              'creation_time': '2012-12-5T11:30:23Z',
                              'component': 'Swag requests',
                              'cc': [{'name': '*****@*****.**'},
                                     {'name': '*****@*****.**'}],
                              'assigned_to': {'name': '*****@*****.**'},
                              'status': 'resolved',
                              'resolution': 'invalid'}]}

        first_request.text = json.dumps(bug_data)

        second_request = requests.Request()
        second_request.status_code = 200
        bug_data['bugs'][0]['component'] = 'Planning'
        bug_data['bugs'][0]['id'] = 7789
        bug_data['bugs'][1]['component'] = 'Planning'
        bug_data['bugs'][1]['id'] = 1200
        second_request.text = json.dumps(bug_data)

        empty_request = requests.Request()
        empty_request.status_code = 200
        empty_request.text = json.dumps({'bugs': []})

        fake_requests_obj.expects_call()
        fake_requests_obj.returns(first_request)
        fake_requests_obj.next_call().returns(empty_request)
        fake_requests_obj.next_call().returns(second_request)
        fake_requests_obj.next_call().returns(empty_request)

        fetch_bugs(components=['Planning', 'Swag Requests'])

        eq_(Bug.objects.all().count(), 4)
        eq_(Bug.objects.filter(component='Planning').count(), 2)
        eq_(Bug.objects.filter(component='Swag Requests').count(), 2)

        # refresh status_obj
        self.assertGreater(get_last_updated_date(), previous_last_updated_time)

        bug = Bug.objects.get(bug_id=7788)
        eq_(bug.cc.all().count(), 1)
        eq_(bug.assigned_to.email, '*****@*****.**')
        eq_(bug.resolution, 'INVALID')
        eq_(bug.council_vote_requested, True)

        bug = Bug.objects.get(bug_id=1199)
        eq_(bug.creator, None)
        eq_(bug.cc.all().count(), 1)
        eq_(bug.council_vote_requested, False)
Exemplo n.º 22
0
 def handle(self, *args, **options):
     """Command handler."""
     fetch_bugs(days=options['days'])
Exemplo n.º 23
0
    def test_with_valid_data(self, fake_requests_obj):
        """Test fetch_bugs valid bug data processing."""
        if (not getattr(settings, 'REMOZILLA_USERNAME', None)
                or not getattr(settings, 'REMOZILLA_PASSWORD', None)):
            raise SkipTest('Skipping test due to unset REMOZILLA_USERNAME.')

        previous_last_updated_time = get_last_updated_date()

        first_request = requests.Request()
        first_request.status_code = 200
        bug_data = {
            'bugs': [{
                'id':
                7788,
                'summary':
                'This is summary',
                'creator': {
                    'name': '*****@*****.**'
                },
                'creation_time':
                '2010-10-5T13:45:23Z',
                'component':
                'Swag Requests',
                'whiteboard':
                'This is whiteboard',
                'cc': [{
                    'name': '*****@*****.**'
                }, {
                    'name': '*****@*****.**'
                }],
                'assigned_to': {
                    'name': '*****@*****.**'
                },
                'status':
                'resolved',
                'resolution':
                'invalid',
                'cf_due_date':
                None
            }, {
                'id':
                1199,
                'summary':
                'New summary',
                'creator': {
                    'name': '*****@*****.**'
                },
                'creation_time':
                '2012-12-5T11:30:23Z',
                'component':
                'Swag requests',
                'cc': [{
                    'name': '*****@*****.**'
                }, {
                    'name': '*****@*****.**'
                }],
                'assigned_to': {
                    'name': '*****@*****.**'
                },
                'status':
                'resolved',
                'resolution':
                'invalid',
                'cf_due_date':
                None
            }]
        }

        first_request.text = json.dumps(bug_data)

        second_request = requests.Request()
        second_request.status_code = 200
        bug_data['bugs'][0]['component'] = 'Planning'
        bug_data['bugs'][0]['id'] = 7789
        bug_data['bugs'][1]['component'] = 'Planning'
        bug_data['bugs'][1]['id'] = 1200
        second_request.text = json.dumps(bug_data)

        empty_request = requests.Request()
        empty_request.status_code = 200
        empty_request.text = json.dumps({'bugs': []})

        fake_requests_obj.expects_call()
        fake_requests_obj.returns(first_request)
        fake_requests_obj.next_call().returns(empty_request)
        fake_requests_obj.next_call().returns(second_request)
        fake_requests_obj.next_call().returns(empty_request)

        fetch_bugs(components=['Planning', 'Swag Requests'])

        eq_(Bug.objects.all().count(), 4)
        eq_(Bug.objects.filter(component='Planning').count(), 2)
        eq_(Bug.objects.filter(component='Swag Requests').count(), 2)

        # refresh status_obj
        self.assertGreater(get_last_updated_date(), previous_last_updated_time)

        bug = Bug.objects.get(bug_id=7788)
        eq_(bug.cc.all().count(), 1)
        eq_(bug.assigned_to.email, '*****@*****.**')
        eq_(bug.due_date, None)
        eq_(bug.resolution, 'INVALID')

        bug = Bug.objects.get(bug_id=1199)
        eq_(bug.creator, None)
        eq_(bug.cc.all().count(), 1)