我正在 Django 中编写一个自动化测试,以检查 webhook 是否在应用程序上工作。测试将一堆 JSON 发送到 webhook 并检查调用是否已记录在数据库中。然而,我遇到的问题是测试调用了http://localhost URL,因此数据保存在我的本地开发数据库中,而不是测试创建的临时数据库中。所以我现在没有办法检查电话是否已接到。
什么是正确的解决方案?
from django.test import TestCase
import requests
from monzo.models import Transaction, RequestLog
class WebhookChecks(TestCase):
fixtures = ['db.json', ]
def test_simple_expense(self):
my_json = '{"type": "transaction.created", REMOVED FOR SECURITY }'
url = 'http://localhost/some_url/webhook/'
headers = {'Content-Type': 'application/json'}
r = requests.post(url, data=my_json, headers=headers)
if not "200" in str(r):
print("Something didn't work out. Error: "+str(r))
self.assertTrue("200" in str(r))