예제 #1
0
    def test_check_if_file_exists_returns_false_path_is_none(
            self, mock_exists, mock_isfile):
        """ Test a valid invocation of API check_if_file_exists """

        # arrange
        file_path = None

        # act
        result = EdgeUtils.check_if_file_exists(file_path)

        # assert
        mock_exists.assert_not_called()
        mock_isfile.assert_not_called()
        self.assertFalse(result)
예제 #2
0
    def test_check_if_file_exists_returns_true(self, mock_exists, mock_isfile):
        """ Test a valid invocation of API check_if_file_exists """
        # arrange #1
        file_path = 'blah'
        mock_exists.return_value = True
        mock_isfile.return_value = True

        # act
        result = EdgeUtils.check_if_file_exists(file_path)

        # assert
        mock_exists.assert_called_with(file_path)
        mock_isfile.assert_called_with(file_path)
        self.assertTrue(result)
예제 #3
0
    def _set_dca_file(self, kwargs, file_key):
        """Helper method to store one of the many device CA certificate and
           private key files required to operate the Edge as a gateway.

        Args:
            kwargs (dict): User supplied KW args
            file_key (str): Key to retrieve and store the file

        Raises:
            ValueError if retrieved file path is None or if the file does not exist.
        """
        file_path = kwargs[file_key]
        if EdgeUtils.check_if_file_exists(file_path):
            self._dca_files_dict[file_key] = file_path
        else:
            raise ValueError('Invalid {0} file: {1}'.format(
                file_key, file_path))