import unittest

from hn import HN
from hn import utils

class TestPagination(unittest.TestCase):

    def setUp(self):
        self.hn = HN()
    
    def tearDown(self):
        pass
    
    def test_more_link_top(self):
        """
        Checks if the "More" link at the bottom of homepage works.
        """
        soup = utils.get_soup()
        fnid = self.hn._get_next_page(soup).lstrip('//')
        expected = 'news2'
        self.assertEqual(len(fnid), len(expected))
        
    def test_more_link_best(self):
        """
        Checks if the "More" link at the bottom of best page works.
        """
        soup = utils.get_soup(page='best')
        fnid = self.hn._get_next_page(soup).lstrip('//')
        expected = 'x?fnid=te9bsVN2BAx0XOpRmUjcY4'
        self.assertEqual(len(fnid), len(expected))
        
    def test_more_link_newest(self):
        """
        Checks if the "More" link at the bottom of newest page works.
        """
        soup = utils.get_soup(page='newest')
        fnid = self.hn._get_next_page(soup).lstrip('//')
        expected = 'x?fnid=te9bsVN2BAx0XOpRmUjcY4'
        self.assertEqual(len(fnid), len(expected))
    
    def test_get_soups_length_best(self):
        """
        Checks if appropriate number of soups are returned on best page.
        """
        soups = self.hn._get_soups(page='best', page_limit=2)
        self.assertEqual(len(soups), 2)
    
    def test_get_zipped_rows(self):
        """
        Tests HN._get_zipped_rows for best page.
        """
        soup = utils.get_soup(page='best')
        rows = self.hn._get_zipped_rows(soup)
        self.assertEqual(len(rows), 30)
    
    
    def test_pagination_top_for_2_pages(self):
        """
        Checks if the pagination works for the front page.
        """
        stories = self.hn.get_stories(page_limit=2)
        self.assertEqual(len(stories), 2 * 30)
    
    def test_pagination_newest_for_3_pages(self):
        """
        Checks if the pagination works for the newest page.
        """
        stories = self.hn.get_stories(story_type='newest', page_limit=3)
        self.assertEqual(len(stories), 3 * 30)
        
    def test_pagination_best_for_2_pages(self):
        """
        Checks if the pagination works for the best page.
        """
        stories = self.hn.get_stories(story_type='best', page_limit=2)
        self.assertEqual(len(stories), 2 * 30)

if __name__ == '__main__':
    unittest.main()
@@ -8,16 +8,27 @@
 unittest
+%0Aimport sys
 %0A%0Afrom h
@@ -116,32 +116,103 @@
 ef setUp(self):%0A
+        # check py version%0A        self.PY2 = sys.version_info%5B0%5D == 2%0A
         self.hn 
@@ -1688,16 +1688,140 @@
 s(soup)%0A
+        if self.PY2:%0A            self.assertEqual(len(rows), 30)%0A        else:%0A            rows = %5Brow for row in rows%5D%0A    
         

add test support for py3