Esempio n. 1
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")
Esempio n. 2
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)