Esempio n. 1
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. 2
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. 3
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. 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_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)