Exemple #1
0
 def test_get_revision(self):
     """
     Test that a revision can be fetched
     """
     reference = Gerrit(url=self.URL)
     revision = reference.get_revision('my-revision')
     self.assertIsInstance(revision, Revision)
Exemple #2
0
 def test_get_project(self):
     """
     Test that a project can be fetched
     """
     reference = Gerrit(url=self.URL)
     reference.call = self.call
     reference.get_project(self.PROJECT)
     self.call.assert_called_with(r_endpoint='/a/projects/{}/'.format(
         self.PROJECT), )
Exemple #3
0
 def test_create_change(self):
     """
     Test that a change can be created
     """
     reference = Gerrit(url=self.URL)
     change = reference.create_change(self.PROJECT, 'change status')
     self.assertIsInstance(change, Change)
     self.mock_post.assert_called_with(auth=mock.ANY,
                                       headers=mock.ANY,
                                       json=mock.ANY,
                                       url='{}/a/changes/'.format(self.URL))
    def test_get_project(self, mock_get_netrc_auth):
        mock_get_netrc_auth.return_value = ('user', 'password')
        req = mock.Mock()
        req.status_code = 200
        req.content = ')]}\'{}'.encode('utf-8')
        call = mock.Mock()
        call.return_value = req

        reference = Gerrit(url='http://domain.com')
        reference.call = call
        project = reference.get_project('gerritproject')
        call.assert_called_with(r_endpoint='/a/projects/gerritproject/', )
def main():
    gerrit_log = Gerrit()
    for _ in range(0, 5):
        gerrit_log.create_patchset()
        gerrit_log.update_patchset()
        gerrit_log.added_comment()
        gerrit_log.merge_change()

    artifactory_logs = Artifactory()
    artifactory_logs.create_all_packages()
    def test_get_project(self, mock_get_netrc_auth):
        mock_get_netrc_auth.return_value = ('user', 'password')
        req = mock.Mock()
        req.status_code = 200
        req.content = ')]}\'{}'.encode('utf-8')
        call = mock.Mock()
        call.return_value = req

        reference = Gerrit(url='http://domain.com')
        reference.call = call
        project = reference.get_project('gerritproject')
        call.assert_called_with(
            r_endpoint='/a/projects/gerritproject/',
        )
Exemple #7
0
 def test_create_project(self):
     """
     Test that a project can be created
     """
     self.req.status_code = 201
     reference = Gerrit(url=self.URL)
     reference.call = self.call
     with mock.patch.object(Project, 'get_project'):
         reference.create_project(self.PROJECT)
         self.call.assert_called_with(
             request='put',
             r_endpoint='/a/projects/{}'.format(self.PROJECT),
             r_payload={},
         )
Exemple #8
0
    def test_no_parameters(self):
        """
        Init without any auth parameters
        """
        reference = Gerrit(url=self.URL, )

        self.auth_ok(reference, self.mock_http_basic_auth)
    def test_init_with_invalid_auth_type(self):
        """Init with invalid auth_type 'invalid'"""

        with self.assertRaises(NotImplementedError) as cm:
            reference = Gerrit(url='http://domain.com', auth_type='invalid')
        self.assertEqual("Authorization type 'invalid' is not implemented",
                         str(cm.exception))
Exemple #10
0
 def test_invalid_type(self):
     """
     Init with invalid auth_type 'invalid'
     """
     with self.assertRaises(NotImplementedError) as err:
         Gerrit(url=self.URL, auth_type='invalid')
     self.assertEqual("Authorization type 'invalid' is not implemented",
                      str(err.exception))
    def test_create_project(self, mock_get_netrc_auth):
        mock_get_netrc_auth.return_value = ('user', 'password')
        req = mock.Mock()
        req.status_code = 201
        req.content = ')]}\'{}'.encode('utf-8')
        call = mock.Mock()
        call.return_value = req

        reference = Gerrit(url='http://domain.com')
        reference.call = call
        with mock.patch.object(Project, 'get_project'):
            project = reference.create_project('gerritproject')
            call.assert_called_with(
                request='put',
                r_endpoint='/a/projects/gerritproject',
                r_payload={},
            )
    def test_create_project(self, mock_get_netrc_auth):
        mock_get_netrc_auth.return_value = ('user', 'password')
        req = mock.Mock()
        req.status_code = 201
        req.content = ')]}\'{}'.encode('utf-8')
        call = mock.Mock()
        call.return_value = req

        reference = Gerrit(url='http://domain.com')
        reference.call = call
        with mock.patch.object(Project, 'get_project'):
            project = reference.create_project('gerritproject')
            call.assert_called_with(
                request='put',
                r_endpoint='/a/projects/gerritproject',
                r_payload={},
            )
    def test_init_partialAuth_pw_given(self, mock_get_netrc_auth):
        # Instantiate gerrit Con
        with self.assertRaises(CredentialsNotFound):
            reference = Gerrit(url='http://domain.com', auth_pw='pass_given')

        # Make sure get_netrc_auth is not called since we have given the credentials.
        self.assertFalse(
            mock_get_netrc_auth.called,
            'Failed to not call get_netrc_auth if credentials were given.')
    def test_init_with_auth_type_http(self, mock_get_netrc_auth,
                                      mock_http_basic_auth):
        """Init with auth_type parameter set to 'http'"""
        mock_get_netrc_auth.return_value = ('user_found', 'password_found')
        auth = mock.Mock()
        auth.username, auth.password = mock_get_netrc_auth()

        reference = Gerrit(url='http://domain.com', auth_type='http')

        mock_http_basic_auth.assert_called_with(auth.username, auth.password)
Exemple #15
0
    def test_type_http(self):
        """
        Init with auth_type parameter set to 'http'
        """
        reference = Gerrit(
            url=self.URL,
            auth_type='http',
        )

        self.auth_ok(reference, self.mock_http_basic_auth)
Exemple #16
0
    def test_type_http_method_digest(self):
        """
        Init with auth_type parameter set to 'http' and auth_method set to 'digest'
        """
        reference = Gerrit(
            url=self.URL,
            auth_type='http',
            auth_method='digest',
        )

        self.auth_ok(reference, self.mock_http_digest_auth)
    def test_create_change(self, mock_get, mock_post, mock_get_netrc_auth):
        mock_get_netrc_auth.return_value = ('user', 'password')
        post = mock.Mock()
        post.status_code = 201
        post.content = ')]}\'{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'.encode(
            'utf-8')
        mock_post.return_value = post

        get = mock.Mock()
        get.status_code = 200
        get.content = ')]}\'{}'.encode('utf-8')
        mock_get.return_value = get

        reference = Gerrit(url='http://domain.com')
        change = reference.create_change('gerritproject', 'change status')
        self.assertIsInstance(change, Change)
        mock_post.assert_called_with(auth=mock.ANY,
                                     headers=mock.ANY,
                                     json=mock.ANY,
                                     url='http://domain.com/a/changes/')
    def test_init_with_invalid_auth_method(self, mock_get_netrc_auth):
        """Init with invalid auth_method 'invalid'"""
        mock_get_netrc_auth.return_value = ('user_found', 'password_found')
        auth = mock.Mock()
        auth.username, auth.password = mock_get_netrc_auth()

        with self.assertRaises(NotImplementedError) as cm:
            reference = Gerrit(url='http://domain.com', auth_method='invalid')
        self.assertEqual(
            "Authorization method 'invalid' for auth_type 'http' is not implemented",
            str(cm.exception))
    def test_get_change(self, mock_get, mock_get_netrc_auth):
        mock_get_netrc_auth.return_value = ('user', 'password')
        get = mock.Mock()
        get.status_code = 200
        get.content = (
            ')]}\''
            '{"name": "gerritproject", '
            '"parent": "All-Projects", '
            '"description": "My gerrit project", '
            '"state": "ACTIVE"}').encode('utf-8')
        mock_get.return_value = get

        reference = Gerrit(url='http://domain.com')
        change = reference.get_change('gerritproject', 'change id')
        self.assertIsInstance(change, Change)
        mock_get.assert_called_with(
            auth=mock.ANY,
            headers=mock.ANY,
            json=mock.ANY,
            url='http://domain.com/a/changes/gerritproject%7Emaster%7Echange%20id/'
        )
    def test_get_change(self, mock_get, mock_get_netrc_auth):
        mock_get_netrc_auth.return_value = ('user', 'password')
        get = mock.Mock()
        get.status_code = 200
        get.content = (')]}\''
                       '{"name": "gerritproject", '
                       '"parent": "All-Projects", '
                       '"description": "My gerrit project", '
                       '"state": "ACTIVE"}').encode('utf-8')
        mock_get.return_value = get

        reference = Gerrit(url='http://domain.com')
        change = reference.get_change('gerritproject', 'change id')
        self.assertIsInstance(change, Change)
        mock_get.assert_called_with(
            auth=mock.ANY,
            headers=mock.ANY,
            json=mock.ANY,
            url=
            'http://domain.com/a/changes/gerritproject%7Emaster%7Echange%20id/'
        )
    def test_init_credentials_not_found(self, mock_get_netrc_auth):
        # Set up mock
        mock_get_netrc_auth.return_value = False

        # Instantiate gerrit Con
        with self.assertRaises(CredentialsNotFound):
            reference = Gerrit(url='http://domain.com')

        # Make sure get_netrc_auth is not called since we have given the credentials.
        self.assertTrue(
            mock_get_netrc_auth.called,
            'Failed to call get_netrc_auth if credentials were not given.')
    def test_create_change(self, mock_get, mock_post, mock_get_netrc_auth):
        mock_get_netrc_auth.return_value = ('user', 'password')
        post = mock.Mock()
        post.status_code = 201
        post.content = ')]}\'{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'.encode('utf-8')
        mock_post.return_value = post

        get = mock.Mock()
        get.status_code = 200
        get.content = ')]}\'{}'.encode('utf-8')
        mock_get.return_value = get

        reference = Gerrit(url='http://domain.com')
        change = reference.create_change('gerritproject', 'change status')
        self.assertIsInstance(change, Change)
        mock_post.assert_called_with(
            auth=mock.ANY,
            headers=mock.ANY,
            json=mock.ANY,
            url='http://domain.com/a/changes/'
        )
Exemple #23
0
    def test_partial_pw_given(self):
        """
        Test that it raises if only password is specified
        """
        # Instantiate gerrit Con
        with self.assertRaises(CredentialsNotFound):
            Gerrit(
                url=self.URL,
                auth_pw=self.PASSWORD,
            )

        # Make sure get_netrc_auth is not called since we have given the credentials.
        self.mock_get_netrc_auth.assert_not_called()
Exemple #24
0
    def test_partial_id_given(self):
        """
        Test that it raises if only username is specified
        """
        # Instantiate gerrit Con
        with self.assertRaises(CredentialsNotFound):
            Gerrit(
                url=self.URL,
                auth_id=self.USERNAME,
            )

        # Make sure get_netrc_auth is not called since we have given the credentials.
        self.mock_get_netrc_auth.assert_not_called()
Exemple #25
0
    def test_credentials_not_found(self):
        """
        Test that is raises if netrc credentials can not be found
        """
        # Set up mock
        self.mock_get_netrc_auth.return_value = False

        # Instantiate gerrit Con
        with self.assertRaises(CredentialsNotFound):
            Gerrit(url=self.URL, )

        # Make sure get_netrc_auth is not called since we have given the credentials.
        self.mock_get_netrc_auth.assert_called_once_with(self.URL)
Exemple #26
0
    def test_netrc(self):
        """
        Test that netrc is used if no credentials are specified
        """
        # Instantiate gerrit Con
        reference = Gerrit(url=self.URL)

        # Make sure get_netrc_auth is called since we have no specified the credentials
        self.mock_get_netrc_auth.assert_called_with(self.URL)

        # Check that the _auth HTTPBasicAuth object contains the
        # given credentials
        self.auth_ok(reference)
Exemple #27
0
    def test_get_change(self):
        """
        Test that a change can be fetched
        """
        self.get.content = self.build_response({
            "name": self.PROJECT,
            "parent": self.PARENT,
            "description": self.DESCRIPTION,
            "state": self.STATE,
        })

        reference = Gerrit(url=self.URL)
        change = reference.get_change(self.PROJECT, self.CHANGE_ID)
        self.assertIsInstance(change, Change)
        self.mock_get.assert_called_with(
            auth=mock.ANY,
            headers=mock.ANY,
            json=mock.ANY,
            url='{}/a/changes/{}%7E{}%7E{}/'.format(
                self.URL,
                self.PROJECT,
                self.BRANCH,
                self.CHANGE_ID,
            ))
    def test_init_credentials_given(self, mock_get_netrc_auth):
        # Instantiate gerrit Con
        reference = Gerrit(url='http://domain.com',
                           auth_id='user_given',
                           auth_pw='password_given')

        # Make sure get_netrc_auth is not called since we have given the credentials.
        self.assertFalse(
            mock_get_netrc_auth.called,
            'Failed to not call get_netrc_auth if credentials were given.')

        # Check that the _auth HTTPBasicAuth object contains the
        # given credentials

        self.assertEqual('user_given', reference._auth.username)
        self.assertEqual('password_given', reference._auth.password)
    def test_init_with_netrc(self, mock_get_netrc_auth):
        # Set up mock
        mock_get_netrc_auth.return_value = ('user_found', 'password_found')

        # Instantiate gerrit Con
        reference = Gerrit(url='http://domain.com')

        # Make sure get_netrc_auth is called since we have no specified the credentials
        self.assertTrue(
            mock_get_netrc_auth.called,
            'Failed to call get_netrc_auth if credentials were not specified.')

        # Check that the _auth HTTPBasicAuth object contains the
        # given credentials

        self.assertEqual('user_found', reference._auth.username)
        self.assertEqual('password_found', reference._auth.password)
Exemple #30
0
    def test_credentials(self):
        """
        Test that netrc is not used when credentials are specified
        """
        # Instantiate gerrit Con
        reference = Gerrit(
            url=self.URL,
            auth_id=self.USERNAME,
            auth_pw=self.PASSWORD,
        )

        # Make sure get_netrc_auth is not called since we have given the credentials.
        self.mock_get_netrc_auth.assert_not_called()

        # Check that the _auth HTTPBasicAuth object contains the
        # given credentials
        self.auth_ok(reference)
Exemple #31
0
class test_url:
    def setUp(self):
        self.gerrit = Gerrit(httpbin, 'admin', 'password')

    def teardown(self):
        self.gerrit = None

    def test_default_credential(self):
        assert_equal(self.gerrit.username, 'admin')
        assert_equal(self.gerrit.password, 'password')
        assert_equal(self.gerrit.host, httpbin)
        assert_is_instance(self.gerrit.URLS, dict)

    def test_dispatch_get(self):
        success, result = self.gerrit.dispatch(
            Request(method='GET', url=httpbin + 'get'))
        assert_true(success)
        success, result = self.gerrit.dispatch(
            Request(method='GET', url=httpbin + 'get1'))
        assert_false(success)

    def test_dispatch_post(self):
        success, result = self.gerrit.dispatch(
            Request(method='POST', url=httpbin + 'post', data={'foo': 'bar'}))
        assert_true(success)
        success, result = self.gerrit.dispatch(
            Request(method='GET', url=httpbin + 'post', data={'foo': 'bar'}))
        assert_false(success)

    def test_dispatch_put(self):
        success, result = self.gerrit.dispatch(
            Request(method='PUT', url=httpbin + 'put', data={'foo': 'bar'}))
        assert_true(success)

    def test_dispatch_delete(self):
        success, result = self.gerrit.dispatch(
            Request(method='DELETE', url=httpbin + 'delete'))
        assert_true(success)
Exemple #32
0
 def setUp(self):
     self.gerrit = Gerrit(httpbin, 'admin', 'password')
 def test_get_revision(self, mock_get_netrc_auth):
     mock_get_netrc_auth.return_value = ('user', 'password')
     reference = Gerrit(url='http://domain.com')
     revision = reference.get_revision('my-revision')
     self.assertIsInstance(revision, Revision)
Exemple #34
0
 def setUp(self):
     """This method is run once before _each_ test method is executed"""
     self.gerrit_server = Gerrit('gerrit.example.com')
 def test_get_revision(self, mock_get_netrc_auth):
     mock_get_netrc_auth.return_value = ('user', 'password')
     reference = Gerrit(url='http://domain.com')
     revision = reference.get_revision('my-revision')
     self.assertIsInstance(revision, Revision)