Exemplo n.º 1
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 = BugzillaREST(BUGZILLA_SERVER_URL, cache=cache)
        cached_bugs = [bug for bug in bg.fetch_from_cache()]
        self.assertEqual(len(cached_bugs), 0)
Exemplo n.º 2
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        bg = BugzillaREST(BUGZILLA_SERVER_URL)

        with self.assertRaises(CacheError):
            _ = [bug for bug in bg.fetch_from_cache()]
Exemplo n.º 3
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 = BugzillaREST(BUGZILLA_SERVER_URL, cache=cache)
        cached_bugs = [bug for bug in bg.fetch_from_cache()]
        self.assertEqual(len(cached_bugs), 0)
Exemplo n.º 4
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        bg = BugzillaREST(BUGZILLA_SERVER_URL)

        with self.assertRaises(CacheError):
            _ = [bug for bug in bg.fetch_from_cache()]
Exemplo n.º 5
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        http_requests = setup_http_server()

        # First, we fetch the topics from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        bg = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2, cache=cache)

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

        # Now, we get the topics 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), 3)

        self.assertEqual(bugs[0]['data']['id'], 1273442)
        self.assertEqual(len(bugs[0]['data']['comments']), 7)
        self.assertEqual(len(bugs[0]['data']['history']), 6)
        self.assertEqual(len(bugs[0]['data']['attachments']), 1)
        self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[0]['uuid'],
                         '68494ad0072ed9e09cecb8235649a38c443326db')
        self.assertEqual(bugs[0]['updated_on'], 1465257689.0)
        self.assertEqual(bugs[0]['category'], 'bug')
        self.assertEqual(bugs[0]['tag'], BUGZILLA_SERVER_URL)

        self.assertEqual(bugs[1]['data']['id'], 1273439)
        self.assertEqual(len(bugs[1]['data']['comments']), 0)
        self.assertEqual(len(bugs[1]['data']['history']), 0)
        self.assertEqual(len(bugs[1]['data']['attachments']), 0)
        self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[1]['uuid'],
                         'd306162de06bc759f9bd9227fe3fd5f08aeb0dde')
        self.assertEqual(bugs[1]['updated_on'], 1465257715.0)
        self.assertEqual(bugs[1]['category'], 'bug')
        self.assertEqual(bugs[1]['tag'], BUGZILLA_SERVER_URL)

        self.assertEqual(bugs[2]['data']['id'], 947945)
        self.assertEqual(len(bugs[2]['data']['comments']), 0)
        self.assertEqual(len(bugs[2]['data']['history']), 0)
        self.assertEqual(len(bugs[2]['data']['attachments']), 0)
        self.assertEqual(bugs[2]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[2]['uuid'],
                         '33edda925351c3310fc3e12d7f18a365c365f6bd')
        self.assertEqual(bugs[2]['updated_on'], 1465257743.0)
        self.assertEqual(bugs[2]['category'], 'bug')
        self.assertEqual(bugs[2]['tag'], BUGZILLA_SERVER_URL)

        # No more requests were sent
        self.assertEqual(len(http_requests), 9)
Exemplo n.º 6
0
    def test_fetch_empty(self):
        """Test whether it works when no bugs are fetched"""

        body = read_file("data/bugzilla_rest_bugs_empty.json")
        httpretty.register_uri(httpretty.GET, BUGZILLA_BUGS_URL, body=body, status=200)

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

        self.assertEqual(len(bugs), 0)
Exemplo n.º 7
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        http_requests = setup_http_server()

        # First, we fetch the topics from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        bg = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2,
                          cache=cache)

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

        # Now, we get the topics 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), 3)

        self.assertEqual(bugs[0]['data']['id'], 1273442)
        self.assertEqual(len(bugs[0]['data']['comments']), 7)
        self.assertEqual(len(bugs[0]['data']['history']), 6)
        self.assertEqual(len(bugs[0]['data']['attachments']), 1)
        self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[0]['uuid'], '68494ad0072ed9e09cecb8235649a38c443326db')
        self.assertEqual(bugs[0]['updated_on'], 1465257689.0)
        self.assertEqual(bugs[0]['category'], 'bug')
        self.assertEqual(bugs[0]['tag'], BUGZILLA_SERVER_URL)

        self.assertEqual(bugs[1]['data']['id'], 1273439)
        self.assertEqual(len(bugs[1]['data']['comments']), 0)
        self.assertEqual(len(bugs[1]['data']['history']), 0)
        self.assertEqual(len(bugs[1]['data']['attachments']), 0)
        self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[1]['uuid'], 'd306162de06bc759f9bd9227fe3fd5f08aeb0dde')
        self.assertEqual(bugs[1]['updated_on'], 1465257715.0)
        self.assertEqual(bugs[1]['category'], 'bug')
        self.assertEqual(bugs[1]['tag'], BUGZILLA_SERVER_URL)

        self.assertEqual(bugs[2]['data']['id'], 947945)
        self.assertEqual(len(bugs[2]['data']['comments']), 0)
        self.assertEqual(len(bugs[2]['data']['history']), 0)
        self.assertEqual(len(bugs[2]['data']['attachments']), 0)
        self.assertEqual(bugs[2]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[2]['uuid'], '33edda925351c3310fc3e12d7f18a365c365f6bd')
        self.assertEqual(bugs[2]['updated_on'], 1465257743.0)
        self.assertEqual(bugs[2]['category'], 'bug')
        self.assertEqual(bugs[2]['tag'], BUGZILLA_SERVER_URL)

        # No more requests were sent
        self.assertEqual(len(http_requests), 9)
Exemplo n.º 8
0
    def test_fetch_empty(self):
        """Test whether it works when no bugs are fetched"""

        body = read_file('data/bugzilla_rest_bugs_empty.json')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGS_URL,
                               body=body,
                               status=200)

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

        self.assertEqual(len(bugs), 0)
Exemplo n.º 9
0
    def test_initialization(self):
        """Test whether attributes are initializated"""

        bg = BugzillaREST(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, BugzillaRESTClient)

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

        bg = BugzillaREST(BUGZILLA_SERVER_URL, origin='')
        self.assertEqual(bg.url, BUGZILLA_SERVER_URL)
        self.assertEqual(bg.origin, BUGZILLA_SERVER_URL)
Exemplo n.º 10
0
    def test_fetch(self):
        """Test whether a list of bugs is returned"""

        http_requests = setup_http_server()

        bg = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2)
        bugs = [bug for bug in bg.fetch()]

        self.assertEqual(len(bugs), 3)

        self.assertEqual(bugs[0]['data']['id'], 1273442)
        self.assertEqual(len(bugs[0]['data']['comments']), 7)
        self.assertEqual(len(bugs[0]['data']['history']), 6)
        self.assertEqual(len(bugs[0]['data']['attachments']), 1)
        self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[0]['uuid'],
                         '68494ad0072ed9e09cecb8235649a38c443326db')
        self.assertEqual(bugs[0]['updated_on'], 1465257689.0)
        self.assertEqual(bugs[0]['category'], 'bug')
        self.assertEqual(bugs[0]['tag'], BUGZILLA_SERVER_URL)

        self.assertEqual(bugs[1]['data']['id'], 1273439)
        self.assertEqual(len(bugs[1]['data']['comments']), 0)
        self.assertEqual(len(bugs[1]['data']['history']), 0)
        self.assertEqual(len(bugs[1]['data']['attachments']), 0)
        self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[1]['uuid'],
                         'd306162de06bc759f9bd9227fe3fd5f08aeb0dde')
        self.assertEqual(bugs[1]['updated_on'], 1465257715.0)
        self.assertEqual(bugs[1]['category'], 'bug')
        self.assertEqual(bugs[1]['tag'], BUGZILLA_SERVER_URL)

        self.assertEqual(bugs[2]['data']['id'], 947945)
        self.assertEqual(len(bugs[2]['data']['comments']), 0)
        self.assertEqual(len(bugs[2]['data']['history']), 0)
        self.assertEqual(len(bugs[2]['data']['attachments']), 0)
        self.assertEqual(bugs[2]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[2]['uuid'],
                         '33edda925351c3310fc3e12d7f18a365c365f6bd')
        self.assertEqual(bugs[2]['updated_on'], 1465257743.0)
        self.assertEqual(bugs[2]['category'], 'bug')
        self.assertEqual(bugs[2]['tag'], BUGZILLA_SERVER_URL)

        # Check requests
        expected = [{
            'last_change_time': ['1970-01-01T00:00:00Z'],
            'limit': ['2'],
            'order': ['changeddate'],
            'include_fields': ['_all']
        }, {
            'ids': ['1273442', '1273439']
        }, {
            'ids': ['1273442', '1273439']
        }, {
            'ids': ['1273442', '1273439'],
            'exclude_fields': ['data']
        }, {
            'last_change_time': ['1970-01-01T00:00:00Z'],
            'offset': ['2'],
            'limit': ['2'],
            'order': ['changeddate'],
            'include_fields': ['_all']
        }, {
            'ids': ['947945']
        }, {
            'ids': ['947945']
        }, {
            'ids': ['947945'],
            'exclude_fields': ['data']
        }, {
            'last_change_time': ['1970-01-01T00:00:00Z'],
            'offset': ['4'],
            'limit': ['2'],
            'order': ['changeddate'],
            'include_fields': ['_all']
        }]

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

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

        http_requests = setup_http_server()

        bg = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2)
        bugs = [bug for bug in bg.fetch()]

        self.assertEqual(len(bugs), 3)

        self.assertEqual(bugs[0]['data']['id'], 1273442)
        self.assertEqual(len(bugs[0]['data']['comments']), 7)
        self.assertEqual(len(bugs[0]['data']['history']), 6)
        self.assertEqual(len(bugs[0]['data']['attachments']), 1)
        self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[0]['uuid'], '68494ad0072ed9e09cecb8235649a38c443326db')
        self.assertEqual(bugs[0]['updated_on'], 1465257689.0)

        self.assertEqual(bugs[1]['data']['id'], 1273439)
        self.assertEqual(len(bugs[1]['data']['comments']), 0)
        self.assertEqual(len(bugs[1]['data']['history']), 0)
        self.assertEqual(len(bugs[1]['data']['attachments']), 0)
        self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[1]['uuid'], 'd306162de06bc759f9bd9227fe3fd5f08aeb0dde')
        self.assertEqual(bugs[1]['updated_on'], 1465257715.0)

        self.assertEqual(bugs[2]['data']['id'], 947945)
        self.assertEqual(len(bugs[2]['data']['comments']), 0)
        self.assertEqual(len(bugs[2]['data']['history']), 0)
        self.assertEqual(len(bugs[2]['data']['attachments']), 0)
        self.assertEqual(bugs[2]['origin'], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[2]['uuid'], '33edda925351c3310fc3e12d7f18a365c365f6bd')
        self.assertEqual(bugs[2]['updated_on'], 1465257743.0)

        # Check requests
        expected = [{
                     'last_change_time' : ['1970-01-01T00:00:00Z'],
                     'limit' : ['2'],
                     'order' : ['changeddate'],
                     'include_fields' : ['_all']
                    },
                    {
                     'ids' : ['1273442', '1273439']
                    },
                    {
                     'ids' : ['1273442', '1273439']
                    },
                    {
                     'ids' : ['1273442', '1273439'],
                     'exclude_fields' : ['data']
                    },
                    {
                     'last_change_time' : ['1970-01-01T00:00:00Z'],
                     'offset' : ['2'],
                     'limit' : ['2'],
                     'order' : ['changeddate'],
                     'include_fields' : ['_all']
                    },
                    {
                     'ids' : ['947945']
                    },
                    {
                     'ids' : ['947945']
                    },
                    {
                     'ids' : ['947945'],
                     'exclude_fields' : ['data']
                    },
                    {
                     'last_change_time' : ['1970-01-01T00:00:00Z'],
                     'offset' : ['4'],
                     'limit' : ['2'],
                     'order' : ['changeddate'],
                     'include_fields' : ['_all']
                    }]

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

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

        http_requests = setup_http_server()

        bg = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2)
        bugs = [bug for bug in bg.fetch()]

        self.assertEqual(len(bugs), 3)

        self.assertEqual(bugs[0]["data"]["id"], 1273442)
        self.assertEqual(len(bugs[0]["data"]["comments"]), 7)
        self.assertEqual(len(bugs[0]["data"]["history"]), 6)
        self.assertEqual(len(bugs[0]["data"]["attachments"]), 1)
        self.assertEqual(bugs[0]["origin"], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[0]["uuid"], "68494ad0072ed9e09cecb8235649a38c443326db")
        self.assertEqual(bugs[0]["updated_on"], 1465257689.0)
        self.assertEqual(bugs[0]["category"], "bug")

        self.assertEqual(bugs[1]["data"]["id"], 1273439)
        self.assertEqual(len(bugs[1]["data"]["comments"]), 0)
        self.assertEqual(len(bugs[1]["data"]["history"]), 0)
        self.assertEqual(len(bugs[1]["data"]["attachments"]), 0)
        self.assertEqual(bugs[1]["origin"], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[1]["uuid"], "d306162de06bc759f9bd9227fe3fd5f08aeb0dde")
        self.assertEqual(bugs[1]["updated_on"], 1465257715.0)
        self.assertEqual(bugs[1]["category"], "bug")

        self.assertEqual(bugs[2]["data"]["id"], 947945)
        self.assertEqual(len(bugs[2]["data"]["comments"]), 0)
        self.assertEqual(len(bugs[2]["data"]["history"]), 0)
        self.assertEqual(len(bugs[2]["data"]["attachments"]), 0)
        self.assertEqual(bugs[2]["origin"], BUGZILLA_SERVER_URL)
        self.assertEqual(bugs[2]["uuid"], "33edda925351c3310fc3e12d7f18a365c365f6bd")
        self.assertEqual(bugs[2]["updated_on"], 1465257743.0)
        self.assertEqual(bugs[2]["category"], "bug")

        # Check requests
        expected = [
            {
                "last_change_time": ["1970-01-01T00:00:00Z"],
                "limit": ["2"],
                "order": ["changeddate"],
                "include_fields": ["_all"],
            },
            {"ids": ["1273442", "1273439"]},
            {"ids": ["1273442", "1273439"]},
            {"ids": ["1273442", "1273439"], "exclude_fields": ["data"]},
            {
                "last_change_time": ["1970-01-01T00:00:00Z"],
                "offset": ["2"],
                "limit": ["2"],
                "order": ["changeddate"],
                "include_fields": ["_all"],
            },
            {"ids": ["947945"]},
            {"ids": ["947945"]},
            {"ids": ["947945"], "exclude_fields": ["data"]},
            {
                "last_change_time": ["1970-01-01T00:00:00Z"],
                "offset": ["4"],
                "limit": ["2"],
                "order": ["changeddate"],
                "include_fields": ["_all"],
            },
        ]

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

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

        self.assertEqual(BugzillaREST.has_resuming(), True)