示例#1
0
class TestProcessThreads(unittest.TestCase):

    def setUp(self):
        mockweb = MockWebClient(HTMLFactory.tablamensajes_html())
        self.threadfactory = AsuntoFactory(mockweb)
        self.mongo = MockMongo()
        self.processthread = ProcessThreads(self.mongo, MockMsgPageFactory())
        self.navhtml = HTMLFactory.tablamensajes_html() +  HTMLFactory.navigation_url()

    def test_getlistofthreads(self):
        self.assertEquals("", self.threadfactory.nextUrl())
        self.processthread.storeThreads(self.threadfactory)

        self.assertEquals(2, self.mongo.treadssaved)

    def test_createThreadStruct(self):
        self.assertEquals("", self.threadfactory.nextUrl())
        thread = self.threadfactory.create(HTMLFactory.asunto())
        msgs = list()
        struct = self.processthread._createThreadStruct(thread, msgs)

        self.assertEquals("LaBSK", struct['source'])
        self.assertEquals(thread['title'], struct['title'])
        self.assertIsInstance(struct['msgs'], list)

    def test_createThreadStruct_with_msgs(self):
        self.processthread.storeThreads(self.threadfactory)

        self.assertEquals(2, len(self.mongo.listofthreads))
        thread = self.mongo.listofthreads[0]
        self.assertEqual(2, len(thread['msgs']))

    def test_default_pagelimit_is_1(self):
        mockweb = MockWebClient(self.navhtml)
        self.processthread.storeThreads(AsuntoFactory(mockweb))

        self.assertEquals(2, len(self.mongo.listofthreads))

    def test_two_loops(self):
        mockweb = MockWebClient(self.navhtml)
        self.processthread.pagelimit = 2
        self.processthread.storeThreads(AsuntoFactory(mockweb))

        self.assertEquals(4, len(self.mongo.listofthreads))

    def test_generate_new_factory(self):
        oldpage = AsuntoFactory( MockWebClient(self.navhtml))
        page = self.processthread._nextPage(oldpage)

        self.assertEquals(u"http://labsk.net/index.php?board=18.20", page.webclient.url)
示例#2
0
class TestProcessThreads(unittest.TestCase):

    def setUp(self):
        mockweb = MockWebClient(HTMLFactory.tablamensajes_html())
        self.threadfactory = AsuntoFactory(mockweb)
        self.mongo = MockMongo()
        self.processthread = ProcessThreads(self.mongo, MockMsgPageFactory())
        self.navhtml = HTMLFactory.tablamensajes_html() +  HTMLFactory.navigation_url()

    def test_getlistofthreads(self):
        self.assertEquals("", self.threadfactory.nextUrl())
        self.processthread.storeThreads(self.threadfactory)

        self.assertEquals(2, self.mongo.treadssaved)

    def test_createThreadStruct_with_msgs(self):
        self.processthread.storeThreads(self.threadfactory)

        self.assertEquals(2, len(self.mongo.listofthreads))
        thread = self.mongo.listofthreads[0]
        self.assertEqual(2, len(thread['msgs']))

    def test_createThreadStruct_stores_locaton(self):
        urlobject = mock()
        when(urlobject).description().thenReturn("X")
        self.threadfactory.urlobject = urlobject

        self.processthread.storeThreads(self.threadfactory)

        self.assertEquals(2, len(self.mongo.listofthreads))
        thread = self.mongo.listofthreads[0]
        self.assertEqual("X", thread['location'])


    def test_default_pagelimit_is_1(self):
        mockweb = MockWebClient(self.navhtml)
        self.processthread.storeThreads(AsuntoFactory(mockweb))

        self.assertEquals(2, len(self.mongo.listofthreads))

    def test_two_loops(self):
        mockweb = MockWebClient(self.navhtml)
        self.processthread.pagelimit = 2
        self.processthread.storeThreads(AsuntoFactory(mockweb))

        self.assertEquals(4, len(self.mongo.listofthreads))

    def test_generate_new_factory(self):
        oldpage = AsuntoFactory( MockWebClient(self.navhtml))
        page = self.processthread._nextPage(oldpage)

        self.assertEquals(u"http://labsk.net/index.php?board=18.20", page.webclient.url)
示例#3
0
class TestAsuntoFactory(unittest.TestCase):
    def setUp(self):
        self.fragment = HTMLFactory().asunto()
        self.factory = AsuntoFactory()

    def test_title(self):
        res = self.factory.create(self.fragment)
        self.assertEqual(res['title'], u'Robinson Crusoe de Portal Games en espanol (al 95)')

    def test_link(self):
        res = self.factory.create(self.fragment)
        self.assertEqual(res['link'], u'http://labsk.net/index.php?topic=126314.0')

    def test_location(self):
        self.factory.urlobject = URL("Url", "Desc")
        thread = ThreadModel(self.factory.create(self.fragment))
        self.assertEqual(thread.location(), u'Desc')

    def test_location_is_empty_when_no_Urlobject_is_given(self):
        thread = ThreadModel(self.factory.create(self.fragment))
        self.assertEqual(thread.location(), "")

    def test_answers_y_views(self):
        thread = ThreadModel(self.factory.create(self.fragment))
        self.assertEqual(thread.answers(), 10)
        self.assertEqual(thread.views(), "490")

    def test_next_url(self):
        mockweb = MockWebClient(HTMLFactory.navigation_url())
        self.factory = AsuntoFactory(mockweb)
        self.assertEqual(self.factory.nextUrl(), u'http://labsk.net/index.php?board=18.20')

    def test_next_url_is_empty_when_not_next_URL(self):
        mockweb = MockWebClient(HTMLFactory.tablamensajes_html())
        self.factory = AsuntoFactory(mockweb)
        self.assertEqual(self.factory.nextUrl(), "")

    def test_create_asuntos(self):
        res = self.factory.createListOfAsuntos(HTMLFactory.tablamensajes())
        self.assertEquals(2, len(res))
        self.assertEqual(res[0]['title'], u'1936 guerra civil -  D6')
        self.assertEqual(res[1]['title'], u'Temporada de Regionales 2014 de Edge')

    def test_create_webclient(self):
        mockweb = MockWebClient(HTMLFactory.tablamensajes_html())
        self.factory =  AsuntoFactory(mockweb)
        res = self.factory.createListOfAsuntos()
        self.assertEquals(2, len(res))
        self.assertEqual(res[0]['title'], u'1936 guerra civil -  D6')
        self.assertEqual(res[1]['title'], u'Temporada de Regionales 2014 de Edge')

    def test_change_url(self):
        webclient = MockWebClient(HTMLFactory.navigation_url())
        self.factory = AsuntoFactory(webclient)
        url = "xxxx"
        self.factory.changeUrl(url)
        self.assertEqual(url, webclient.url)

    def test_when_change_url_descripcion_remains_the_same(self):
        webclient = MockWebClient(HTMLFactory.navigation_url())
        self.factory = AsuntoFactory(webclient)
        self.factory.urlobject = URL("Url", "Desc")
        self.factory.changeUrl("yyy")
        thread = ThreadModel(self.factory.create(self.fragment))
        self.assertEqual(thread.location(), u'Desc')

    def test_create_with_url(self):
        url = "xxx"
        factory = AsuntoFactory(url=url)

        self.assertEqual(url, factory.webclient.url)

    def test_append_if_valid_when_is_Valid(self):
        l = list()
        msg = {'tile': 'x', 'link': 'y'}
        self.factory.append_if_valid(l, msg)
        self.assertEquals(len(l), 1)

    def test_append_if_valid_when_is_not_Valid(self):
        l = list()
        msg = {'tile': "", 'link': ""}
        self.assertEquals(len(l), 0)
        self.factory.append_if_valid(l, msg)
        self.assertEquals(len(l), 0)

    def test_get_number_from(self):
        txt = "10 resuestas"
        self.assertEqual("10",  self.factory._get_number_from(txt))

    def test_create_with_URL_object(self):
        asunto = AsuntoFactory.createFromURLObject(URL("xx", "yy"))
        self.assertEqual(asunto.webclient.url, "xx")
示例#4
0
class TestAsuntoFactory(unittest.TestCase):
    def setUp(self):
        self.fragment = HTMLFactory().asunto()
        self.factory = AsuntoFactory()

    def test_title(self):
        res = self.factory.create(self.fragment)
        #print res['title']
        self.assertEqual(res['title'], u'Robinson Crusoe de Portal Games en espanol (al 95)')

    def test_link(self):
        res = self.factory.create(self.fragment)
        #print res['link']
        self.assertEqual(res['link'], u'http://labsk.net/index.php?topic=126314.0')

    def test_next_url(self):
        mockweb = MockWebClient(HTMLFactory.navigation_url())
        self.factory =  AsuntoFactory(mockweb)
        self.assertEqual(self.factory.nextUrl(), u'http://labsk.net/index.php?board=18.20')

    def test_next_url_is_empty_when_not_next_URL(self):
        mockweb = MockWebClient(HTMLFactory.tablamensajes_html())
        self.factory =  AsuntoFactory(mockweb)
        self.assertEqual(self.factory.nextUrl(), "")

    def test_create_asuntos(self):
        res = self.factory.createListOfAsuntos(HTMLFactory.tablamensajes())
        self.assertEquals(2, len(res))
        self.assertEqual(res[0]['title'], u'1936 guerra civil -  D6')
        self.assertEqual(res[1]['title'], u'Temporada de Regionales 2014 de Edge')

    def test_create_webclient(self):
        mockweb = MockWebClient(HTMLFactory.tablamensajes_html())
        self.factory =  AsuntoFactory(mockweb)
        res = self.factory.createListOfAsuntos()
        self.assertEquals(2, len(res))
        self.assertEqual(res[0]['title'], u'1936 guerra civil -  D6')
        self.assertEqual(res[1]['title'], u'Temporada de Regionales 2014 de Edge')

    def test_change_url(self):
        webclient = MockWebClient(HTMLFactory.navigation_url())
        self.factory = AsuntoFactory(webclient)
        url = "xxxx"
        self.factory.changeUrl(url)

        self.assertEqual(url, webclient.url)

    def test_create_with_url(self):
        url = "xxx"
        factory = AsuntoFactory(url=url)

        self.assertEqual(url, factory.webclient.url)

    def test_append_if_valid_when_is_Valid(self):
        l = list()
        msg = {'tile': 'x', 'link': 'y'}

        self.factory.append_if_valid(l, msg)

        self.assertEquals(len(l), 1)

    def test_append_if_valid_when_is_not_Valid(self):
        l = list()
        msg = {'tile': "", 'link': ""}

        self.factory.append_if_valid(l, msg)

        self.assertEquals(len(l), 0)
示例#5
0
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