-
-
Save hyunjun/fc03491d5775a51c0f247ef06528eb56 to your computer and use it in GitHub Desktop.
unittest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from config import * | |
from flask import Flask | |
from flask import jsonify | |
from test_chat import TestChat | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
import os | |
import unittest | |
import pytest | |
class TestBookingConfirmation(TestChat): | |
def test_get_booking_confirmation(self): | |
"""Get booking confirmation""" | |
self.logger.info("start chat") | |
self.mylogger = logging.getLogger() | |
self.params['bookingId'] = GENERIC_BOOKING | |
self.params['message'] = "" | |
self.params['intent'] = "StartChat" | |
self.mylogger.info('INFO') | |
response = self.get_response() | |
MESSAGES.append(response) | |
#self.messages.append(response['message']) | |
#self.responseTypes.append(response['responseType']) | |
self.assertIn("What can I help you with today?", response['message']) | |
self.assertEqual("StartChat", response['responseType']) | |
self.mylogger.debug('DEBUG') | |
self.params['message'] = "" | |
self.params['intent'] = "ResendConfirmation" | |
self.params['id'] = self.get_new_id() | |
response = self.get_response() | |
MESSAGES.append(response) | |
self.assertIn("copy of your booking confirmation sent to your email", response['message']) | |
self.assertEqual("RequestBookingConfirmation", response['responseType']) | |
self.assertTrue(response['disableTextInput']) | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
t = unittest.TestLoader().loadTestsFromTestCase(TestBookingConfirmation) | |
unittest.TextTestRunner(verbosity=2).run(t) | |
# 이렇게 local variable로 복사하고 clear하지 않음면 MESSAGES에 response가 계속 누적. cache때문인 듯 싶지만 확실하진 않음 | |
msgs = MESSAGES[:] | |
MESSAGES.clear() | |
return jsonify(msgs) | |
if __name__ == '__main__': | |
app.run() | |
# 그냥 main에서 호출해서 python3 main.py로 실행하기 | |
# https://docs.python.org/3/library/unittest.html | |
# https://stackoverflow.com/questions/13761697/how-to-access-the-unittest-mainverbosity-setting-in-a-unittest-testcase | |
#unittest.main() | |
#t = unittest.TestLoader().loadTestsFromTestCase(TestBookingConfirmation) | |
#unittest.TextTestRunner(verbosity=2).run(t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment