0
我有一個啓動用戶的登錄請求懲戒在Django視圖測試的輔助功能
它看起來是這樣的一個觀點功能:
def initiate_login(request):
# get request parameters
return check_user_and_send_otp(login_id)
請求然後由另一個函數處理
def check_user_and_send_otp(login_id):
# check if user exits
return send_otp_to_user(phone_number)
然後另一個功能
def send_otp_to_user(phone_number):
# sends a message to user
return response
問題出在測試我的代碼時,我不想在測試時將消息發送到電話號碼。
我的登錄測試函數看起來有點像這樣,是否可以在不改變我的代碼的情況下進行模擬?
def test_login_initiator(self):
response = self.client.post(self.login_url, data=self.login_data, content_type="application/json", **self.headers)
self.assertEqual(response.status_code, 200)
所有被他人所調用的這些功能都位於單獨的模塊
感謝您的快速響應,send_otp函數實際上調用第三方API來發送短信給用戶的手機,'response'是如果消息成功,我可以發佈實際的代碼段,如果你喜歡。這是隻是爲了簡化事情。 –
哦,基本上,你試圖檢查文本消息是否被成功發送到手機,但不想實際發送正確的消息? –
我只想讓函數返回true(即發送消息),但實際上不發送消息。這就像用'return True'來覆蓋' –