Example #1
0
    def test_can_setup_with_max(self):
        """Test if a HackerNews instance can be created with custom max."""

        hackernews = HackerNews()
        hackernews.setup(url=self.url, max=50)
        self.assertEqual(hackernews.url, self.url)
        self.assertEqual(hackernews.max, 50)
        self.assertEqual(hackernews.file, './hackernews.txt')
Example #2
0
    def test_can_setup_with_defaults(self):
        """Test if a HackerNews instance with a custom URL gets default max and
        file name fields."""

        hackernews = HackerNews()
        hackernews.setup(url=self.url)
        self.assertEqual(hackernews.url, self.url)
        self.assertEqual(hackernews.max, 25)
        self.assertEqual(hackernews.file, './hackernews.txt')
Example #3
0
    def test_setup_hackernews_max_file(self):
        """Test if a HackerNews instance can be created with custom URL, max,
        and filename fields.
        """

        hackernews = HackerNews()
        hackernews.setup(url=self.url, max=50, file='hackernews3.txt')
        self.assertEqual(hackernews.url, self.url)
        self.assertEqual(hackernews.max, 50)
        self.assertEqual(hackernews.file, 'hackernews3.txt')
Example #4
0
    def test_setup_hackernews_with_file(self):
        """Test if a HackerNews instance can be created with a custom output
        file name.
        """

        hackernews = HackerNews()
        hackernews.setup(url=self.url, file='hackernews2.txt')
        self.assertEqual(hackernews.url, self.url)
        self.assertEqual(hackernews.max, 25)
        self.assertEqual(hackernews.file, 'hackernews2.txt')
Example #5
0
    def test_can_write_to_file(self):
        """ Test the save_link method on a file.
        Writes to the file (within save_link()) and reads from the file to
        verify that it was in fact written to with the expected data.
        """

        write_str = 'hello\tworld\n'
        filename = 'testfile.txt'
        hackernews = HackerNews()
        hackernews.setup(file=filename)
        hackernews.save_link('hello', 'world')
        with open('testfile.txt', 'r+') as out_file:
            buf = out_file.read(256)
            self.assertEqual(buf, write_str)
Example #6
0
    def test_setup_no_url(self):
        """Test if a HackerNews instance with no URL gets the default."""

        hackernews = HackerNews()
        hackernews.setup()
        self.assertEqual(hackernews.url, hackernews.TOP_STORIES)