Пример #1
0
    def test_generate_plan_no_persist_include(self,
                                              mock_stack_action: PropertyMock,
                                              mock_tags: PropertyMock) -> None:
        """Test generate plan no persist include."""
        mock_stack_action.return_value = MagicMock()
        mock_tags.return_value = {}
        context = mock_context(
            namespace="test",
            extra_config_args=self.config_no_persist,
            region=self.region,
        )
        action = BaseAction(
            context=context,
            provider_builder=MockProviderBuilder(provider=self.provider,
                                                 region=self.region),
        )

        plan = action._generate_plan(include_persistent_graph=True)

        mock_tags.assert_not_called()
        self.assertIsInstance(plan, Plan)
        # order is different between python2/3 so can't compare dicts
        result_graph_dict = plan.graph.to_dict()
        self.assertEqual(2, len(result_graph_dict))
        self.assertEqual(set(), result_graph_dict["stack1"])
        self.assertEqual(set(["stack1"]), result_graph_dict["stack2"])
        self.assertEqual(BaseAction.DESCRIPTION, plan.description)
        self.assertTrue(plan.require_unlocked)
Пример #2
0
    def test__disable_events__specific_names(self, mock_events):
        """Test disabling specific events."""
        mock_event1 = MagicMock(spec=HoudiniEvent)

        mock_enabled1 = PropertyMock(return_value=True)
        type(mock_event1).enabled = mock_enabled1

        mock_event2 = MagicMock(spec=HoudiniEvent)

        mock_enabled2 = PropertyMock(return_value=True)
        type(mock_event2).enabled = mock_enabled2

        mock_events.return_value = {
            mock_event1.name: mock_event1,
            mock_event2.name: mock_event2,
        }

        manager = ht.events.manager.HoudiniEventManager()
        manager._event_states = {}

        manager._disable_events(names=[mock_event2.name])

        # Event 1's enabled property should not have been accessed.
        mock_enabled1.assert_not_called()

        # Event 2's should have been accessed to get the current value
        # and once to disable it.
        mock_enabled2.assert_has_calls([call(), call(False)])

        self.assertTrue(manager._event_states[mock_event2.name])
        self.assertEqual(len(manager._event_states), 1)
Пример #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

    @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()
Пример #4
0
    def test__disable_events__specific_names(self, mock_events):
        """Test disabling specific events."""
        mock_event1 = MagicMock(spec=HoudiniEvent)

        mock_enabled1 = PropertyMock(return_value=True)
        type(mock_event1).enabled = mock_enabled1

        mock_event2 = MagicMock(spec=HoudiniEvent)

        mock_enabled2 = PropertyMock(return_value=True)
        type(mock_event2).enabled = mock_enabled2

        mock_events.return_value = {
            mock_event1.name: mock_event1,
            mock_event2.name: mock_event2,
        }

        manager = ht.events.manager.HoudiniEventManager()
        manager._event_states = {}

        manager._disable_events(names=[mock_event2.name])

        # Event 1's enabled property should not have been accessed.
        mock_enabled1.assert_not_called()

        # Event 2's should have been accessed to get the current value
        # and once to disable it.
        mock_enabled2.assert_has_calls([call(), call(False)])

        self.assertTrue(manager._event_states[mock_event2.name])
        self.assertEqual(len(manager._event_states), 1)
Пример #5
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])
Пример #6
0
 def test_download_results_expired_url(self, get_mock):
     requests_result_mock = Mock()
     status_code_mock = PropertyMock(return_value=404)
     type(requests_result_mock).status_code = status_code_mock
     content_mock = PropertyMock(return_value=bytes())
     type(requests_result_mock).content = content_mock
     get_mock.return_value = requests_result_mock
     results = self.plugin._download_results(RESULT_DICT)
     status_code_mock.assert_called_once()
     content_mock.assert_not_called()
     self.assertEqual(self.plugin.tradefed_results_url, RESULT_URL)
     self.assertIsNone(results.test_results)
     self.assertIsNone(results.tradefed_stdout)
     self.assertIsNone(results.tradefed_logcat)
Пример #7
0
    def test_only_test_class_gets_set_if_not_test_identifier(
            self, mock_metric, get_context):
        result = Mock()
        test_method = PropertyMock()
        test_class = PropertyMock()
        type(result).test_method = test_method
        type(result).test_class = test_class
        mock_metric.return_value = result
        logger = BoundedMetricsLogger(event=self.event)
        logger.context = self.context
        logger.publisher = self.publisher
        logger.context.identifier = 'BestClass'

        logger.add('limitless_metric', 123, unit='skies')

        test_class.assert_called_with('BestClass')
        test_method.assert_not_called()
Пример #8
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()