Ejemplo n.º 1
0
 def test_success_false(self):
     """
     If any shove instance has a nonzero return code return False.
     """
     command = SentCommandFactory.create()
     CommandLogFactory.create(sent_command=command, return_code=0)
     CommandLogFactory.create(sent_command=command, return_code=1)
     assert_false(command.success)
Ejemplo n.º 2
0
 def test_success_none(self):
     """
     If any shove instance hasn't received a return code yet, return
     None.
     """
     command = SentCommandFactory.create()
     CommandLogFactory.create(sent_command=command, return_code=0)
     CommandLogFactory.create(sent_command=command, return_code=None)
     assert_true(command.success is None)
Ejemplo n.º 3
0
    def test_handle_log_found(self, mock_log):
        """If a command log is found, save the given output to the log."""
        command_log = CommandLogFactory.create()
        monitor_shove_logs.handle_log_event(command_log.pk, 6, 'asdf')

        mock_log.assert_called_with('asdf')
        command_log = CommandLog.objects.get(pk=command_log.pk)  # Refresh from DB
        assert_equal(command_log.return_code, 6)
Ejemplo n.º 4
0
    def test_read_logfile(self):
        """The log attribute should return the contents of the logfile."""
        log = CommandLogFactory.create()

        with self.settings(MEDIA_ROOT=self.temporary_media_directory):
            log.logfile.save(None, ContentFile('asdf'))

            log = CommandLog.objects.get(pk=log.pk)
            assert_equal(log.log, 'asdf')
Ejemplo n.º 5
0
    def test_write_logfile(self):
        log = CommandLogFactory.create()

        with self.settings(MEDIA_ROOT=self.temporary_media_directory):
            log.log = 'qwer'
            log.save()

            log = CommandLog.objects.get(pk=log.pk)
            with log.logfile as f:
                assert_equal(f.read(), 'qwer')