Exemplo n.º 1
0
    def test_invalid_directory_status(self, mock_parsing_handler,
                                      mock_api_handler,
                                      mock_validate_and_upload,
                                      mock_upload_helpers):
        """
        Checks that function exits when directory status is invalid
        :return:
        """

        stub_directory_status = self.StubDirectoryStatus()
        stub_directory_status._status = DirectoryStatus.INVALID

        mock_parsing_handler.get_run_status.side_effect = [
            stub_directory_status
        ]
        mock_upload_helpers.directory_has_readonly_conflict.side_effect = [
            False
        ]

        result = upload.upload_run_single_entry(
            stub_directory_status.directory)

        # verify result
        self.assertEqual(result.exit_code, exit_return.EXIT_CODE_ERROR)

        # verify calls occurred
        mock_parsing_handler.get_run_status.assert_called_with(
            stub_directory_status.directory)

        # ensure upload did not occur
        mock_validate_and_upload.assert_not_called()
Exemplo n.º 2
0
    def test_directory_not_writable_no_readonly_status(
            self, mock_parsing_handler, mock_api_handler,
            mock_validate_and_upload, mock_upload_helpers):
        """
        Checks that function exits with success when directory status is delayed and there is still delay time
        :return:
        """

        stub_directory_status = self.StubDirectoryStatus()
        stub_directory_status._status = DirectoryStatus.DELAYED

        mock_parsing_handler.get_run_status.side_effect = [
            stub_directory_status
        ]
        mock_upload_helpers.directory_has_readonly_conflict.side_effect = [
            True
        ]

        result = upload.upload_run_single_entry(
            stub_directory_status.directory)

        # verify result
        self.assertEqual(result.exit_code, exit_return.EXIT_CODE_ERROR)

        # verify calls occurred
        mock_parsing_handler.get_run_status.assert_called_with(
            stub_directory_status.directory)
        mock_upload_helpers.directory_has_readonly_conflict.assert_called_with(
            stub_directory_status.directory)

        # ensure upload did not occur
        mock_validate_and_upload.assert_not_called()
Exemplo n.º 3
0
    def test_new_directory_status(self, mock_parsing_handler, mock_api_handler,
                                  mock_validate_and_upload,
                                  mock_upload_helpers):
        """
        Checks that function continues when directory status is new
        :return:
        """

        stub_directory_status = self.StubDirectoryStatus()
        stub_directory_status._status = DirectoryStatus.NEW

        mock_parsing_handler.get_run_status.side_effect = [
            stub_directory_status
        ]
        mock_api_handler.get_default_upload_mode.side_effect = ["mock_mode"]
        mock_validate_and_upload.side_effect = ["mock_result"]
        mock_upload_helpers.directory_has_readonly_conflict.side_effect = [
            False
        ]

        result = upload.upload_run_single_entry(
            stub_directory_status.directory)

        # verify result
        self.assertEqual(result, "mock_result")

        # verify calls occurred
        mock_parsing_handler.get_run_status.assert_called_with(
            stub_directory_status.directory)

        # ensure upload occurs
        mock_validate_and_upload.assert_called_with(stub_directory_status,
                                                    "mock_mode", False)
Exemplo n.º 4
0
    def run(self):
        """
        This runs when the threads start call is done

        When uploading, the default is to upload with force_upload=True,
          when continuing a partial upload, force_upload=False instead
          s.t. we ignore delay logic and simplify earlier run parse logic
        :return:
        """

        force_upload = not self._partial_continue
        self._exit_return = upload.upload_run_single_entry(
            directory=self._run_dir,
            force_upload=force_upload,
            upload_mode=self._upload_mode,
            continue_upload=self._partial_continue)
        pass
Exemplo n.º 5
0
    def test_delay_time_has_passed_directory_status(self, mock_parsing_handler,
                                                    mock_api_handler,
                                                    mock_validate_and_upload,
                                                    mock_upload_helpers):
        """
        Checks that function exits with success when directory status is delayed and the delay has passed
        :return:
        """
        # set a delay for 0 as time has passed
        config.set_config_options(delay=0)

        stub_directory_status = self.StubDirectoryStatus()
        stub_directory_status._status = DirectoryStatus.DELAYED

        mock_parsing_handler.get_run_status.side_effect = [
            stub_directory_status
        ]
        mock_api_handler.get_default_upload_mode.side_effect = ["mock_mode"]
        mock_validate_and_upload.side_effect = ["mock_result"]
        mock_upload_helpers.directory_has_readonly_conflict.side_effect = [
            False
        ]

        result = upload.upload_run_single_entry(
            stub_directory_status.directory)

        # verify result
        self.assertEqual(result, "mock_result")

        # verify calls occurred
        mock_parsing_handler.get_run_status.assert_called_with(
            stub_directory_status.directory)

        # ensure upload occurs
        mock_validate_and_upload.assert_called_with(stub_directory_status,
                                                    "mock_mode", False)
Exemplo n.º 6
0
    def test_new_with_delay_config_directory_status(self, mock_parsing_handler,
                                                    mock_api_handler,
                                                    mock_validate_and_upload,
                                                    mock_upload_helpers,
                                                    mock_set_run_delayed):
        """
        Checks that function exits with success when directory status is new and there is a delay set
        :return:
        """
        # set a delay
        config.set_config_options(delay=1)

        stub_directory_status = self.StubDirectoryStatus()
        stub_directory_status._status = DirectoryStatus.NEW

        mock_parsing_handler.get_run_status.side_effect = [
            stub_directory_status
        ]
        mock_set_run_delayed.side_effect = [None]
        mock_upload_helpers.directory_has_readonly_conflict.side_effect = [
            False
        ]

        result = upload.upload_run_single_entry(
            stub_directory_status.directory)

        # verify result
        self.assertEqual(result.exit_code, exit_return.EXIT_CODE_SUCCESS)

        # verify calls occurred
        mock_parsing_handler.get_run_status.assert_called_with(
            stub_directory_status.directory)
        mock_set_run_delayed.assert_called_with(stub_directory_status)

        # ensure upload did not occur
        mock_validate_and_upload.assert_not_called()