Exemplo n.º 1
0
 def test_write_changes_declaration_when_write_changes_is_true(
         self, mock_login):
     bot = AbstractBotJob(write_changes=True)
     bot.logger.info = Mock()
     bot.write_changes_declaration()
     bot.logger.info.assert_called_with(
         'write_changes is TRUE. Permanent modifications may be made.'
     )  # TODO
Exemplo n.º 2
0
 def test_write_changes_declaration_when_write_changes_is_false(
         self, mock_login):
     bot = AbstractBotJob(write_changes=False)
     bot.logger.info = Mock()
     bot.write_changes_declaration()
     bot.logger.info.assert_called_with(
         'write_changes is FALSE. No external modifications will be made.'
     )  # TODO
 def test_save_when_dry_run_is_false(self, mock_login, mock_sys_exit):
     save_fn = Mock()
     bot = AbstractBotJob(dry_run=False)
     bot.logger.info = Mock()
     old_changed = copy.deepcopy(bot.changed)
     bot.save(save_fn)
     assert save_fn.assert_called_once
     assert bot.logger.info.assert_called_once
     assert mock_sys_exit.assert_called_once
     assert bot.changed == old_changed + 1
     assert not bot.changed > bot.limit
Exemplo n.º 4
0
 def test_save_when_dry_run_is_true(self, mock_sys_exit):
     save_fn = Mock()
     bot = AbstractBotJob(ol=self.ol, dry_run=True)
     bot.logger.info = Mock()
     old_changed = copy.deepcopy(bot.changed)
     bot.save(save_fn)
     assert save_fn.assert_not_called
     assert bot.logger.info.call_count == 2
     assert mock_sys_exit.assert_called_once
     assert bot.changed == old_changed + 1
     assert not bot.changed > bot.limit
Exemplo n.º 5
0
 def test_save_when_write_changes_is_false(self, mock_login, mock_sys_exit):
     save_fn = Mock()
     bot = AbstractBotJob(write_changes=False)
     bot.logger.info = Mock()
     old_changed = copy.deepcopy(bot.changed)
     bot.save(save_fn)
     assert save_fn.assert_not_called
     assert bot.logger.info.call_count == 2
     assert mock_sys_exit.assert_called_once
     assert bot.changed == old_changed + 1
     assert not bot.changed > bot.limit
Exemplo n.º 6
0
 def test_save_exits_when_limit_reached(self, mock_login, mock_sys_exit):
     save_fn = Mock()
     bot = AbstractBotJob(write_changes=False, limit=10)
     bot.logger.info = Mock()
     for i in range(
             bot.limit
     ):  # simulate calling save_fn many times in a run() method
         if mock_sys_exit.call_count > 1:
             break
         bot.save(save_fn)
     assert mock_sys_exit.assert_called_once
     assert save_fn.assert_not_called
     assert bot.changed == bot.limit
     assert bot.logger.info.call_count == bot.limit + 1
Exemplo n.º 7
0
 def test_process_row_with_string(self):
     random_data = list()
     for i in range(4):
         random_data.append(string.ascii_letters[random.randint(
             0,
             len(string.ascii_letters) - 1)])
     random_data = '\t'.join([
         random_data[0], random_data[1], random_data[2], random_data[3],
         '{"foo": "bar" }'
     ])
     job = AbstractBotJob()
     returned_row, returned_json_data = job.process_row(random_data)
     assert isinstance(returned_row, list)
     assert isinstance(returned_json_data, dict)
Exemplo n.º 8
0
 def test__init__(self):
     bot = AbstractBotJob()
     assert bot.changed == 0
     assert bot.limit == 1
     assert bot.dry_run is True
     assert bot.logger.handlers
     assert getattr(bot, 'console_handler', None) is not None
     assert isinstance(bot.ol, OpenLibrary)
Exemplo n.º 9
0
 def test__init__(self, mock_login):
     bot = AbstractBotJob()
     assert bot.changed == 0
     assert bot.limit == 1
     assert bot.write_changes is False
     assert bot.logger.handlers
     assert getattr(bot, 'console_handler', None) is not None
     assert isinstance(bot.ol, OpenLibrary)
Exemplo n.º 10
0
 def test_save_exits_when_limit_reached(self, mock_sys_exit):
     save_fn = Mock()
     bot = AbstractBotJob(ol=self.ol,
                          dry_run=True,
                          limit=random.randint(2, 20))
     bot.logger.info = Mock()
     old_changed = copy.deepcopy(bot.changed)
     for i in range(
             bot.limit +
             1):  # simulate calling save_fn many times in a run() method
         if mock_sys_exit.call_count > 0: break
         bot.save(save_fn)
     assert mock_sys_exit.assert_called_once
     assert save_fn.assert_not_called
     assert bot.logger.info.call_count == bot.limit + 1
     assert bot.changed == old_changed + bot.limit
     assert not bot.changed > bot.limit
Exemplo n.º 11
0
 def test__str2bool_errors_for_non_boolean_input(self, mock_login):
     bot = AbstractBotJob()
     self.assertRaises(ArgumentTypeError, bot._str2bool,
                       'this is a non-boolean string')
Exemplo n.º 12
0
 def test__str2bool_returns_false_for_falsey_input(self, mock_login):
     falsey_input = random.choice(self.falsey_values)
     bot = AbstractBotJob()
     assert bot._str2bool(falsey_input) is False
Exemplo n.º 13
0
 def test__str2bool_returns_true_for_truthy_input(self, mock_login):
     truthy_input = random.choice(self.truthy_values)
     bot = AbstractBotJob()
     assert bot._str2bool(truthy_input)
Exemplo n.º 14
0
 def test_setup_logger(self, mock_login):
     job_name = __name__
     logger, console_handler = AbstractBotJob.setup_logger(job_name)
     assert isinstance(logger, logging.Logger)
     assert isinstance(console_handler, logging.StreamHandler)
Exemplo n.º 15
0
 def test_dry_run_declaration_when_dry_run_is_false(self):
     bot = AbstractBotJob(dry_run=False)
     bot.logger.info = Mock()
     bot.dry_run_declaration()
     bot.logger.info.assert_called_with(
         'dry-run is FALSE. Permanent modifications can be made.')  # TODO
Exemplo n.º 16
0
 def test_dry_run_declaration_when_dry_run_is_true(self):
     bot = AbstractBotJob(dry_run=True)
     bot.logger.info = Mock()
     bot.dry_run_declaration()
     bot.logger.info.assert_called_with(
         'dry-run is TRUE. No external modifications will be made.')  # TODO
Exemplo n.º 17
0
 def test__str2bool_errors_for_non_boolean_input(self):
     non_boolean_input = random.choice(string.ascii_letters)
     while non_boolean_input in (self.falsey_values + self.truthy_values):
         non_boolean_input = random.choice(string.ascii_letters)
     bot = AbstractBotJob(ol=self.ol)
     self.assertRaises(ArgumentTypeError, bot._str2bool, non_boolean_input)