Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_does_not_insert_secret_with_unknown_method_call(self):
# create client with secret
secret = "hello"
client = Client(secret=secret)
responses.add_callback(responses.POST, client.server, callback=self.call_params_callback)
# create params
params = ["param1", "param2"]
# call function and assert result
resp = client.call("other.method", params, insert_secret=True)
assert secret not in resp
def test_multicall2(self):
client = Client()
responses.add_callback(responses.POST, client.server, callback=self.call_params_callback)
# create params
params_1 = ["2089b05ecca3d829"]
params_2 = ["2fa07b6e85c40205"]
calls = [(client.REMOVE, params_1), (client.REMOVE, params_2)]
# copy params and insert secret
expected_params = [
[
{"methodName": client.REMOVE, "params": deepcopy(params_1)},
{"methodName": client.REMOVE, "params": deepcopy(params_2)},
]
]
# call function and assert result
resp = client.multicall2(calls)
assert resp == expected_params
def test_insert_secret_with_batch_call(self):
# create client with secret
secret = "hello"
client = Client(secret=secret)
responses.add_callback(responses.POST, client.server, callback=self.batch_call_params_callback)
# create params
params_1 = ["param1", "param2"]
params_2 = ["param3", "param4"]
# copy params and insert secret
expected_params = [deepcopy(params_1), deepcopy(params_2)]
for p in expected_params:
p.insert(0, f"token:{secret}")
# call function and assert result
resp = client.batch_call(
[(client.ADD_URI, params_1, 0), (client.ADD_METALINK, params_2, 1)], insert_secret=True
)
assert resp == expected_params
def test_insert_secret_with_multicall2(self):
# create client with secret
secret = "hello"
client = Client(secret=secret)
responses.add_callback(responses.POST, client.server, callback=self.call_params_callback)
# create params
params_1 = ["2089b05ecca3d829"]
params_2 = ["2fa07b6e85c40205"]
calls = [(client.REMOVE, params_1), (client.REMOVE, params_2)]
# copy params and insert secret
expected_params = [
[
{"methodName": client.REMOVE, "params": deepcopy(params_1)},
{"methodName": client.REMOVE, "params": deepcopy(params_2)},
]
]
for param in expected_params[0]:
param["params"].insert(0, f"token:{secret}")
# call function and assert result
def test_retries_request_when_creation_failed(self):
mock_responses.add(mock_responses.GET,
'https://api.sendgrid.com/v3/user/webhooks/parse/settings/my-domain',
status=404)
mock_responses.add_callback(mock_responses.POST,
'https://api.sendgrid.com/v3/user/webhooks/parse/settings',
callback=MockResponses([(500, '', ''), (200, '', '')]))
action = SetupSendgridMailbox('my-key', max_retries=3, retry_interval_seconds=0.001)
action('my-client-id', 'my-domain')
self.assertEqual(len(mock_responses.calls), 4)
def test_batch_call(self):
client = Client()
responses.add_callback(responses.POST, client.server, callback=self.batch_call_params_callback)
# create params
params_1 = ["param1", "param2"]
params_2 = ["param3", "param4"]
# copy params and insert secret
expected_params = [params_1, params_2]
# call function and assert result
resp = client.batch_call([(client.ADD_URI, params_1, 0), (client.ADD_METALINK, params_2, 1)])
assert resp == expected_params
def test_insert_secret_with_system_multicall(self):
# create client with secret
secret = "hello"
client = Client(secret=secret)
responses.add_callback(responses.POST, client.server, callback=self.call_params_callback)
# create params
params = [
[
{"methodName": client.ADD_URI, "params": ["param1", "param2"]},
{"methodName": client.ADD_URI, "params": ["param3", "param4"]},
]
]
# copy params and insert secret
expected_params = deepcopy(params)
for param in expected_params[0]:
param["params"].insert(0, f"token:{secret}")
# call function and assert result
resp = client.call(client.MULTICALL, params, insert_secret=True)
assert resp == expected_params
def test_with_correct_password(self):
mock_responses.add_callback(
mock_responses.POST,
github.GRAPHQL_URL,
callback=MockResponses([
'''{
"data": {
"viewer": {
"login": "user",
"organization": {
"teams": {
"edges": [
{"cursor": "cursor1"},
{"cursor": "cursor2"}
],
"nodes": [
{"slug": "team1"},
{"slug": "team2"}
def test_insert_secret_with_aria2_method_call(self):
# create client with secret
secret = "hello"
client = Client(secret=secret)
responses.add_callback(responses.POST, client.server, callback=self.call_params_callback)
# create params
params = ["param1", "param2"]
# copy params and insert secret
expected_params = deepcopy(params)
expected_params.insert(0, f"token:{secret}")
# call function and assert result
resp = client.call(client.ADD_URI, params, insert_secret=True)
assert resp == expected_params