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)
 def test_success_true(self):
     """
     If all shove instances executed the command successfully,
     return True.
     """
     command = SentCommandFactory.create()
     CommandLogFactory.create_batch(2, sent_command=command, return_code=0)
     assert_true(command.success)
 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)
Beispiel #4
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)
Beispiel #5
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')
Beispiel #6
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')
    def test_get_context_data(self):
        sent_command = SentCommandFactory.create()
        log1, log2 = CommandLogFactory.create_batch(2, sent_command=sent_command)

        view = views.SentCommandDetails()
        view.kwargs = {'project_id': sent_command.project.id}
        view.object = sent_command  # Required for get_context_data.

        ctx = view.get_context_data()
        assert_equal(ctx['project'], sent_command.project)
        assert_equal(list(ctx['logs']), [log1, log2])