def test_attach_application_log_does_nothing_wth_no_log_specified(self):
     app_id = self.getUniqueString()
     case_addDetail = Mock()
     launcher = UpstartApplicationLauncher(case_addDetail)
     j = MagicMock(spec=_l.journal.Reader)
     with patch.object(_l.journal, 'Reader', return_value=j):
         launcher._attach_application_log(app_id)
         expected = launcher._get_user_unit_match(app_id)
         j.add_match.assert_called_once_with(_SYSTEMD_USER_UNIT=expected)
         self.assertEqual(0, case_addDetail.call_count)
    def test_attach_application_log_attaches_log(self):
        token = self.getUniqueString()
        case_addDetail = Mock()
        launcher = UpstartApplicationLauncher(case_addDetail)
        app_id = self.getUniqueString()
        j = MagicMock(spec=_l.journal.Reader)
        j.__iter__ = lambda x: iter([token])
        with patch.object(_l.journal, 'Reader', return_value=j):
            launcher._attach_application_log(app_id)

            self.assertEqual(1, case_addDetail.call_count)
            content_name, content_obj = case_addDetail.call_args[0]
            self.assertEqual("Application Log (%s)" % app_id, content_name)
            self.assertThat(content_obj.as_text(), Contains(token))