def test_vk_upload_photo_w_peer_id(self): actions = [] env = VKEnvironment(self.get_fake_manager(actions), None) async def _upload_file_to_vk(self, url, data): return {"doc": "upload"} env.replace_method("_upload_file_to_vk", _upload_file_to_vk) attachment = self.loop.run_until_complete( env.upload_photo(b"file", peer_id=2)) self.assertEqual(attachment, "file") self.assertEqual(len(actions), 3) self.assertEqual(actions[0], ('photos.getMessagesUploadServer', { 'peer_id': 2 })) self.assertEqual(actions[1], ('photos.saveMessagesPhoto', { 'doc': 'upload' })) self.assertEqual(actions[2], ('attachment', 'photo'))
def test_vk_upload_doc(self): actions = [] env = VKEnvironment(self.get_fake_manager(actions), None) async def _upload_file_to_vk(self, url, data): return {"doc": "upload"} env.replace_method("_upload_file_to_vk", _upload_file_to_vk) attachment = self.loop.run_until_complete( env.upload_doc(b"file", "filename")) self.assertEqual(attachment, "file") self.assertEqual(len(actions), 3) self.assertEqual(actions[0], ('docs.getWallUploadServer', { 'group_id': 10, 'type': 'doc' })) self.assertEqual(actions[1], ('docs.save', {'doc': 'upload'})) self.assertEqual(actions[2], ('attachment', 'doc'))
def test_concrete_environments(self): env1 = VKEnvironment("vk") env2 = TGEnvironment("tg") env1.replace_method("reply", print) env1.a = 10 child1 = env1.spawn() self.assertEqual(child1.a, 10) self.assertEqual(child1.reply.func, print) env2.replace_method("reply", print) env2.a = 10 child2 = env2.spawn() self.assertEqual(child2.a, 10) self.assertEqual(child2.reply.func, print)