def test_serializable(self): keyboard = Keyboard(['버튼1', '버튼2']) serialized = json.dumps(keyboard, ensure_ascii=False) deserialized = json.loads(serialized) assert deserialized == { 'type': 'buttons', 'buttons': ['버튼1', '버튼2'], } assert Keyboard(**deserialized) == keyboard
def test_unsupported_operand(self): with pytest.raises(TypeError) as excinfo: Keyboard([]) + Keyboard([]) assert 'Keyboard + Keyboard' in str(excinfo.value) with pytest.raises(TypeError) as excinfo: Response() + Keyboard([]) assert 'Response + Keyboard' in str(excinfo.value) with pytest.raises(TypeError) as excinfo: Response() + Response() assert 'Response + Response' in str(excinfo.value)
def test_once_input_scenario(self, chatter, data): check = Checker().init(chatter).user(data['user_key']) chatter.add_base('홈', lambda: Keyboard(['숫자 맞추기'])) @chatter.rule('숫자 맞추기', '홈', '맞추는중') def guess(data): message = '숫자 맞추기를 시작합니다.' return Text(message) + Keyboard(type='text') @chatter.rule(action='*', src='맞추는중', dest='홈') def decide(data): answer = data['content'] if answer == '42': text = Text('맞았습니다!') else: text = Text('틀렸습니다!') return text + chatter.home() assert chatter.rules.action('숫자 맞추기').one() is not None assert chatter.rules.src('맞추는중').one() is not None data['content'] = '숫자 맞추기' res = chatter.route(data) data['content'] = '21' res = chatter.route(data) (check.src('맞추는중').dest('홈').msg('text').contain('틀렸습니다').home().do( res)) data['content'] = '숫자 맞추기' res = chatter.route(data) data['content'] = '42' res = chatter.route(data) (check.src('맞추는중').dest('홈').msg('text').contain('맞았습니다').home().do( res))
def intro(data): message = '안녕하세요! 무엇을 도와드릴까요?' buttons = ['오늘의 날씨', '취소'] return Text(message) + Keyboard(buttons)
def hom_keyboard(): home_buttons = ['자기소개', '사이트로 이동하기'] return Keyboard(home_buttons)
class Data: input = Keyboard(type='text') button = Keyboard(['버튼1', '버튼2'])
def test_invalid_no_argument(self): with pytest.raises(TypeError) as excinfo: Keyboard() assert 'buttons must be list' in str(excinfo.value)
def test_invalid_button(self): with pytest.raises(TypeError) as excinfo: Keyboard('버튼1') assert 'buttons must be list' in str(excinfo.value)
def test_invalid_input_with_button(self): with pytest.raises(TypeError) as excinfo: Keyboard(['버튼1'], type='text') assert 'buttons must be None' in str(excinfo.value)
def test_button(self, keyboard): button_keyboard = Keyboard(['버튼1', '버튼2']) assert keyboard.dict.button == button_keyboard assert button_keyboard.type == 'buttons' assert button_keyboard.buttons == ['버튼1', '버튼2']
def test_input(self, keyboard): input_keyboard = Keyboard(type='text') assert keyboard.dict.input == input_keyboard assert input_keyboard.type == 'text' assert input_keyboard.buttons is None
def home_keyboard(): home_buttons = ['과사무실 전화번호', '소프트웨어융합대학 홈페이지', '문의하기'] return Keyboard(home_buttons)
def guess(data): message = '숫자 맞추기를 시작합니다.' return Text(message) + Keyboard(type='text')
def try_again(data): text = Text('틀렸습니다.') keyboard = Keyboard(type='text') return text + keyboard
def test_homebase_without_args(self): home = HomeBase() home.name = '홈' home.func = lambda: Keyboard(['버튼']) assert home() == home.func()
def keyboard(): return Keyboard(['버튼'])