Esempio n. 1
0
    def test_bug_activity(self):
        """Test bug acitivity API call"""

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

        body = read_file('data/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)
Esempio n. 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_version.xml')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_METADATA_URL,
                               body=body,
                               status=200)

        body = read_file('data/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'],
            '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)
Esempio n. 3
0
    def test_bugs(self):
        """Test bugs API call"""

        # Set up a mock HTTP server
        body = read_file('data/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)
Esempio n. 4
0
    def test_bug_activity(self):
        """Test bug acitivity API call"""

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

        body = read_file('data/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)
Esempio n. 5
0
    def test_bugs(self):
        """Test bugs API call"""

        # Set up a mock HTTP server
        body = read_file('data/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)
Esempio n. 6
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_version.xml')
        httpretty.register_uri(httpretty.GET,
                               BUGZILLA_METADATA_URL,
                               body=body, status=200)

        body = read_file('data/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'],
                    '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)
Esempio n. 7
0
    def test_buglist(self):
        """Test buglist API call"""

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

        body = read_file('data/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'],
            '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'],
            '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)
Esempio n. 8
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_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()
Esempio n. 9
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_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()
Esempio n. 10
0
    def test_buglist(self):
        """Test buglist API call"""

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

        body = read_file('data/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'],
                    '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'],
                    '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)
Esempio n. 11
0
    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)
Esempio n. 12
0
    def test_init(self):
        """Test initialization"""

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

        client = BugzillaClient(BUGZILLA_SERVER_URL)
        self.assertEqual(client.version, None)
Esempio n. 13
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.POST,
                               BUGZILLA_LOGIN_URL,
                               body="",
                               status=200)

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

        # Set up a mock HTTP server
        body = read_file('data/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)
Esempio n. 15
0
    def test_metadata(self):
        """Test metadata API call"""

        # Set up a mock HTTP server
        body = read_file('data/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)
Esempio n. 16
0
    def test_init(self):
        """Test initialization"""

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