Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def gerrit_api(request):
"""Create a Gerrit container for the given version and return an API."""
with GerritContainer(request.param) as gerrit:
port = gerrit.get_exposed_port(8080)
url = "http://localhost:%s" % port
api = GerritRestAPI(url=url, auth=Anonymous())
_initialize(api)
auth = HTTPBasicAuth("admin", "secret")
api = GerritRestAPI(url=url, auth=auth)
yield api
def test_explicit_anonymous_with_netrc(self):
"""Test explicit anonymous access when credentials are in netrc."""
with patch("pygerrit2.rest.auth._get_netrc_auth") as mock_netrc:
mock_netrc.return_value = ("netrcuser", "netrcpass")
auth = Anonymous()
api = GerritRestAPI(url="http://review.example.com", auth=auth)
assert api.auth is None
assert not api.url.endswith("/a/")
def test_explicit_anonymous_without_netrc(self):
"""Test explicit anonymous access when credentials are not in netrc."""
with patch("pygerrit2.rest.auth._get_netrc_auth") as mock_netrc:
mock_netrc.return_value = None
auth = Anonymous()
api = GerritRestAPI(url="http://review.example.com", auth=auth)
assert api.auth is None
assert not api.url.endswith("/a/")