def test_download_line_sticker(self): sticker = Sticker(self._mock_bot, TEST_USER_NAME, TEST_USER_ID, TEST_CHAT_ID, 1646410) sticker.download_line_sticker() _, _, files = next(os.walk(sticker._sticker_dir)) actual = len(files) assert actual == 16
def test_unzip_sticker(self): sticker = Sticker(self._mock_bot, TEST_USER_NAME, TEST_USER_ID, TEST_CHAT_ID) shutil.copy('./tests/static/zip/test.zip', sticker._sticker_dir) sticker.unzip_sticker('test.zip') _, dirs, files = next(os.walk(sticker._sticker_dir)) assert len(files) == 3 assert len(dirs) == 1
def test_is_already_sticker_name(self, sticker_set_name, ans): sticker = Sticker(self._mock_bot, TEST_USER_NAME, TEST_USER_ID, TEST_CHAT_ID) self._mock_bot.getStickerSet = asynctest.Mock( side_effect=MockTelepot.mock_get_sticker_set) loop = asyncio.get_event_loop() actual = loop.run_until_complete( sticker.is_already_sticker_name(sticker_set_name)) assert actual is ans
def test_generate_sticker_name(self, sticker_id, file_name, ans): self._mock_bot.getMe = asynctest.Mock( side_effect=MockTelepot.mock_get_me) sticker = Sticker(self._mock_bot, TEST_USER_NAME, TEST_USER_ID, TEST_CHAT_ID, sticker_id) loop = asyncio.get_event_loop() actual = loop.run_until_complete( sticker.generate_sticker_name(file_name=file_name)) assert actual == ans
def test_resize_sticker(self): sticker = Sticker(self._mock_bot, TEST_USER_NAME, TEST_USER_ID, TEST_CHAT_ID) for filename in glob.glob('./tests/static/png/*.*'): shutil.copy(filename, sticker._sticker_dir) sticker.resize_sticker() png_list = glob.glob(f'{sticker._sticker_dir}/*.png') for png in png_list: img = Image.open(png) width, height = img.size actual = max(width, height) assert actual == 512
def test_register_line_sticker(self, command, ans): self._mock_bot.sendMessage = asynctest.Mock( side_effect=MockTelepot.mock_send_message) self._mock_bot.getMe = asynctest.Mock( side_effect=MockTelepot.mock_get_me) sticker = Sticker(self._mock_bot, TEST_USER_NAME, TEST_USER_ID, TEST_CHAT_ID) sticker.create_sticker_set = asynctest.Mock( side_effect=self.mock_create_sticker_set) StickerStore.insert_sticker_info = MagicMock( side_effect=self.mock_insert_sticker_info) StickerStore.fetch_line_sticker_info = MagicMock( side_effect=self.mock_fetch_line_sticker_info) loop = asyncio.get_event_loop() actual = loop.run_until_complete( sticker.register_line_sticker(command)) assert actual is ans
def test_create_sticker_set(self, sticker_title, sticker_set_name, ans): sticker = Sticker(self._mock_bot, TEST_USER_NAME, TEST_USER_ID, TEST_CHAT_ID) for filename in glob.glob('./tests/static/png/*.*'): shutil.copy(filename, sticker._sticker_dir) self._mock_bot.uploadStickerFile = asynctest.Mock( side_effect=MockTelepot.mock_upload_sticker_file) self._mock_bot.createNewStickerSet = asynctest.Mock( side_effect=MockTelepot.mock_create_new_sticker_set) self._mock_bot.addStickerToSet = asynctest.Mock( side_effect=MockTelepot.mock_add_sticker_to_set) sticker.delete_sticker_set = asynctest.Mock( side_effect=self.mock_delete_sticker_set) loop = asyncio.get_event_loop() actual = loop.run_until_complete( sticker.create_sticker_set(sticker_title, sticker_set_name)) assert actual is ans
def test_fetch_line_sticker_title(self, stikcer_id, region, ans): sticker = Sticker(self._mock_bot, TEST_USER_NAME, TEST_USER_ID, TEST_CHAT_ID, stikcer_id) actual = sticker.fetch_line_sticker_title(region=region) assert actual == ans
def test_new_size(self, width, height): new_w, new_h = Sticker.new_size(width, height) actual = max(new_w, new_h) assert actual == 512