def test_setlanguage(self): ''' Tests responses on setlanguage request. ''' configure_for_unittest() from command import setlanguage from model import Chat chat = Chat(id=1).save() bot = FakeBot() upd = FakeUpdate(message=FakeMessage(chat=FakeChat(id=1))) # valid request upd.message.text = '/setlanguage ru' setlanguage(bot, upd) chat.refresh() self.assertEqual(chat.language, 'ru') self.assertEqual(bot.sended_message['text'], _('The language has changed!')) self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardHide) # trying to set non-existent language upd.message.text = '/setlanguage de' setlanguage(bot, upd) self.assertEqual(bot.sended_message['text'], _('Unknown language!')) self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardHide) # trying to set same language upd.message.text = '/setlanguage ru' setlanguage(bot, upd) self.assertEqual(bot.sended_message['text'], _('You are already using this language!')) self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardHide)
def test_watch(self): ''' Tests responses on watch request. ''' configure_for_unittest() from command import watch from model import Chat, Show, Season, Episode, Video chat = Chat(id=1).save() show = Show(title='House of Cards').save() season1 = Season(show=show, number=1).save() season2 = Season(show=show, number=2).save() episode1 = Episode(season=season1, number=1, release_date=dt(2010, 1, 1)).save() episode2 = Episode(season=season1, number=2).save() episode3 = Episode(season=season2, number=1).save() video1 = Video(link='link to video').save() video2 = Video(link='one more link').save() show.seasons.connect(season1) show.seasons.connect(season2) season1.episodes.connect(episode1) season1.episodes.connect(episode2) season2.episodes.connect(episode3) episode1.videos.connect(video1) episode1.videos.connect(video2) chat.rated_videos.connect(video1, {'value': 1}) bot = FakeBot() upd = FakeUpdate(message=FakeMessage(chat=FakeChat(id=1))) # valid request upd.message.text = '/watch house of cards s1 e1' watch(bot, upd) self.assertEqual(bot.sended_message['text'], 'link to video') self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardMarkup) self.assertEqual(bot.sended_message['reply_markup'].keyboard, [[Emoji.THUMBS_UP_SIGN, Emoji.THUMBS_DOWN_SIGN]]) chat.referer = '' # bot is waiting for feedback chat.save() # valid request - without arguments upd.message.text = '/watch' watch(bot, upd) chat.refresh() self.assertEqual('/watch', chat.referer) self.assertEqual(bot.sended_message['text'], _('Which TV show would you like to see?')) self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardHide) # valid request - continue with show_title upd.message.text = ' '.join([chat.referer, 'house of cards']) watch(bot, upd) chat.refresh() self.assertEqual(chat.referer, '/watch house of cards') self.assertEqual(bot.sended_message['text'], _('Which season would you like to see?')) self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardMarkup) self.assertEqual(bot.sended_message['reply_markup'].keyboard, [['1']]) # valid request - continue with seasons number upd.message.text = ' '.join([chat.referer, 's1']) watch(bot, upd) chat.refresh() self.assertEqual(chat.referer, '/watch house of cards s1') self.assertEqual(bot.sended_message['text'], _('Which episode would you like to see?')) self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardMarkup) self.assertEqual(bot.sended_message['reply_markup'].keyboard, [['1']]) # valid request - continue with episode number upd.message.text = ' '.join([chat.referer, 'e1']) watch(bot, upd) chat.refresh() self.assertEqual(chat.referer, '/rate link to video') self.assertEqual(bot.sended_message['text'], 'link to video') self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardMarkup) self.assertEqual(bot.sended_message['reply_markup'].keyboard, [[Emoji.THUMBS_UP_SIGN, Emoji.THUMBS_DOWN_SIGN]]) chat.referer = '' chat.save() # trying to watch non-existent TV show upd.message.text = '/watch kitchen' watch(bot, upd) self.assertEqual(bot.sended_message['text'], _('This TV show is not available.')) self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardHide) # trying to watch non-existent season upd.message.text = '/watch house of cards s5' watch(bot, upd) self.assertEqual(bot.sended_message['text'], _('This season is not available.')) self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardHide) # trying to watch unavailable season upd.message.text = '/watch house of cards s2 e1' watch(bot, upd) self.assertEqual(bot.sended_message['text'], _('This season is not available.')) self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardHide) # trying to watch non-existent episode upd.message.text = '/watch house of cards s1 e5' watch(bot, upd) self.assertEqual(bot.sended_message['text'], _('This episode is not available.')) self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardHide) # trying to watch unavailable episode upd.message.text = '/watch house of cards s1 e2' watch(bot, upd) self.assertEqual(bot.sended_message['text'], _('This episode is not available.')) self.assertEqual(bot.sended_message['chat_id'], 1) self.assertEqual(type(bot.sended_message['reply_markup']), ReplyKeyboardHide)