Esempio n. 1
0
    def test_history(self):
        """Test history API call"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla_rest_bugs_history.json')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGS_HISTORY_1273442_URL,
                               body=body, status=200)


        # Call API
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        response = client.history('1273442', '1273439')

        self.assertEqual(response, body)

        # Check request params
        expected = {
                    'ids' : ['1273442', '1273439']
                   }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/rest/bug/1273442/history')
        self.assertDictEqual(req.querystring, expected)
Esempio n. 2
0
    def test_attachments(self):
        """Test attachments API call"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla_rest_bugs_attachments.json')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGS_ATTACHMENTS_1273442_URL,
                               body=body, status=200)

        # Call API
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        response = client.attachments('1273442', '1273439')

        self.assertEqual(response, body)

        # Check request params
        expected = {
            'ids' : ['1273442', '1273439'],
            'exclude_fields' : ['data']
        }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/rest/bug/1273442/attachment')
        self.assertDictEqual(req.querystring, expected)
Esempio n. 3
0
    def test_auth_token_call(self):
        """Test whether the API token is included on the calls when it was set"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla_rest_bugs.json')

        # Set up a mock HTTP server
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_LOGIN_URL,
                               body='{"token": "786-OLaWfBisMY", "id": "786"}',
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGS_URL,
                               body=body, status=200)

        # Test API token login
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL,
                                    user='******',
                                    password='******')

        self.assertEqual(client.api_token, '786-OLaWfBisMY')

        # Check whether it is included on the calls
        _ = client.bugs()

        # Check request params
        expected = {
                     'last_change_time' : ['1970-01-01T00:00:00Z'],
                     'limit' : ['500'],
                     'order' : ['changeddate'],
                     'include_fields' : ['_all'],
                     'token' :  ['786-OLaWfBisMY']
                   }

        req = httpretty.last_request()
        self.assertDictEqual(req.querystring, expected)

        # Test API token initialization
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL,
                                    api_token='ABCD')
        _ = client.bugs()

        expected = {
                    'last_change_time' : ['1970-01-01T00:00:00Z'],
                    'limit' : ['500'],
                    'order' : ['changeddate'],
                    'include_fields' : ['_all'],
                    'token' :  ['ABCD']
                   }

        req = httpretty.last_request()
        self.assertDictEqual(req.querystring, expected)
Esempio n. 4
0
    def test_bugs(self):
        """Test bugs API call"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla_rest_bugs.json')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGS_URL,
                               body=body, status=200)


        # Call API
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        response = client.bugs()

        self.assertEqual(response, body)

        # Check request params
        expected = {
                     'last_change_time' : ['1970-01-01T00:00:00Z'],
                     'limit' : ['500'],
                     'order' : ['changeddate'],
                     'include_fields' : ['_all']
                   }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/rest/bug')
        self.assertDictEqual(req.querystring, expected)

        # Call API with parameters
        from_date = datetime.datetime(2016, 6, 7, 0, 0, 0)

        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        response = client.bugs(from_date=from_date, offset=100, max_bugs=5)

        self.assertEqual(response, body)

        expected = {
                    'last_change_time' : ['2016-06-07T00:00:00Z'],
                    'offset' : ['100'],
                    'limit' : ['5'],
                    'order' : ['changeddate'],
                    'include_fields' : ['_all']
                   }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/rest/bug')
        self.assertDictEqual(req.querystring, expected)
Esempio n. 5
0
    def test_bugs(self):
        """Test bugs API call"""

        # Set up a mock HTTP server
        body = read_file("data/bugzilla_rest_bugs.json")
        httpretty.register_uri(httpretty.GET, BUGZILLA_BUGS_URL, body=body, status=200)

        # Call API
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        response = client.bugs()

        self.assertEqual(response, body)

        # Check request params
        expected = {
            "last_change_time": ["1970-01-01T00:00:00Z"],
            "limit": ["500"],
            "order": ["changeddate"],
            "include_fields": ["_all"],
        }

        req = httpretty.last_request()

        self.assertEqual(req.method, "GET")
        self.assertRegex(req.path, "/rest/bug")
        self.assertDictEqual(req.querystring, expected)

        # Call API with parameters
        from_date = datetime.datetime(2016, 6, 7, 0, 0, 0)

        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        response = client.bugs(from_date=from_date, offset=100, max_bugs=5)

        self.assertEqual(response, body)

        expected = {
            "last_change_time": ["2016-06-07T00:00:00Z"],
            "offset": ["100"],
            "limit": ["5"],
            "order": ["changeddate"],
            "include_fields": ["_all"],
        }

        req = httpretty.last_request()

        self.assertEqual(req.method, "GET")
        self.assertRegex(req.path, "/rest/bug")
        self.assertDictEqual(req.querystring, expected)
Esempio n. 6
0
    def test_init_auth(self):
        """Test initialization with authentication"""

        # Set up a mock HTTP server
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_LOGIN_URL,
                               body='{"token": "786-OLaWfBisMY", "id": "786"}',
                               status=200)

        client = BugzillaRESTClient(BUGZILLA_SERVER_URL,
                                    user='******',
                                    password='******')

        self.assertEqual(client.api_token, '786-OLaWfBisMY')

        # Check request params
        expected = {
            'login': ['*****@*****.**'],
            'password': ['1234'],
        }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/rest/login')
        self.assertEqual(req.querystring, expected)
Esempio n. 7
0
    def test_auth_token_call(self):
        """Test whether the API token is included on the calls when it was set"""

        # Set up a mock HTTP server
        body = read_file("data/bugzilla_rest_bugs.json")

        # Set up a mock HTTP server
        httpretty.register_uri(
            httpretty.GET, BUGZILLA_LOGIN_URL, body='{"token": "786-OLaWfBisMY", "id": "786"}', status=200
        )

        httpretty.register_uri(httpretty.GET, BUGZILLA_BUGS_URL, body=body, status=200)

        # Test API token login
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL, user="******", password="******")

        self.assertEqual(client.api_token, "786-OLaWfBisMY")

        # Check whether it is included on the calls
        _ = client.bugs()

        # Check request params
        expected = {
            "last_change_time": ["1970-01-01T00:00:00Z"],
            "limit": ["500"],
            "order": ["changeddate"],
            "include_fields": ["_all"],
            "token": ["786-OLaWfBisMY"],
        }

        req = httpretty.last_request()
        self.assertDictEqual(req.querystring, expected)

        # Test API token initialization
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL, api_token="ABCD")
        _ = client.bugs()

        expected = {
            "last_change_time": ["1970-01-01T00:00:00Z"],
            "limit": ["500"],
            "order": ["changeddate"],
            "include_fields": ["_all"],
            "token": ["ABCD"],
        }

        req = httpretty.last_request()
        self.assertDictEqual(req.querystring, expected)
Esempio n. 8
0
    def test_comments(self):
        """Test comments API call"""

        # Set up a mock HTTP server
        body = read_file("data/bugzilla_rest_bugs_comments.json")
        httpretty.register_uri(httpretty.GET, BUGZILLA_BUGS_COMMENTS_1273442_URL, body=body, status=200)

        # Call API
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        response = client.comments("1273442", "1273439")

        self.assertEqual(response, body)

        # Check request params
        expected = {"ids": ["1273442", "1273439"]}

        req = httpretty.last_request()

        self.assertEqual(req.method, "GET")
        self.assertRegex(req.path, "/rest/bug/1273442/comment")
        self.assertDictEqual(req.querystring, expected)
Esempio n. 9
0
    def test_invalid_auth(self):
        """Test whether it fails when the authentication goes wrong"""

        # Set up a mock HTTP server
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_LOGIN_URL,
                               body="401 Client Error: Authorization Required",
                               status=401)

        with self.assertRaises(BackendError):
            _ = BugzillaRESTClient(BUGZILLA_SERVER_URL,
                                   user='******',
                                   password='******')
Esempio n. 10
0
    def test_attachments(self):
        """Test attachments API call"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla_rest_bugs_attachments.json')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGS_ATTACHMENTS_1273442_URL,
                               body=body,
                               status=200)

        # Call API
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        response = client.attachments('1273442', '1273439')

        self.assertEqual(response, body)

        # Check request params
        expected = {'ids': ['1273442', '1273439'], 'exclude_fields': ['data']}

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/rest/bug/1273442/attachment')
        self.assertDictEqual(req.querystring, expected)
Esempio n. 11
0
    def test_history(self):
        """Test history API call"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla_rest_bugs_history.json')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGS_HISTORY_1273442_URL,
                               body=body,
                               status=200)

        # Call API
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        response = client.history('1273442', '1273439')

        self.assertEqual(response, body)

        # Check request params
        expected = {'ids': ['1273442', '1273439']}

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/rest/bug/1273442/history')
        self.assertDictEqual(req.querystring, expected)
Esempio n. 12
0
    def test_auth_token_call(self):
        """Test whether the API token is included on the calls when it was set"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla_rest_bugs.json')

        # Set up a mock HTTP server
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_LOGIN_URL,
                               body='{"token": "786-OLaWfBisMY", "id": "786"}',
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGS_URL,
                               body=body,
                               status=200)

        # Test API token login
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL,
                                    user='******',
                                    password='******')

        self.assertEqual(client.api_token, '786-OLaWfBisMY')

        # Check whether it is included on the calls
        _ = client.bugs()

        # Check request params
        expected = {
            'last_change_time': ['1970-01-01T00:00:00Z'],
            'limit': ['500'],
            'order': ['changeddate'],
            'include_fields': ['_all'],
            'token': ['786-OLaWfBisMY']
        }

        req = httpretty.last_request()
        self.assertDictEqual(req.querystring, expected)

        # Test API token initialization
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL, api_token='ABCD')
        _ = client.bugs()

        expected = {
            'last_change_time': ['1970-01-01T00:00:00Z'],
            'limit': ['500'],
            'order': ['changeddate'],
            'include_fields': ['_all'],
            'token': ['ABCD']
        }

        req = httpretty.last_request()
        self.assertDictEqual(req.querystring, expected)
Esempio n. 13
0
    def test_bugs(self):
        """Test bugs API call"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla_rest_bugs.json')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGS_URL,
                               body=body,
                               status=200)

        # Call API
        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        response = client.bugs()

        self.assertEqual(response, body)

        # Check request params
        expected = {
            'last_change_time': ['1970-01-01T00:00:00Z'],
            'limit': ['500'],
            'order': ['changeddate'],
            'include_fields': ['_all']
        }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/rest/bug')
        self.assertDictEqual(req.querystring, expected)

        # Call API with parameters
        from_date = datetime.datetime(2016, 6, 7, 0, 0, 0)

        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        response = client.bugs(from_date=from_date, offset=100, max_bugs=5)

        self.assertEqual(response, body)

        expected = {
            'last_change_time': ['2016-06-07T00:00:00Z'],
            'offset': ['100'],
            'limit': ['5'],
            'order': ['changeddate'],
            'include_fields': ['_all']
        }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/rest/bug')
        self.assertDictEqual(req.querystring, expected)
Esempio n. 14
0
    def test_init(self):
        """Test initialization"""

        client = BugzillaRESTClient(BUGZILLA_SERVER_URL)
        self.assertEqual(client.base_url, BUGZILLA_SERVER_URL)
        self.assertEqual(client.api_token, None)