Ejemplo n.º 1
0
class TestMsgFactory(unittest.TestCase):
    def setUp(self):
        self.fragment = HTMLFactory().msg()
        webclient = MockWebClient(HTMLFactory.msg_html())
        self.factory = MsgFactory(webclient)

    def test_user(self):
        res = self.factory.createMsg(self.fragment)
        self.assertEqual(res['user'], "flOrO")

    def test_date(self):
        res = self.factory.createMsg(self.fragment)
        self.assertEqual(res['date'], u' 25 de Octubre de 2013, 12:12:00 pm \xbb')

    """
    def test_body(self):
        res = self.factory.createMsg(self.fragment, "XX")
        self.assertEqual(res['body'], "XX")
    """

    def test_create_with_webclient(self):
        res = self.factory.create()
        self.assertEqual(res['date'], u' 25 de Octubre de 2013, 12:12:00 pm \xbb')
        self.assertEqual(res['user'], "flOrO")

    def test_create_list_of_msgs(self):
        msgs = self.factory.createListOfMsgs()
        self.assertEqual(len(msgs), 2)

    def test_create_list_of_msgs_includes_body(self):
        msgs = self.factory.createListOfMsgs()
        msg = msgs[1]
        self.assertEqual(msg['body'], u"Body")

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

        self.assertEqual(url, webclient.url)
Ejemplo n.º 2
0
class TestMsgFactory(unittest.TestCase):
    def setUp(self):
        self.fragment = HTMLFactory().msg()
        webclient = MockWebClient(HTMLFactory.msg_html())
        self.factory = MsgFactory(webclient)
        self.msg_from_fragment = self.factory.createMsg(self.fragment)
        self.extected_content = u'Content\n'

    def test_user(self):
        self.assertEqual(self.msg_from_fragment['user'], "flOrO")

    def test_date(self):
        self.assertEqual(self.msg_from_fragment['date'],
                         u' 25 de Octubre de 2013, 12:12:00 pm \xbb')

    def test_body(self):
        msg = MsgModel(self.msg_from_fragment)
        self.assertIn("Parece ser que este juego de Asyncro Games",
                      msg.body())

    def test_id(self):
        self.assertEqual(self.msg_from_fragment['id'], "msg_1169262")

    def test_create_list_of_msgs(self):
        msgs = self.factory.createListOfMsgs()
        self.assertEqual(len(msgs), 2)

    def test_create_list_of_msgs_includes_body(self):
        msgs = self.factory.createListOfMsgs()
        msg = msgs[1]
        self.assertEqual(msg['body'], u"Body\n")

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

        self.assertEqual(url, webclient.url)

    def test_msg_with_HTML_inside(self):
        self.factory = MsgFactory(MockWebClient(HTMLFactory.msg_html()))
        res = self.factory.createMsg(HTMLFactory.msg_with_html)
        self.assertEqual(res['user'], "LudoNoticias")
        msg = MsgModel(res)
        self.assertEqual(msg.body()[:10], "Osprey Pub")

    def test_get_content_recursively_no_tags(self):
        html = BeautifulSoup("Content")
        res = self.factory._get_content_recursively(html)
        self.assertEqual(self.extected_content, res)

    def test_get_content_recursively_one_tag(self):
        html = BeautifulSoup("<strong>Content</strong>")
        res = self.factory._get_content_recursively(html)
        self.assertEqual(self.extected_content, res)

    def test_get_content_recursively_two_tags(self):
        html = BeautifulSoup("<strong><i>Content</i></strong>")
        res = self.factory._get_content_recursively(html)
        self.assertEqual(self.extected_content, res)

    def test_get_content_recursively_list_of_tags(self):
        html = BeautifulSoup("<strong>Content</strong> <i>Content</i>")
        res = self.factory._get_content_recursively(html)
        self.assertEqual(u'Content\n \nContent\n', res)

    def test_get_content_recursively_empty(self):
        html = BeautifulSoup("")
        res = self.factory._get_content_recursively(html)
        self.assertEqual("", res)

    def test_get_date_when_date_is_hoy(self):
        html = BeautifulSoup("""<div class="smalltext">&#171; <strong>Respuesta #45 en:</strong> <strong>Hoy</strong> a las 12:05:56 pm &#187;</div>""")
        self.factory.date_manager.now = TestMsgFactory.mock_hoy
        res = self.factory._get_date(html)
        self.assertEqual(u"1 de Enero de 2014, a las 12:05:56 pm \xbb", res)

    @staticmethod
    def mock_hoy():
        return datetime(2014, 01, 01)