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_throws_on_errors(self):
mock_responses.add(mock_responses.DELETE,
'https://api.sendgrid.com/v3/user/webhooks/parse/settings/my-domain',
status=500)
action = DeleteSendgridMailbox('my-key')
with self.assertRaises(Exception):
action('my-client-id', 'my-domain')
self.assertEqual(len(mock_responses.calls), 1)
def test_parse_nullable_type(self):
mock.add(
mock.POST, self.url, status=200,
body=(
'a\n' +
'String\n' +
'\\N\n' +
'\\\\N\n' +
'\n'
)
)
table = Table(
't1', self.metadata(),
Column('a', types.String)
)
rv = self.session.query(*table.c).all()
def test_handles_missing_mailbox(self):
mock_responses.add(mock_responses.DELETE,
'https://api.sendgrid.com/v3/user/webhooks/parse/settings/my-domain',
status=404)
action = DeleteSendgridMailbox('my-key')
action('my-client-id', 'my-domain')
self.assertEqual(len(mock_responses.calls), 1)
def test_makes_request_when_key_is_set(self):
mock_responses.add(mock_responses.GET,
'https://api.sendgrid.com/v3/user/webhooks/parse/settings/my-domain',
status=404)
mock_responses.add(mock_responses.POST, 'https://api.sendgrid.com/v3/user/webhooks/parse/settings', status=200)
action = SetupSendgridMailbox('my-key', max_retries=1, retry_interval_seconds=1)
action('my-client-id', 'my-domain')
self.assertEqual(len(mock_responses.calls), 2)
self.assertIn(b'"hostname": "my-domain"', mock_responses.calls[1].request.body)
def test_call_raises_known_error(self):
client = Client()
responses.add(
responses.POST,
client.server,
json={"error": {"code": JSONRPC_PARSER_ERROR, "message": "Custom message"}},
status=200,
)
with pytest.raises(ClientException, match=rf"{JSONRPC_CODES[JSONRPC_PARSER_ERROR]}\nCustom message") as e:
client.call("aria2.method")
assert e.code == JSONRPC_PARSER_ERROR
def test_fails_request_when_retry_limit_is_exceeded(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, '', '') for _ in range(5)]))
action = SetupSendgridMailbox('my-key', max_retries=3, retry_interval_seconds=0.001)
with self.assertRaises(Exception):
action('my-client-id', 'my-domain')
def test_with_missing_team(self):
mock_responses.add(
mock_responses.POST,
github.GRAPHQL_URL,
body='''{
"data": {
"viewer": {
"login": "user",
"organization": {
"teams": {
"edges": [
{"cursor": "cursor1"}
],
"nodes": [
{"slug": "team1"}
]
}
}
def test_call_raises_custom_error(self):
client = Client()
responses.add(
responses.POST, client.server, json={"error": {"code": 1, "message": "Custom message"}}, status=200
)
with pytest.raises(ClientException, match=r"Custom message") as e:
client.call("aria2.method")
assert e.code == 1
def test_parse_float_types(self):
types_ = ['Float32', 'Float64']
columns = ['a', 'b']
mock.add(
mock.POST, self.url, status=200,
body=(
'\t'.join(columns) + '\n' +
'\t'.join(types_) + '\n' +
'\t'.join(['42'] * len(types_)) + '\n'
)
)
table = Table(
't1', self.metadata(),
*[Column(col, types.Float) for col in columns]
)
rv = self.session.query(*table.c).first()
self.assertEqual(rv, tuple([42.0] * len(columns)))
def test_with_bad_password(self):
mock_responses.add(
mock_responses.POST,
github.GRAPHQL_URL,
json={'message': 'Bad credentials'},
status=401,
)
user = self._auth(access_token='incorrect')
self.assertIsNone(user)