def test_run_http_exc_raise_unknown_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(255, err.code) mock_get.assert_called_once_with(url)
def test_run_http_exc_with_auth(self, mock_get, mock_run): url = 'http://[email protected]' cmd.run_http_exc(FakeException, url) 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)
def test_run_http_exc_with_auth(self, mock_get, mock_run): url = 'http://[email protected]' cmd.run_http_exc(FakeException, url) # 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')) calls = [mock.call(url), mock.call(url, auth=('user', 'pass'))] mock_get.assert_has_calls(calls)
def test_run_http_exc_with_auth(self, mock_get, mock_run): url = 'http://[email protected]' cmd.run_http_exc(FakeException, url) mock_run.assert_called_once_with('git', 'credential', 'fill', stdin='url=%s' % url) calls = [mock.call(url), mock.call(url, auth=('user', 'pass'))] mock_get.assert_has_calls(calls)
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)
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)
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)
def test_run_http_exc_without_auth(self, mock_get, mock_run): url = 'http://[email protected]' cmd.run_http_exc(FakeException, url) self.assertFalse(mock_run.called) mock_get.assert_called_once_with(url)