Esempio n. 1
0
 def test_run_http_exc_raise_http_error(self, mock_get):
     url = 'http://gerrit.example.com'
     try:
         cmd.run_http_exc(FakeException, url)
         self.fails('Exception expected')
     except FakeException as err:
         self.assertEqual(cmd.http_code_2_return_code(404), err.code)
         mock_get.assert_called_once_with(url)
Esempio n. 2
0
 def test_run_http_exc_raise_http_error(self, mock_get):
     url = 'http://gerrit.example.com'
     try:
         cmd.run_http_exc(FakeException, url)
         self.fails('Exception expected')
     except FakeException as err:
         self.assertEqual(cmd.http_code_2_return_code(404), err.code)
         mock_get.assert_called_once_with(url)
Esempio n. 3
0
    def test_run_http_exc_with_failing_git_creds(self, mock_get, mock_run):
        url = 'http://[email protected]'

        try:
            cmd.run_http_exc(FakeException, url)
            self.fails('Exception expected')
        except FakeException as err:
            self.assertEqual(cmd.http_code_2_return_code(401), err.code)
        mock_run.assert_called_once_with('git', 'credential', 'fill',
                                         stdin='url=%s' % url)
        mock_get.assert_called_once_with(url)
Esempio n. 4
0
    def test_run_http_exc_with_failing_auth(self, mock_get, mock_run):
        url = 'http://[email protected]'

        try:
            cmd.run_http_exc(FakeException, url)
            self.fails('Exception expected')
        except FakeException as err:
            self.assertEqual(cmd.http_code_2_return_code(401), err.code)
        mock_run.assert_called_once_with(mock.ANY, 'git', 'credential', 'fill',
                                         stdin='url=%s' % url)
        calls = [mock.call(url), mock.call(url, auth=('user', 'pass'))]
        mock_get.assert_has_calls(calls)
Esempio n. 5
0
    def test_run_http_exc_with_failing_git_creds(self, mock_get, mock_run):
        url = 'http://[email protected]'

        try:
            cmd.run_http_exc(FakeException, url)
            self.fails('Exception expected')
        except FakeException as err:
            self.assertEqual(cmd.http_code_2_return_code(401), err.code)
        mock_run.assert_called_once_with('git',
                                         'credential',
                                         'fill',
                                         stdin='url=%s' % url)
        mock_get.assert_called_once_with(url)
Esempio n. 6
0
    def test_run_http_exc_with_failing_git_creds(self, mock_get, mock_run):
        url = 'http://[email protected]'

        try:
            cmd.run_http_exc(FakeException, url)
            self.fails('Exception expected')
        except FakeException as err:
            self.assertEqual(cmd.http_code_2_return_code(401), err.code)
        # This gets encoded to utf8 which means the type passed down
        # is bytes.
        mock_run.assert_called_once_with('git', 'credential', 'fill',
                                         stdin=b'url=%s' % url.encode('utf-8'))
        mock_get.assert_called_once_with(url)
Esempio n. 7
0
    def test_run_http_exc_with_failing_git_creds(self, mock_get, mock_run):
        url = 'http://[email protected]'

        try:
            cmd.run_http_exc(FakeException, url)
            self.fails('Exception expected')
        except FakeException as err:
            self.assertEqual(cmd.http_code_2_return_code(401), err.code)
        # This gets encoded to utf8 which means the type passed down
        # is bytes.
        mock_run.assert_called_once_with('git', 'credential', 'fill',
                                         stdin=b'url=%s' % url.encode('utf-8'))
        mock_get.assert_called_once_with(url)
Esempio n. 8
0
    def test_run_http_exc_with_failing_auth(self, mock_get, mock_run):
        url = 'http://[email protected]'

        try:
            cmd.run_http_exc(FakeException, url)
            self.fails('Exception expected')
        except FakeException as err:
            self.assertEqual(cmd.http_code_2_return_code(401), err.code)
        mock_run.assert_called_once_with(mock.ANY,
                                         'git',
                                         'credential',
                                         'fill',
                                         stdin='url=%s' % url)
        calls = [mock.call(url), mock.call(url, auth=('user', 'pass'))]
        mock_get.assert_has_calls(calls)