Beispiel #1
0
    def test_bug_activity(self):
        """Test bug acitivity API call"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla/bugzilla_version.xml')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_METADATA_URL,
                               body=body, status=200)

        body = read_file('data/bugzilla/bugzilla_bug_activity.html')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_ACTIVITY_URL,
                               body=body, status=200)

        # Call API
        client = BugzillaClient(BUGZILLA_SERVER_URL)
        response = client.bug_activity('8')

        self.assertEqual(response, body)

        # Check request params
        expected = {'id': ['8']}

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/show_activity.cgi')
        self.assertDictEqual(req.querystring, expected)
Beispiel #2
0
    def test_buglist_old_version(self):
        """Test buglist API call when the version of the server is less than 3.3"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla/bugzilla_version.xml')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_METADATA_URL,
                               body=body, status=200)

        body = read_file('data/bugzilla/bugzilla_buglist.csv')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               body=body, status=200)

        # Call API without args
        client = BugzillaClient(BUGZILLA_SERVER_URL)
        client.version = '3.2.3'
        response = client.buglist()

        self.assertEqual(response, body)

        # Check request params
        expected = {
            'ctype': ['csv'],
            'limit': ['10000'],
            'order': ['Last Changed'],
            'chfieldfrom': ['1970-01-01 00:00:00']
        }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/buglist.cgi')
        self.assertDictEqual(req.querystring, expected)
Beispiel #3
0
    def test_bugs(self):
        """Test bugs API call"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla/bugzilla_bug.xml')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUG_URL,
                               body=body, status=200)

        # Call API
        client = BugzillaClient(BUGZILLA_SERVER_URL)
        response = client.bugs('8', '9')

        self.assertEqual(response, body)

        # Check request params
        expected = {
            'id': ['8', '9'],
            'ctype': ['xml'],
            'excludefield': ['attachmentdata']
        }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/show_bug.cgi')
        self.assertDictEqual(req.querystring, expected)
Beispiel #4
0
    def test_not_found_version(self):
        """Test if it fails when the server version is not found"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla/bugzilla_no_version.xml')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_METADATA_URL,
                               body=body, status=200)

        with self.assertRaises(BackendError):
            client = BugzillaClient(BUGZILLA_SERVER_URL)
            client.buglist()
    def test_init(self):
        """Test initialization"""

        client = BugzillaClient(BUGZILLA_SERVER_URL)
        self.assertEqual(client.version, None)
        self.assertTrue(client.ssl_verify)
        self.assertIsInstance(client.session, requests.Session)

        client = BugzillaClient(BUGZILLA_SERVER_URL, ssl_verify=False)
        self.assertEqual(client.version, None)
        self.assertFalse(client.ssl_verify)
        self.assertIsInstance(client.session, requests.Session)
    def test_logout(self):
        """Test whether the logout is properly completed"""

        # Set up a mock HTTP server
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_LOGIN_URL,
                               body="index.cgi?logout=1",
                               status=200)

        client = BugzillaClient(BUGZILLA_SERVER_URL)
        client.logout()

        req = httpretty.last_request()
        self.assertEqual(req.close_connection, True)
    def test_init_auth(self):
        """Test initialization with authentication"""

        # Set up a mock HTTP server
        httpretty.register_uri(httpretty.POST,
                               BUGZILLA_LOGIN_URL,
                               body="index.cgi?logout=1",
                               status=200)

        _ = BugzillaClient(BUGZILLA_SERVER_URL,
                           user='******',
                           password='******')

        # Check request params
        expected = {
            'Bugzilla_login': ['*****@*****.**'],
            'Bugzilla_password': ['1234'],
            'GoAheadAndLogIn': ['Log in']
        }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'POST')
        self.assertRegex(req.path, '/index.cgi')
        self.assertEqual(req.parsed_body, expected)
    def test_invalid_auth(self):
        """Test whether it fails when the authentication goes wrong"""

        # Set up a mock HTTP server
        httpretty.register_uri(httpretty.POST,
                               BUGZILLA_LOGIN_URL,
                               body="",
                               status=200)

        with self.assertRaises(BackendError):
            _ = BugzillaClient(BUGZILLA_SERVER_URL,
                               user='******',
                               password='******')
Beispiel #9
0
    def test_metadata(self):
        """Test metadata API call"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla/bugzilla_version.xml')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_METADATA_URL,
                               body=body, status=200)

        # Call API
        client = BugzillaClient(BUGZILLA_SERVER_URL)
        response = client.metadata()

        self.assertEqual(response, body)

        # Check request params
        expected = {'ctype': ['xml']}

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/show_bug.cgi')
        self.assertDictEqual(req.querystring, expected)
Beispiel #10
0
    def test_sanitize_for_archive(self):
        """Test whether the sanitize method works properly"""

        url = "http://example.com"
        headers = "headers-information"
        payload = {'GoAheadAndLogIn': '******',
                   'Bugzilla_password': '******',
                   'Bugzilla_login': '******'}

        s_url, s_headers, s_payload = BugzillaClient.sanitize_for_archive(url, headers, copy.deepcopy(payload))
        payload.pop('GoAheadAndLogIn')
        payload.pop('Bugzilla_password')
        payload.pop('Bugzilla_login')

        self.assertEqual(url, s_url)
        self.assertEqual(headers, s_headers)
        self.assertEqual(payload, s_payload)
    def test_buglist(self):
        """Test buglist API call"""

        # Set up a mock HTTP server
        body = read_file('data/bugzilla/bugzilla_version.xml')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_METADATA_URL,
                               body=body,
                               status=200)

        body = read_file('data/bugzilla/bugzilla_buglist.csv')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_BUGLIST_URL,
                               body=body,
                               status=200)

        # Call API without args
        client = BugzillaClient(BUGZILLA_SERVER_URL)
        response = client.buglist()

        self.assertEqual(client.version, '4.2.1+')
        self.assertEqual(response, body)

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

        req = httpretty.last_request()

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

        # Call API with from_date
        response = client.buglist(from_date=datetime.datetime(2015, 1, 1))

        self.assertEqual(response, body)

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

        req = httpretty.last_request()

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

        # Call API having defined max_bugs_cvs parameter
        client = BugzillaClient(BUGZILLA_SERVER_URL, max_bugs_csv=300)
        response = client.buglist()

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

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/buglist.cgi')
        self.assertDictEqual(req.querystring, expected)
Beispiel #12
0
    def test_init(self):
        """Test initialization"""

        client = BugzillaClient(BUGZILLA_SERVER_URL)
        self.assertEqual(client.version, None)
        self.assertIsInstance(client._session, requests.Session)