Пример #1
0
 def test_postprocess_testjob_save_attachments(
     self,
     results_url_mock,
     get_from_artifactorial_mock,
     assign_test_log_mock,
     create_testrun_attachment_mock,
 ):
     results_url_mock.return_value = "http://foo.com"
     result_files = ResultFiles()
     result_files.test_results = ExtractedResult()
     result_files.test_results.contents = "abc"
     result_files.test_results.length = 3
     get_from_artifactorial_mock.return_value = result_files
     testjob_mock = MagicMock()
     id_mock = PropertyMock(return_value="999111")
     type(testjob_mock).pk = id_mock
     job_id_mock = PropertyMock(return_value="1234")
     type(testjob_mock).job_id = job_id_mock
     testjob_mock.backend = MagicMock()
     implementation_type_mock = PropertyMock(return_value="lava")
     type(testjob_mock.backend).implementation_type = implementation_type_mock
     definition_mock = PropertyMock(return_value=JOB_DEFINITION)
     type(testjob_mock).definition = definition_mock
     self.plugin.postprocess_testjob(testjob_mock)
     implementation_type_mock.assert_called_once()
     definition_mock.assert_called()
     results_url_mock.assert_called()
     testjob_mock.testrun.metadata.__setitem__.assert_called()
     testjob_mock.testrun.save.assert_called()
     assign_test_log_mock.assert_called()
     create_testrun_attachment_mock.assert_called()
Пример #2
0
class LiveSyncMiddlewareTestCase(TestCase):
    def setUp(self):
        self.mocked_response = Mock()
        self.get_response = Mock(return_value=self.mocked_response)
        self.middleware = DjangoLiveSyncMiddleware(self.get_response)
        self.mock_content_property = PropertyMock(return_value=b"<body></body>")
        type(self.mocked_response).content = self.mock_content_property

    @patch('livesync.core.middleware.settings.DEBUG', True)
    def test_middleware_injects_js_file_correctly(self):
        self.mocked_response.__getitem__ = Mock(return_value='text/html')
        # act
        self.middleware(Mock())
        # assert

        self.mock_content_property.assert_called()
        self.assertTrue(b"<script src='/static/livesync.js'></script>" in self.mock_content_property.call_args[0][0])

    @patch('livesync.core.middleware.settings.DEBUG', True)
    @patch('django.conf.settings.DEBUG', True)
    def test_middleware_does_not_inject_js_file_if_content_type_is_not_html(self):
        self.mocked_response.__getitem__ = Mock(return_value='json')
        # act
        self.middleware(Mock())
        # assert
        self.mock_content_property.assert_not_called()

    @patch('livesync.core.middleware.settings.DEBUG', False)
    def test_middleware_does_not_inject_js_file_if_not_debugging(self):
        self.mocked_response.__getitem__ = Mock(return_value='text/html')
        # act
        self.middleware(Mock())
        # assert
        self.mock_content_property.assert_not_called()
Пример #3
0
class LiveSyncMiddlewareTestCase(TestCase):
    def setUp(self):
        self.mocked_response = Mock()
        self.get_response = Mock(return_value=self.mocked_response)
        self.middleware = DjangoLiveSyncMiddleware(self.get_response)
        self.mock_content_property = PropertyMock(
            return_value=b"<body></body>")
        type(self.mocked_response).content = self.mock_content_property

    @override_settings(DEBUG=True)
    def test_middleware_injects_js_file_correctly(self):
        self.mocked_response.__getitem__ = Mock(return_value='text/html')
        # act
        self.middleware(Mock())
        # assert

        self.mock_content_property.assert_called()
        self.assertTrue(b"<script src='/static/livesync.js'></script>" in
                        self.mock_content_property.call_args[0][0])

    @override_settings(DEBUG=True)
    def test_middleware_does_not_inject_js_file_if_content_type_is_not_html(
            self):
        self.mocked_response.__getitem__ = Mock(return_value='json')
        # act
        self.middleware(Mock())
        # assert
        self.mock_content_property.assert_not_called()

    @override_settings(DEBUG=False)
    def test_middleware_does_not_inject_js_file_if_not_debugging(self):
        self.mocked_response.__getitem__ = Mock(return_value='text/html')
        # act
        self.middleware(Mock())
        # assert
        self.mock_content_property.assert_not_called()

    @override_settings(DEBUG=True)
    @patch('django.template.loader.get_template')
    def test_middleware_custom_snippet_injektion(self, mock_template):
        self.mocked_response.__getitem__ = Mock(return_value='text/html')

        mock_template.return_value = Template('mocked_snippet')
        # act
        self.middleware(Mock())
        # assert

        self.mock_content_property.assert_called()
        self.assertTrue(
            b"mocked_snippet" in self.mock_content_property.call_args[0][0])
Пример #4
0
 def test_enter_with_url(self, requestsPatch):
     """Ensure requests and response.content gets called"""
     TEST_URL = "http://test.com"
     getMethod = MagicMock()
     getMethodReturnValue = Mock()
     getMethod.return_value = getMethodReturnValue
     contentPropertyMock = PropertyMock()
     type(getMethodReturnValue).content = contentPropertyMock
     requestsPatch.get = getMethod
     with XmlFeed(TEST_URL) as feed:
         self.assertTrue(feed.is_url)
         self.assertFalse(feed.is_file)
         pass
     getMethod.assert_called_with(TEST_URL)
     contentPropertyMock.assert_called()
Пример #5
0
 def test_get_from_artifactorial_empty_results(self, download_results_mock):
     suite_name = "2_bar"
     download_results_mock.return_value = ResultFiles()
     testjob_mock = Mock()
     testjob_mock.backend.get_implementation().proxy.results.get_testjob_suites_list_yaml.return_value = (
         SUITES
     )
     testjob_mock.backend.get_implementation().proxy.results.get_testsuite_results_yaml.return_value = (
         "[]"
     )
     job_id_mock = PropertyMock(return_value=999)
     type(testjob_mock).job_id = job_id_mock
     result = self.plugin._get_from_artifactorial(testjob_mock, suite_name)
     job_id_mock.assert_called()
     testjob_mock.backend.get_implementation().proxy.results.get_testjob_suites_list_yaml.assert_called_once()
     testjob_mock.backend.get_implementation().proxy.results.get_testsuite_results_yaml.assert_called()
     self.assertIsNone(result)
Пример #6
0
    def test_postprocess_testrun(self):
        test_1 = Mock()
        test_1_name = PropertyMock(return_value="test_1")
        type(test_1).name = test_1_name
        test_1_log = PropertyMock()
        type(test_1).log = test_1_log

        test_2 = Mock()
        test_2_name = PropertyMock(return_value="test_2")
        type(test_2).name = test_2_name
        test_2_log = PropertyMock()
        type(test_2).log = test_2_log

        test_3 = Mock()
        test_3_name = PropertyMock(return_value="test_3")
        type(test_3).name = test_3_name
        test_3_log = PropertyMock()
        type(test_3).log = test_3_log

        testrun = Mock()
        testrun_log = PropertyMock(return_value=TEST_LOG)
        type(testrun).log_file = testrun_log

        testrun.tests = Mock()
        testrun.tests.filter.return_value = [test_1, test_2, test_3]

        self.plugin.postprocess_testrun(testrun)
        testrun.tests.filter.assert_called()
        testrun_log.assert_called()

        test_1_name.assert_called()
        test_1_log.assert_called()
        test_1.save.assert_called()

        # test_2 not present in the log
        test_2_name.assert_called()
        test_2_log.assert_not_called()
        test_2.save.assert_not_called()

        test_3_name.assert_called()
        test_3_log.assert_called()
        test_3.save.assert_called()