def test_write_package_version_file_backs_up_original_file_before_writing(self):
        parent_mock = MagicMock()  # create a parent mock so we can assert on the order of child mock calls.
        parent_mock.attach_mock(self.patch('app.util.autoversioning.os'), 'os')
        parent_mock.attach_mock(self.patch('app.util.autoversioning.fs'), 'fs')

        autoversioning.write_package_version_file(package_version_string='1.2.3')

        expected_rename_call = call.os.rename(AnythingOfType(str), AnythingOfType(str))
        expected_write_file_call = call.fs.write_file(AnythingOfType(str), AnythingOfType(str))
        self.assertLess(parent_mock.method_calls.index(expected_rename_call),
                        parent_mock.method_calls.index(expected_write_file_call),
                        'write_package_version_file() should rename the original file before writing the new file.')
Пример #2
0
    def test_start_app_force_kill_countdown_is_called_when_app_exits_normally(
            self):
        self.patch('main.MasterSubcommand'
                   )  # causes subcommand run() method to return immediately

        main.main(['master'])

        self.start_force_kill_countdown_mock.assert_called_once_with(
            seconds=AnythingOfType(int))
Пример #3
0
    def test_start_subjob_makes_correct_call_to_slave(self):
        slave = self._create_slave(slave_url='splinter.sensei.net:43001')
        subjob = self._create_test_subjob(build_id=911, subjob_id=187)

        slave.start_subjob(subjob)

        expected_start_subjob_url = 'http://splinter.sensei.net:43001/v1/build/911/subjob/187'
        (url, post_body, _), _ = self.mock_network.post_with_digest.call_args
        self.assertEqual(url, expected_start_subjob_url,
                         'A correct POST call should be sent to slave to start a subjob.')
        self.assertEqual(post_body, {'atomic_commands': AnythingOfType(list)},
                         'Call to start subjob should contain list of atomic_commands for this subjob.')
Пример #4
0
    def test_start_app_force_kill_countdown_is_called_when_app_exits_via_unhandled_exception(
            self):
        run_mock = self.patch('main.MasterSubcommand').return_value.run
        run_mock.side_effect = Exception(
            'I am here to trigger teardown handlers!')

        with self.assertRaises(
                SystemExit,
                msg=
                'UnhandledExceptionHandler should convert Exception to SystemExit.'
        ):
            main.main(['master'])

        self.start_force_kill_countdown_mock.assert_called_once_with(
            seconds=AnythingOfType(int))