def test_callback_response_with_test_object_2(self): Theme.objects.create(name='test_obj_2') test_object = TestModelMaterial() test_object.theme = Theme.objects.get(id=1) test_object.text = "gg" test_object.pub_date = '12.12.2020' Material.objects.create(theme=test_object.theme, text=test_object.text, pub_date=test_object.pub_date, file=upload_material_file_folder( test_object, 'gg.docx')) data = { "object": { "message": { "from_id": BotTest.test_id, "text": "test_obj_2" } } } vk_bot_test = vk_bot.VkBot() vk_bot_test.callback_response(data) res = self.vk.method("messages.getConversations", { "offset": 0, "count": 1, "filter": "all" }) self.assertEquals( res['items'][0]["last_message"]['text'], "Все имеющиеся материалы по дисциплине test_obj_2 предоставлены")
def test_message_send_empty_file_name(self): rnd = random.randint(1, 2147483647) test_object = vk_bot.VkBot() test_text = 'Тест' test_object.vk_message_send(text=test_text, id=BotTest.test_id, file_name='', rnd=rnd) res = self.vk.method("messages.getConversations", { "offset": 0, "count": 1, "filter": "all" }) self.assertEquals(res['items'][0]["last_message"]['text'], test_text)
def test_callback_response_theme_empty(self): data = { "object": { "message": { "from_id": BotTest.test_id, "text": "Тест_" } } } vk_bot_test = vk_bot.VkBot() vk_bot_test.callback_response(data) res = self.vk.method("messages.getConversations", { "offset": 0, "count": 1, "filter": "all" }) self.assertEquals(res['items'][0]["last_message"]['text'], "Данного предмета нет")
def test_message_send_with_bad_file_name(self): try: rnd = random.randint(1, 2147483647) test_object = vk_bot.VkBot() test_text = 'Тест' test_file_path = 'gsad\grf3sad.docx' test_object.vk_message_send(text=test_text, id=BotTest.test_id, file_name=test_file_path, rnd=rnd) res = self.vk.method("messages.getConversations", { "offset": 0, "count": 1, "filter": "all" }) self.assertTrue(False) except: self.assertTrue(True)
def test_message_send_with_file_name_2(self): rnd = random.randint(1, 2147483647) test_object = vk_bot.VkBot() test_text = 'Тест' test_file_path = 'gsad\gsad.docx' test_file_name = 'gsad.docx' test_object.vk_message_send(text=test_text, id=BotTest.test_id, file_name=test_file_path, rnd=rnd) res = self.vk.method("messages.getConversations", { "offset": 0, "count": 1, "filter": "all" }) self.assertEquals( res['items'][0]["last_message"]['attachments'][0]['doc']['title'], test_file_name)
def test_callback_response_material_empty(self): Theme.objects.create(name='test_obj_11') data = { "object": { "message": { "from_id": BotTest.test_id, "text": "test_obj_11" } } } vk_bot_test = vk_bot.VkBot() vk_bot_test.callback_response(data) res = self.vk.method("messages.getConversations", { "offset": 0, "count": 1, "filter": "all" }) self.assertEquals(res['items'][0]["last_message"]['text'], "Данных по test_obj_11 пока нет")