Esempio n. 1
0
    def test_fetch_empty(self):
        """Test whethet it works when no bugs are fetched"""

        body = read_file('data/bugzilla_version.xml')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_METADATA_URL,
                               body=body, status=200)
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               body="", status=200)

        from_date = datetime.datetime(2100, 1, 1)


        bg = Bugzilla(BUGZILLA_SERVER_URL)
        bugs = [bug for bug in bg.fetch(from_date=from_date)]

        self.assertEqual(len(bugs), 0)

        # Check request
        expected = {
                     'ctype' : ['csv'],
                     'order' : ['changeddate'],
                     'chfieldfrom' : ['2100-01-01 00:00:00']
                    }

        req = httpretty.last_request()

        self.assertDictEqual(req.querystring, expected)
Esempio n. 2
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        bg = Bugzilla(BUGZILLA_SERVER_URL, max_bugs=5)

        with self.assertRaises(CacheError):
            _ = [bug for bug in bg.fetch_from_cache()]
Esempio n. 3
0
    def test_fetch_empty(self):
        """Test whethet it works when no bugs are fetched"""

        body = read_file('data/bugzilla_version.xml')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_METADATA_URL,
                               body=body,
                               status=200)
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               body="",
                               status=200)

        from_date = datetime.datetime(2100, 1, 1)

        bg = Bugzilla(BUGZILLA_SERVER_URL)
        bugs = [bug for bug in bg.fetch(from_date=from_date)]

        self.assertEqual(len(bugs), 0)

        # Check request
        expected = {
            'ctype': ['csv'],
            'order': ['changeddate'],
            'chfieldfrom': ['2100-01-01 00:00:00']
        }

        req = httpretty.last_request()

        self.assertDictEqual(req.querystring, expected)
Esempio n. 4
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        bg = Bugzilla(BUGZILLA_SERVER_URL, max_bugs=5)

        with self.assertRaises(CacheError):
            _ = [bug for bug in bg.fetch_from_cache()]
Esempio n. 5
0
    def test_fetch_from_empty_cache(self):
        """Test if there are not any bugs returned when the cache is empty"""

        cache = Cache(self.tmp_path)
        bg = Bugzilla(BUGZILLA_SERVER_URL, max_bugs=5, cache=cache)

        cached_bugs = [bug for bug in bg.fetch_from_cache()]
        self.assertEqual(len(cached_bugs), 0)
Esempio n. 6
0
    def test_fetch_from_empty_cache(self):
        """Test if there are not any bugs returned when the cache is empty"""

        cache = Cache(self.tmp_path)
        bg = Bugzilla(BUGZILLA_SERVER_URL, max_bugs=5, cache=cache)

        cached_bugs = [bug for bug in bg.fetch_from_cache()]
        self.assertEqual(len(cached_bugs), 0)
Esempio n. 7
0
    def test_parse_activity(self):
        """Test activity bug parsing"""

        raw_html = read_file('data/bugzilla_bug_activity.html')

        activity = Bugzilla.parse_bug_activity(raw_html)
        result = [event for event in activity]

        self.assertEqual(len(result), 14)

        expected = {
            'Who': '*****@*****.**',
            'When': '2013-06-25 11:57:23 CEST',
            'What': 'Attachment #172 Attachment is obsolete',
            'Removed': '0',
            'Added': '1'
        }
        self.assertDictEqual(result[0], expected)

        expected = {
            'Who': '*****@*****.**',
            'When': '2013-06-25 11:59:07 CEST',
            'What': 'Depends on',
            'Removed': '350',
            'Added': ''
        }
        self.assertDictEqual(result[6], expected)
Esempio n. 8
0
    def test_parse_activity(self):
        """Test activity bug parsing"""

        raw_html = read_file('data/bugzilla_bug_activity.html')

        activity = Bugzilla.parse_bug_activity(raw_html)
        result = [event for event in activity]

        self.assertEqual(len(result), 14)

        expected = {
                    'Who' : '*****@*****.**',
                    'When' : '2013-06-25 11:57:23 CEST',
                    'What' : 'Attachment #172 Attachment is obsolete',
                    'Removed' : '0',
                    'Added' : '1'
                   }
        self.assertDictEqual(result[0], expected)

        expected = {
                    'Who' : '*****@*****.**',
                    'When' : '2013-06-25 11:59:07 CEST',
                    'What' : 'Depends on',
                    'Removed' : '350',
                    'Added' : ''
                   }
        self.assertDictEqual(result[6], expected)
Esempio n. 9
0
    def test_parse_activity_no_table(self):
        """Test if it raises an exception the activity table is not found"""

        raw_html = read_file('data/bugzilla_bug_activity_not_valid.html')

        with self.assertRaises(ParseError):
            activity = Bugzilla.parse_bug_activity(raw_html)
            _ = [event for event in activity]
Esempio n. 10
0
    def test_parse_empty_activity(self):
        """Test the parser when the activity table is empty"""

        raw_html = read_file('data/bugzilla_bug_activity_empty.html')

        activity = Bugzilla.parse_bug_activity(raw_html)
        result = [event for event in activity]
        self.assertEqual(len(result), 0)
Esempio n. 11
0
    def test_parse_invalid_bug_details(self):
        """Test whether it fails parsing an invalid XML with no bugs"""

        raw_xml = read_file('data/bugzilla_bugs_details_not_valid.xml')

        with self.assertRaises(ParseError):
            bugs = Bugzilla.parse_bugs_details(raw_xml)
            _ = [bug for bug in bugs]
Esempio n. 12
0
    def test_parse_empty_activity(self):
        """Test the parser when the activity table is empty"""

        raw_html = read_file('data/bugzilla_bug_activity_empty.html')

        activity = Bugzilla.parse_bug_activity(raw_html)
        result = [event for event in activity]
        self.assertEqual(len(result), 0)
Esempio n. 13
0
    def test_parse_activity_no_table(self):
        """Test if it raises an exception the activity table is not found"""

        raw_html = read_file('data/bugzilla_bug_activity_not_valid.html')

        with self.assertRaises(ParseError):
            activity = Bugzilla.parse_bug_activity(raw_html)
            _ = [event for event in activity]
Esempio n. 14
0
    def test_parse_invalid_bug_details(self):
        """Test whether it fails parsing an invalid XML with no bugs"""

        raw_xml = read_file('data/bugzilla_bugs_details_not_valid.xml')

        with self.assertRaises(ParseError):
            bugs = Bugzilla.parse_bugs_details(raw_xml)
            _ = [bug for bug in bugs]
Esempio n. 15
0
    def test_parse_empty_activity(self):
        """Test the parser when the activity table is empty"""

        # There are two possible cases for empty tables.
        # The first case includes the term 'bug' while the second
        # one replaces it by 'issue'.

        raw_html = read_file('data/bugzilla_bug_activity_empty.html')

        activity = Bugzilla.parse_bug_activity(raw_html)
        result = [event for event in activity]
        self.assertEqual(len(result), 0)

        raw_html = read_file('data/bugzilla_bug_activity_empty_alt.html')

        activity = Bugzilla.parse_bug_activity(raw_html)
        result = [event for event in activity]
        self.assertEqual(len(result), 0)
Esempio n. 16
0
    def test_parse_empty_activity(self):
        """Test the parser when the activity table is empty"""

        # There are two possible cases for empty tables.
        # The first case includes the term 'bug' while the second
        # one replaces it by 'issue'.

        raw_html = read_file('data/bugzilla_bug_activity_empty.html')

        activity = Bugzilla.parse_bug_activity(raw_html)
        result = [event for event in activity]
        self.assertEqual(len(result), 0)

        raw_html = read_file('data/bugzilla_bug_activity_empty_alt.html')

        activity = Bugzilla.parse_bug_activity(raw_html)
        result = [event for event in activity]
        self.assertEqual(len(result), 0)
Esempio n. 17
0
    def test_initialization(self):
        """Test whether attributes are initializated"""

        bg = Bugzilla(BUGZILLA_SERVER_URL, origin='test', max_bugs=5)

        self.assertEqual(bg.url, BUGZILLA_SERVER_URL)
        self.assertEqual(bg.origin, 'test')
        self.assertEqual(bg.max_bugs, 5)
        self.assertIsInstance(bg.client, BugzillaClient)

        # When origin is empty or None it will be set to
        # the value in url
        bg = Bugzilla(BUGZILLA_SERVER_URL)
        self.assertEqual(bg.url, BUGZILLA_SERVER_URL)
        self.assertEqual(bg.origin, BUGZILLA_SERVER_URL)

        bg = Bugzilla(BUGZILLA_SERVER_URL, origin='')
        self.assertEqual(bg.url, BUGZILLA_SERVER_URL)
        self.assertEqual(bg.origin, BUGZILLA_SERVER_URL)
Esempio n. 18
0
    def test_parse_buglist(self):
        """Test buglist parsing"""

        raw_csv = read_file('data/bugzilla_buglist.csv')

        bugs = Bugzilla.parse_buglist(raw_csv)
        result = [bug for bug in bugs]

        self.assertEqual(len(result), 5)
        self.assertEqual(result[0]['bug_id'], '15')
        self.assertEqual(result[4]['bug_id'], '19')
Esempio n. 19
0
    def test_parse_bugs_details(self):
        """Test bugs details parsing"""

        raw_xml = read_file('data/bugzilla_bugs_details.xml')

        bugs = Bugzilla.parse_bugs_details(raw_xml)
        result = [bug for bug in bugs]

        self.assertEqual(len(result), 5)

        bug_ids = [bug['bug_id'][0]['__text__'] \
                   for bug in result]
        expected = ['15', '18', '17', '20', '19']

        self.assertListEqual(bug_ids, expected)

        raw_xml = read_file('data/bugzilla_bugs_details_next.xml')

        bugs = Bugzilla.parse_bugs_details(raw_xml)
        result = [bug for bug in bugs]
Esempio n. 20
0
    def test_parse_bugs_details(self):
        """Test bugs details parsing"""

        raw_xml = read_file('data/bugzilla_bugs_details.xml')

        bugs = Bugzilla.parse_bugs_details(raw_xml)
        result = [bug for bug in bugs]

        self.assertEqual(len(result), 5)

        bug_ids = [bug['bug_id'][0]['__text__'] \
                   for bug in result]
        expected = ['15', '18', '17', '20', '19']

        self.assertListEqual(bug_ids, expected)

        raw_xml = read_file('data/bugzilla_bugs_details_next.xml')

        bugs = Bugzilla.parse_bugs_details(raw_xml)
        result = [bug for bug in bugs]
Esempio n. 21
0
    def test_parse_buglist(self):
        """Test buglist parsing"""

        raw_csv = read_file('data/bugzilla_buglist.csv')

        bugs = Bugzilla.parse_buglist(raw_csv)
        result = [bug for bug in bugs]

        self.assertEqual(len(result), 5)
        self.assertEqual(result[0]['bug_id'], '15')
        self.assertEqual(result[4]['bug_id'], '19')
Esempio n. 22
0
    def test_fetch_auth(self):
        """Test whether authentication works"""

        requests = []
        bodies_csv = [read_file('data/bugzilla_buglist_next.csv'), ""]
        bodies_xml = [
            read_file('data/bugzilla_version.xml', mode='rb'),
            read_file('data/bugzilla_bugs_details_next.xml', mode='rb')
        ]
        bodies_html = [
            read_file('data/bugzilla_bug_activity.html', mode='rb'),
            read_file('data/bugzilla_bug_activity_empty.html', mode='rb')
        ]

        def request_callback(method, uri, headers):
            if uri.startswith(BUGZILLA_LOGIN_URL):
                body = "index.cgi?logout=1"
            elif uri.startswith(BUGZILLA_BUGLIST_URL):
                body = bodies_csv.pop(0)
            elif uri.startswith(BUGZILLA_BUG_URL):
                body = bodies_xml.pop(0)
            else:
                body = bodies_html[(len(requests) + 1) % 2]

            requests.append(httpretty.last_request())

            return (200, headers, body)

        httpretty.register_uri(
            httpretty.POST,
            BUGZILLA_LOGIN_URL,
            responses=[httpretty.Response(body=request_callback)])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])
        httpretty.register_uri(
            httpretty.GET,
            BUGZILLA_BUG_URL,
            responses=[httpretty.Response(body=request_callback)])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_ACTIVITY_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])

        from_date = datetime.datetime(2015, 1, 1)

        bg = Bugzilla(BUGZILLA_SERVER_URL,
                      user='******',
                      password='******')
        bugs = [bug for bug in bg.fetch(from_date=from_date)]

        self.assertEqual(len(bugs), 2)
        self.assertEqual(bugs[0]['data']['bug_id'][0]['__text__'], '30')
        self.assertEqual(len(bugs[0]['data']['activity']), 14)
        self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[0]['uuid'],
                         '4b166308f205121bc57704032acdc81b6c9bb8b1')
        self.assertEqual(bugs[0]['updated_on'], 1426868155.0)

        self.assertEqual(bugs[1]['data']['bug_id'][0]['__text__'], '888')
        self.assertEqual(len(bugs[1]['data']['activity']), 0)
        self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[1]['uuid'],
                         'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
        self.assertEqual(bugs[1]['updated_on'], 1439404330.0)

        # Check requests
        auth_expected = {
            'Bugzilla_login': ['*****@*****.**'],
            'Bugzilla_password': ['1234'],
            'GoAheadAndLogIn': ['Log in']
        }
        expected = [{
            'ctype': ['xml']
        }, {
            'ctype': ['csv'],
            'order': ['changeddate'],
            'chfieldfrom': ['2015-01-01 00:00:00']
        }, {
            'ctype': ['csv'],
            'order': ['changeddate'],
            'chfieldfrom': ['2015-08-12 18:32:11']
        }, {
            'ctype': ['xml'],
            'id': ['30', '888'],
            'excludefield': ['attachmentdata']
        }, {
            'id': ['30']
        }, {
            'id': ['888']
        }]

        # Check authentication request
        auth_req = requests.pop(0)
        self.assertDictEqual(auth_req.parsed_body, auth_expected)

        # Check the rests of the headers
        self.assertEqual(len(requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(requests[i].querystring, expected[i])
Esempio n. 23
0
    def test_has_resuming(self):
        """Test if it returns True when has_resuming is called"""

        self.assertEqual(Bugzilla.has_resuming(), True)
Esempio n. 24
0
    def test_has_resuming(self):
        """Test if it returns True when has_resuming is called"""

        self.assertEqual(Bugzilla.has_resuming(), True)
Esempio n. 25
0
    def test_fetch_from_date(self):
        """Test whether a list of bugs is returned from a given date"""

        requests = []
        bodies_csv = [read_file('data/bugzilla_buglist_next.csv'), ""]
        bodies_xml = [
            read_file('data/bugzilla_version.xml', mode='rb'),
            read_file('data/bugzilla_bugs_details_next.xml', mode='rb')
        ]
        bodies_html = [
            read_file('data/bugzilla_bug_activity.html', mode='rb'),
            read_file('data/bugzilla_bug_activity_empty.html', mode='rb')
        ]

        def request_callback(method, uri, headers):
            if uri.startswith(BUGZILLA_BUGLIST_URL):
                body = bodies_csv.pop(0)
            elif uri.startswith(BUGZILLA_BUG_URL):
                body = bodies_xml.pop(0)
            else:
                body = bodies_html[len(requests) % 2]

            requests.append(httpretty.last_request())

            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])
        httpretty.register_uri(
            httpretty.GET,
            BUGZILLA_BUG_URL,
            responses=[httpretty.Response(body=request_callback)])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_ACTIVITY_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])

        from_date = datetime.datetime(2015, 1, 1)

        bg = Bugzilla(BUGZILLA_SERVER_URL)
        bugs = [bug for bug in bg.fetch(from_date=from_date)]

        self.assertEqual(len(bugs), 2)
        self.assertEqual(bugs[0]['data']['bug_id'][0]['__text__'], '30')
        self.assertEqual(len(bugs[0]['data']['activity']), 14)
        self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[0]['uuid'],
                         '4b166308f205121bc57704032acdc81b6c9bb8b1')
        self.assertEqual(bugs[0]['updated_on'], 1426868155.0)

        self.assertEqual(bugs[1]['data']['bug_id'][0]['__text__'], '888')
        self.assertEqual(len(bugs[1]['data']['activity']), 0)
        self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[1]['uuid'],
                         'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
        self.assertEqual(bugs[1]['updated_on'], 1439404330.0)

        # Check requests
        expected = [{
            'ctype': ['xml']
        }, {
            'ctype': ['csv'],
            'order': ['changeddate'],
            'chfieldfrom': ['2015-01-01 00:00:00']
        }, {
            'ctype': ['csv'],
            'order': ['changeddate'],
            'chfieldfrom': ['2015-08-12 18:32:11']
        }, {
            'ctype': ['xml'],
            'id': ['30', '888'],
            'excludefield': ['attachmentdata']
        }, {
            'id': ['30']
        }, {
            'id': ['888']
        }]

        self.assertEqual(len(requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(requests[i].querystring, expected[i])
Esempio n. 26
0
    def test_fetch_from_date(self):
        """Test whether a list of bugs is returned from a given date"""

        requests = []
        bodies_csv = [read_file('data/bugzilla_buglist_next.csv'),
                      ""]
        bodies_xml = [read_file('data/bugzilla_version.xml', mode='rb'),
                      read_file('data/bugzilla_bugs_details_next.xml', mode='rb')]
        bodies_html = [read_file('data/bugzilla_bug_activity.html', mode='rb'),
                       read_file('data/bugzilla_bug_activity_empty.html', mode='rb')]

        def request_callback(method, uri, headers):
            if uri.startswith(BUGZILLA_BUGLIST_URL):
                body = bodies_csv.pop(0)
            elif uri.startswith(BUGZILLA_BUG_URL):
                body = bodies_xml.pop(0)
            else:
                body = bodies_html[len(requests) % 2]

            requests.append(httpretty.last_request())

            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_URL,
                               responses=[
                                    httpretty.Response(body=request_callback)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_ACTIVITY_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])

        from_date = datetime.datetime(2015, 1, 1)

        bg = Bugzilla(BUGZILLA_SERVER_URL)
        bugs = [bug for bug in bg.fetch(from_date=from_date)]

        self.assertEqual(len(bugs), 2)
        self.assertEqual(bugs[0]['data']['bug_id'][0]['__text__'], '30')
        self.assertEqual(len(bugs[0]['data']['activity']), 14)
        self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[0]['uuid'], '4b166308f205121bc57704032acdc81b6c9bb8b1')
        self.assertEqual(bugs[0]['updated_on'], 1426868155.0)
        self.assertEqual(bugs[0]['category'], 'bug')

        self.assertEqual(bugs[1]['data']['bug_id'][0]['__text__'], '888')
        self.assertEqual(len(bugs[1]['data']['activity']), 0)
        self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[1]['uuid'], 'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
        self.assertEqual(bugs[1]['updated_on'], 1439404330.0)
        self.assertEqual(bugs[1]['category'], 'bug')

        # Check requests
        expected = [{
                     'ctype' : ['xml']
                    },
                    {
                     'ctype' : ['csv'],
                     'order' : ['changeddate'],
                     'chfieldfrom' : ['2015-01-01 00:00:00']
                    },
                    {
                     'ctype' : ['csv'],
                     'order' : ['changeddate'],
                     'chfieldfrom' : ['2015-08-12 18:32:11']
                    },
                    {
                     'ctype' : ['xml'],
                     'id' : ['30', '888'],
                     'excludefield' : ['attachmentdata']
                    },
                    {
                     'id' : ['30']
                    },
                    {
                     'id' : ['888']
                    }]

        self.assertEqual(len(requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(requests[i].querystring, expected[i])
Esempio n. 27
0
    def test_fetch_auth(self):
        """Test whether authentication works"""

        requests = []
        bodies_csv = [read_file('data/bugzilla_buglist_next.csv'),
                      ""]
        bodies_xml = [read_file('data/bugzilla_version.xml', mode='rb'),
                      read_file('data/bugzilla_bugs_details_next.xml', mode='rb')]
        bodies_html = [read_file('data/bugzilla_bug_activity.html', mode='rb'),
                       read_file('data/bugzilla_bug_activity_empty.html', mode='rb')]

        def request_callback(method, uri, headers):
            if uri.startswith(BUGZILLA_LOGIN_URL):
                body="index.cgi?logout=1"
            elif uri.startswith(BUGZILLA_BUGLIST_URL):
                body = bodies_csv.pop(0)
            elif uri.startswith(BUGZILLA_BUG_URL):
                body = bodies_xml.pop(0)
            else:
                body = bodies_html[(len(requests) + 1) % 2]

            requests.append(httpretty.last_request())

            return (200, headers, body)

        httpretty.register_uri(httpretty.POST,
                               BUGZILLA_LOGIN_URL,
                               responses=[
                                    httpretty.Response(body=request_callback)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_URL,
                               responses=[
                                    httpretty.Response(body=request_callback)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_ACTIVITY_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])

        from_date = datetime.datetime(2015, 1, 1)

        bg = Bugzilla(BUGZILLA_SERVER_URL,
                      user='******',
                      password='******')
        bugs = [bug for bug in bg.fetch(from_date=from_date)]

        self.assertEqual(len(bugs), 2)
        self.assertEqual(bugs[0]['data']['bug_id'][0]['__text__'], '30')
        self.assertEqual(len(bugs[0]['data']['activity']), 14)
        self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[0]['uuid'], '4b166308f205121bc57704032acdc81b6c9bb8b1')
        self.assertEqual(bugs[0]['updated_on'], 1426868155.0)

        self.assertEqual(bugs[1]['data']['bug_id'][0]['__text__'], '888')
        self.assertEqual(len(bugs[1]['data']['activity']), 0)
        self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[1]['uuid'], 'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
        self.assertEqual(bugs[1]['updated_on'], 1439404330.0)

        # Check requests
        auth_expected = {
                         'Bugzilla_login' : ['*****@*****.**'],
                         'Bugzilla_password' : ['1234'],
                         'GoAheadAndLogIn' : ['Log in']
                        }
        expected = [{
                     'ctype' : ['xml']
                    },
                    {
                     'ctype' : ['csv'],
                     'order' : ['changeddate'],
                     'chfieldfrom' : ['2015-01-01 00:00:00']
                    },
                    {
                     'ctype' : ['csv'],
                     'order' : ['changeddate'],
                     'chfieldfrom' : ['2015-08-12 18:32:11']
                    },
                    {
                     'ctype' : ['xml'],
                     'id' : ['30', '888'],
                     'excludefield' : ['attachmentdata']
                    },
                    {
                     'id' : ['30']
                    },
                    {
                     'id' : ['888']
                    }]

        # Check authentication request
        auth_req = requests.pop(0)
        self.assertDictEqual(auth_req.parsed_body, auth_expected)

        # Check the rests of the headers
        self.assertEqual(len(requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(requests[i].querystring, expected[i])
Esempio n. 28
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        requests = []
        bodies_csv = [
            read_file('data/bugzilla_buglist.csv'),
            read_file('data/bugzilla_buglist_next.csv'), ""
        ]
        bodies_xml = [
            read_file('data/bugzilla_version.xml', mode='rb'),
            read_file('data/bugzilla_bugs_details.xml', mode='rb'),
            read_file('data/bugzilla_bugs_details_next.xml', mode='rb')
        ]
        bodies_html = [
            read_file('data/bugzilla_bug_activity.html', mode='rb'),
            read_file('data/bugzilla_bug_activity_empty.html', mode='rb')
        ]

        def request_callback(method, uri, headers):
            if uri.startswith(BUGZILLA_BUGLIST_URL):
                body = bodies_csv.pop(0)
            elif uri.startswith(BUGZILLA_BUG_URL):
                body = bodies_xml.pop(0)
            else:
                body = bodies_html[len(requests) % 2]

            requests.append(httpretty.last_request())

            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(3)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_ACTIVITY_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(7)
                               ])

        # First, we fetch the bugs from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        bg = Bugzilla(BUGZILLA_SERVER_URL, max_bugs=5, cache=cache)

        bugs = [bug for bug in bg.fetch()]
        self.assertEqual(len(requests), 13)

        # Now, we get the bugs from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cached_bugs = [bug for bug in bg.fetch_from_cache()]
        self.assertEqual(len(cached_bugs), len(bugs))

        self.assertEqual(len(cached_bugs), 7)

        self.assertEqual(cached_bugs[0]['data']['bug_id'][0]['__text__'], '15')
        self.assertEqual(len(cached_bugs[0]['data']['activity']), 0)
        self.assertEqual(cached_bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(cached_bugs[0]['uuid'],
                         '5a8a1e25dfda86b961b4146050883cbfc928f8ec')
        self.assertEqual(cached_bugs[0]['updated_on'], 1248276445.0)

        self.assertEqual(cached_bugs[6]['data']['bug_id'][0]['__text__'],
                         '888')
        self.assertEqual(len(cached_bugs[6]['data']['activity']), 14)
        self.assertEqual(cached_bugs[6]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(cached_bugs[6]['uuid'],
                         'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
        self.assertEqual(cached_bugs[6]['updated_on'], 1439404330.0)

        self.assertEqual(len(requests), 13)
Esempio n. 29
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        requests = []
        bodies_csv = [read_file('data/bugzilla_buglist.csv'),
                      read_file('data/bugzilla_buglist_next.csv'),
                      ""]
        bodies_xml = [read_file('data/bugzilla_version.xml', mode='rb'),
                      read_file('data/bugzilla_bugs_details.xml', mode='rb'),
                      read_file('data/bugzilla_bugs_details_next.xml', mode='rb')]
        bodies_html = [read_file('data/bugzilla_bug_activity.html', mode='rb'),
                       read_file('data/bugzilla_bug_activity_empty.html', mode='rb')]

        def request_callback(method, uri, headers):
            if uri.startswith(BUGZILLA_BUGLIST_URL):
                body = bodies_csv.pop(0)
            elif uri.startswith(BUGZILLA_BUG_URL):
                body = bodies_xml.pop(0)
            else:
                body = bodies_html[len(requests) % 2]

            requests.append(httpretty.last_request())

            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(3)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_ACTIVITY_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(7)
                               ])

        # First, we fetch the bugs from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        bg = Bugzilla(BUGZILLA_SERVER_URL, max_bugs=5, cache=cache)

        bugs = [bug for bug in bg.fetch()]
        self.assertEqual(len(requests), 13)

        # Now, we get the bugs from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cached_bugs = [bug for bug in bg.fetch_from_cache()]
        self.assertEqual(len(cached_bugs), len(bugs))

        self.assertEqual(len(cached_bugs), 7)

        self.assertEqual(cached_bugs[0]['data']['bug_id'][0]['__text__'], '15')
        self.assertEqual(len(cached_bugs[0]['data']['activity']), 0)
        self.assertEqual(cached_bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(cached_bugs[0]['uuid'], '5a8a1e25dfda86b961b4146050883cbfc928f8ec')
        self.assertEqual(cached_bugs[0]['updated_on'], 1248276445.0)
        self.assertEqual(cached_bugs[0]['category'], 'bug')

        self.assertEqual(cached_bugs[6]['data']['bug_id'][0]['__text__'], '888')
        self.assertEqual(len(cached_bugs[6]['data']['activity']), 14)
        self.assertEqual(cached_bugs[6]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(cached_bugs[6]['uuid'], 'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
        self.assertEqual(cached_bugs[6]['updated_on'], 1439404330.0)
        self.assertEqual(cached_bugs[6]['category'], 'bug')

        self.assertEqual(len(requests), 13)
Esempio n. 30
0
    def test_fetch(self):
        """Test whether a list of bugs is returned"""

        requests = []
        bodies_csv = [
            read_file('data/bugzilla_buglist.csv'),
            read_file('data/bugzilla_buglist_next.csv'), ""
        ]
        bodies_xml = [
            read_file('data/bugzilla_version.xml', mode='rb'),
            read_file('data/bugzilla_bugs_details.xml', mode='rb'),
            read_file('data/bugzilla_bugs_details_next.xml', mode='rb')
        ]
        bodies_html = [
            read_file('data/bugzilla_bug_activity.html', mode='rb'),
            read_file('data/bugzilla_bug_activity_empty.html', mode='rb')
        ]

        def request_callback(method, uri, headers):
            if uri.startswith(BUGZILLA_BUGLIST_URL):
                body = bodies_csv.pop(0)
            elif uri.startswith(BUGZILLA_BUG_URL):
                body = bodies_xml.pop(0)
            else:
                body = bodies_html[len(requests) % 2]

            requests.append(httpretty.last_request())

            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(3)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_ACTIVITY_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(7)
                               ])

        bg = Bugzilla(BUGZILLA_SERVER_URL, max_bugs=5)
        bugs = [bug for bug in bg.fetch()]

        self.assertEqual(len(bugs), 7)

        self.assertEqual(bugs[0]['data']['bug_id'][0]['__text__'], '15')
        self.assertEqual(len(bugs[0]['data']['activity']), 0)
        self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[0]['uuid'],
                         '5a8a1e25dfda86b961b4146050883cbfc928f8ec')
        self.assertEqual(bugs[0]['updated_on'], 1248276445.0)

        self.assertEqual(bugs[6]['data']['bug_id'][0]['__text__'], '888')
        self.assertEqual(len(bugs[6]['data']['activity']), 14)
        self.assertEqual(bugs[6]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[6]['uuid'],
                         'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
        self.assertEqual(bugs[6]['updated_on'], 1439404330.0)

        # Check requests
        expected = [{
            'ctype': ['xml']
        }, {
            'ctype': ['csv'],
            'order': ['changeddate'],
            'chfieldfrom': ['1970-01-01 00:00:00']
        }, {
            'ctype': ['csv'],
            'order': ['changeddate'],
            'chfieldfrom': ['2009-07-30 11:35:33']
        }, {
            'ctype': ['csv'],
            'order': ['changeddate'],
            'chfieldfrom': ['2015-08-12 18:32:11']
        }, {
            'ctype': ['xml'],
            'id': ['15', '18', '17', '20', '19'],
            'excludefield': ['attachmentdata']
        }, {
            'id': ['15']
        }, {
            'id': ['18']
        }, {
            'id': ['17']
        }, {
            'id': ['20']
        }, {
            'id': ['19']
        }, {
            'ctype': ['xml'],
            'id': ['30', '888'],
            'excludefield': ['attachmentdata']
        }, {
            'id': ['30']
        }, {
            'id': ['888']
        }]

        self.assertEqual(len(requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(requests[i].querystring, expected[i])
Esempio n. 31
0
    def test_fetch(self):
        """Test whether a list of bugs is returned"""

        requests = []
        bodies_csv = [read_file('data/bugzilla_buglist.csv'),
                      read_file('data/bugzilla_buglist_next.csv'),
                      ""]
        bodies_xml = [read_file('data/bugzilla_version.xml', mode='rb'),
                      read_file('data/bugzilla_bugs_details.xml', mode='rb'),
                      read_file('data/bugzilla_bugs_details_next.xml', mode='rb')]
        bodies_html = [read_file('data/bugzilla_bug_activity.html', mode='rb'),
                       read_file('data/bugzilla_bug_activity_empty.html', mode='rb')]

        def request_callback(method, uri, headers):
            if uri.startswith(BUGZILLA_BUGLIST_URL):
                body = bodies_csv.pop(0)
            elif uri.startswith(BUGZILLA_BUG_URL):
                body = bodies_xml.pop(0)
            else:
                body = bodies_html[len(requests) % 2]

            requests.append(httpretty.last_request())

            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(3)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_ACTIVITY_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(7)
                               ])

        bg = Bugzilla(BUGZILLA_SERVER_URL, max_bugs=5)
        bugs = [bug for bug in bg.fetch()]

        self.assertEqual(len(bugs), 7)

        self.assertEqual(bugs[0]['data']['bug_id'][0]['__text__'], '15')
        self.assertEqual(len(bugs[0]['data']['activity']), 0)
        self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[0]['uuid'], '5a8a1e25dfda86b961b4146050883cbfc928f8ec')
        self.assertEqual(bugs[0]['updated_on'], 1248276445.0)
        self.assertEqual(bugs[0]['category'], 'bug')

        self.assertEqual(bugs[6]['data']['bug_id'][0]['__text__'], '888')
        self.assertEqual(len(bugs[6]['data']['activity']), 14)
        self.assertEqual(bugs[6]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[6]['uuid'], 'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
        self.assertEqual(bugs[6]['updated_on'], 1439404330.0)
        self.assertEqual(bugs[0]['category'], 'bug')

        # Check requests
        expected = [{
                     'ctype' : ['xml']
                    },
                    {
                     'ctype' : ['csv'],
                     'order' : ['changeddate'],
                     'chfieldfrom' : ['1970-01-01 00:00:00']
                    },
                    {
                     'ctype' : ['csv'],
                     'order' : ['changeddate'],
                     'chfieldfrom' : ['2009-07-30 11:35:33']
                    },
                    {
                     'ctype' : ['csv'],
                     'order' : ['changeddate'],
                     'chfieldfrom' : ['2015-08-12 18:32:11']
                    },
                    {
                     'ctype' : ['xml'],
                     'id' : ['15', '18', '17', '20', '19'],
                     'excludefield' : ['attachmentdata']
                    },
                    {
                     'id' : ['15']
                    },
                    {
                     'id' : ['18']
                    },
                    {
                     'id' : ['17']
                    },
                    {
                     'id' : ['20']
                    },
                    {
                     'id' : ['19']
                    },
                    {
                     'ctype' : ['xml'],
                     'id' : ['30', '888'],
                     'excludefield' : ['attachmentdata']
                    },
                    {
                     'id' : ['30']
                    },
                    {
                     'id' : ['888']
                    }]

        self.assertEqual(len(requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(requests[i].querystring, expected[i])