class TestHtmlParser(unittest.TestCase):

    def setUp(self):
        f = codecs.open('test-page1.html', 'r', 'utf-8')
        self.html = f.read()
        self.reader = HtmlParser()

    def testParseMatchesInPlayerPage(self):
        matches = self.reader.find_matches(self.html)

        answer = [Match(656830280, datetime(2014, 5, 12, 18, 40), (28, 4)),
                  Match(656759204, datetime(2014, 5, 12, 18, 0), (36,54)),
                  Match(655653242, datetime(2014, 5, 12, 5, 10), (42,25)),
                  Match(655639078, datetime(2014, 5, 12, 4, 16), (5,39)),
                  Match(655610044, datetime(2014, 5, 12, 4, 4), (34,1)),
                  Match(655198197, datetime(2014, 5, 11, 19, 31), (46,15)),
                  Match(654944424, datetime(2014, 5, 11, 17, 5), (54,24)),
                  Match(654717322, datetime(2014, 5, 11, 14, 53), (39,38)),
                  Match(653725177, datetime(2014, 5, 11, 5, 12), (38,24)),
                  Match(653221484, datetime(2014, 5, 10, 20, 16), (42,8)),
                  Match(653097369, datetime(2014, 5, 10, 19, 1), (42,29)),
                  Match(652982870, datetime(2014, 5, 10, 17, 50), (44,8)),
                  Match(652756205, datetime(2014, 5, 10, 15, 41), (29,57)),
                  Match(652288108, datetime(2014, 5, 10, 11, 47), (40,8)),
                  Match(651421025, datetime(2014, 5, 9, 21, 29), (41,8)),
                  Match(651256378, datetime(2014, 5, 9, 19, 22), (43,51)),
                  Match(651206198, datetime(2014, 5, 9, 18, 29), (26,29)),
                  Match(650785626, datetime(2014, 5, 9, 14, 47), (54,27)),
                  Match(650717825, datetime(2014, 5, 9, 13, 44), (28,34)),
                  Match(650014223, datetime(2014, 5, 9, 4, 43), (44,5))]

        length = min(len(answer), len(matches))

        for i in range(0, length):
            expected_match = answer[i]
            match = matches[i]

            self.assertEqual(expected_match.match_id, match.match_id)
            self.assertEqual(expected_match.datetime, match.datetime)
            self.assertEqual(expected_match.duration, match.duration)

        self.assertEqual(20, len(matches))

    def testStringToDatetime(self):
        date = datetime.strptime('May 12, 2014 18:40 +00:00', '%b %d, %Y %H:%M +00:00')

        self.assertEqual(2014, date.year)
        self.assertEqual(5, date.month)
        self.assertEqual(12, date.day)
        self.assertEqual(18, date.hour)
        self.assertEqual(40, date.minute)
 def setUp(self):
     f = codecs.open('test-page1.html', 'r', 'utf-8')
     self.html = f.read()
     self.reader = HtmlParser()