Example #1
0
 def test_json_news_no_limit(self, args, res):
     """Tests --date with --json with --limit"""
     parsed_arg = self.arg_parser.parse_args(args)
     storage = reader.selection_from_db(parsed_arg.date)
     news, items = reader.collect_and_format_news(storage, parsed_arg)
     with StringIO() as buf, redirect_stdout(buf):
         reader.selection_from_db(parsed_arg.date)
         reader.print_news(parsed_arg.json, parsed_arg.colorize, news)
         load = loads(buf.getvalue())
         self.assertEqual(len(load), res)
Example #2
0
 def test_no_news_date(self):
     """Tests --date argument with no news"""
     args = [
         '--date=30210522',
     ]
     parsed_arg = self.arg_parser.parse_args(args)
     with self.assertRaises(SystemExit):
         with StringIO() as buf, redirect_stdout(buf):
             reader.selection_from_db(parsed_arg.date)
             self.assertEqual('No news for entered date\n', buf.getvalue())
Example #3
0
 def test_news_limit(self, args, res):
     """Tests --date with limit"""
     parsed_arg = self.arg_parser.parse_args(args)
     storage = reader.selection_from_db(parsed_arg.date)
     news, items = reader.collect_and_format_news(storage, parsed_arg)
     with StringIO() as buf, redirect_stdout(buf):
         reader.selection_from_db(parsed_arg.date)
         reader.print_news(parsed_arg.json, parsed_arg.colorize, news)
         result_news_dates_and_links = findall('Date: .+\nLink: .+\n',
                                               buf.getvalue())
         self.assertEqual(len(result_news_dates_and_links), res)
Example #4
0
 def test_invalid_date(self):
     """Tests --date argument with invalid value"""
     args = [
         '--date=20212222',
     ]
     parsed_arg = self.arg_parser.parse_args(args)
     with self.assertRaises(SystemExit):
         with StringIO() as buf, redirect_stdout(buf):
             reader.selection_from_db(parsed_arg.date)
             self.assertEqual(
                 'Invalid date. Please correct the date and try again\n',
                 buf.getvalue())
Example #5
0
 def test_json_news(self):
     """Tests --date with --json printing"""
     args = [
         '--date=20210530',
         '--json',
     ]
     parsed_arg = self.arg_parser.parse_args(args)
     storage = reader.selection_from_db(parsed_arg.date)
     news, items = reader.collect_and_format_news(storage, parsed_arg)
     with StringIO() as buf, redirect_stdout(buf):
         reader.selection_from_db(parsed_arg.date)
         reader.print_news(parsed_arg.json, parsed_arg.colorize, news)
         loads(buf.getvalue())