def test_createThreadStruct(self): mockweb = MockWebClient(HTMLFactory.tablamensajes_html()) self.threadfactory = AsuntoFactory(mockweb) self.assertEquals("", self.threadfactory.nextUrl()) thread = self.threadfactory.create(HTMLFactory.asunto()) msgs = list() struct = ThreadModel(self. processthread._createThreadStruct(thread, msgs)) self.assertEquals("LaBSK", struct.source()) self.assertEquals(thread['title'], struct.title()) self.assertEquals(struct.answers(), 0) self.assertIsInstance(struct.json()['msgs'], list)
class TestProcessThread(unittest.TestCase): def setUp(self): self.processthread = ProcessThread() self.t01 = ThreadModel(Reports.get_asylum_thread()) self.t02 = ThreadModel(Reports.get_asylum_thread()) self.listener = mock() self.processthread.listener = self.listener def test_set_the_limit_for_process_msg(self): #self.processthread.setMsgPageLimit(4) self. processthread.msgpagelimit = 4 process = self. processthread._createProcessMsgs() self.assertEqual(process.pagelimit, 4) # Pocess Thread def test_createThreadStruct(self): mockweb = MockWebClient(HTMLFactory.tablamensajes_html()) self.threadfactory = AsuntoFactory(mockweb) self.assertEquals("", self.threadfactory.nextUrl()) thread = self.threadfactory.create(HTMLFactory.asunto()) msgs = list() struct = ThreadModel(self. processthread._createThreadStruct(thread, msgs)) self.assertEquals("LaBSK", struct.source()) self.assertEquals(thread['title'], struct.title()) self.assertEquals(struct.answers(), 0) self.assertIsInstance(struct.json()['msgs'], list) def test_when_thread_is_new_then_store_it(self): self.processthread.database = mock() self.processthread.processmsgfactory = mock() page = mock() when(page).createListOfMsgs().thenReturn(list()) when(self.processthread.processmsgfactory).create(any()).thenReturn(page) thread = mock() self.processthread._evaluate_thread(thread) verify(self.processthread.database, times=1).saveThread(any()) def test_when_thread_exists_not_saved(self): self.db = mock() when(self.db).find_one_by('link', self.t01.link()).thenReturn(self.t01.json()) self.processthread.database = self.db self.processthread._evaluate_thread(self.t01) verify(self.db, times=1).find_one_by('link', self.t01.link()) verify(self.db, times=0).saveThread(any()) verify(self.listener, times=1).skippingUnmodifiedThread(any(), any()) def test_hilo_igual_es_no_modificado(self): self.assertTrue(self.processthread._is_unmodified(self.t01, self.t02)) def test_hilo_distinto_num_de_mensajes_es_modificado(self): self.t01.msgList().append_msg({'date': "Otra fecha"}) self.assertFalse(self.processthread._is_unmodified(self.t01, self.t02)) """ Ya no uso este criterio