String formatting improvements for tests (2) (#33666)

This commit is contained in:
Franck Nijhof authored and GitHub committed 2020-04-05 00:33:07 +02:00
1 parent 906385172a
commit d7e9959442
19 files changed
+65 -76

No files matched your search

+10 -10
View File
@@ -81,14 +81,14 @@ async def test_mailgun_webhook_with_missing_signature(
event_count = len(mailgun_events)
await http_client.post(
"/api/webhook/{}".format(webhook_id_with_api_key),
f"/api/webhook/{webhook_id_with_api_key}",
json={"hello": "mailgun", "signature": {}},
)
assert len(mailgun_events) == event_count
await http_client.post(
"/api/webhook/{}".format(webhook_id_with_api_key), json={"hello": "mailgun"}
f"/api/webhook/{webhook_id_with_api_key}", json={"hello": "mailgun"}
)
assert len(mailgun_events) == event_count
@@ -104,13 +104,13 @@ async def test_mailgun_webhook_with_different_api_key(
event_count = len(mailgun_events)
await http_client.post(
"/api/webhook/{}".format(webhook_id_with_api_key),
f"/api/webhook/{webhook_id_with_api_key}",
json={
"hello": "mailgun",
"signature": {
"signature": hmac.new(
key=b"random_api_key",
msg=bytes("{}{}".format(timestamp, token), "utf-8"),
msg=bytes(f"{timestamp}{token}", "utf-8"),
digestmod=hashlib.sha256,
).hexdigest(),
"timestamp": timestamp,
@@ -132,13 +132,13 @@ async def test_mailgun_webhook_event_with_correct_api_key(
event_count = len(mailgun_events)
await http_client.post(
"/api/webhook/{}".format(webhook_id_with_api_key),
f"/api/webhook/{webhook_id_with_api_key}",
json={
"hello": "mailgun",
"signature": {
"signature": hmac.new(
key=bytes(API_KEY, "utf-8"),
msg=bytes("{}{}".format(timestamp, token), "utf-8"),
msg=bytes(f"{timestamp}{token}", "utf-8"),
digestmod=hashlib.sha256,
).hexdigest(),
"timestamp": timestamp,
@@ -159,7 +159,7 @@ async def test_mailgun_webhook_with_missing_signature_without_api_key(
event_count = len(mailgun_events)
await http_client.post(
"/api/webhook/{}".format(webhook_id_without_api_key),
f"/api/webhook/{webhook_id_without_api_key}",
json={"hello": "mailgun", "signature": {}},
)
@@ -168,7 +168,7 @@ async def test_mailgun_webhook_with_missing_signature_without_api_key(
assert mailgun_events[-1].data["hello"] == "mailgun"
await http_client.post(
"/api/webhook/{}".format(webhook_id_without_api_key), json={"hello": "mailgun"}
f"/api/webhook/{webhook_id_without_api_key}", json={"hello": "mailgun"}
)
assert len(mailgun_events) == event_count + 1
@@ -186,13 +186,13 @@ async def test_mailgun_webhook_event_without_an_api_key(
event_count = len(mailgun_events)
await http_client.post(
"/api/webhook/{}".format(webhook_id_without_api_key),
f"/api/webhook/{webhook_id_without_api_key}",
json={
"hello": "mailgun",
"signature": {
"signature": hmac.new(
key=bytes(API_KEY, "utf-8"),
msg=bytes("{}{}".format(timestamp, token), "utf-8"),
msg=bytes(f"{timestamp}{token}", "utf-8"),
digestmod=hashlib.sha256,
).hexdigest(),
"timestamp": timestamp,