Beispiel #1
0
def test__create_archive_with_an_export_file(mocker):
    export = Export()
    archive_path = None
    with TemporaryDirectory() as temp_dir, NamedTemporaryFile() as export_file:
        archive_path = export._create_archive(temp_dir, "mock.sd-export", {},
                                              [export_file.name])
        assert archive_path == os.path.join(temp_dir, "mock.sd-export")
        assert os.path.exists(archive_path)  # sanity check

    assert not os.path.exists(archive_path)
Beispiel #2
0
def test__run_printer_preflight_raises_ExportError_if_not_empty_string(mocker):
    """
    Ensure ExportError is raised if _run_disk_test returns anything other than 'USB_CONNECTED'.
    """
    export = Export()
    export._create_archive = mocker.MagicMock(return_value="mock_archive_path")
    export._export_archive = mocker.MagicMock(
        return_value="SOMETHING_OTHER_THAN_EMPTY_STRING")

    with pytest.raises(ExportError):
        export._run_printer_preflight("mock_archive_dir")
Beispiel #3
0
def test__run_usb_test_raises_ExportError_if_not_USB_CONNECTED(mocker):
    '''
    Ensure ExportError is raised if _run_disk_test returns anything other than 'USB_CONNECTED'.
    '''
    export = Export()
    export._create_archive = mocker.MagicMock(return_value='mock_archive_path')
    export._export_archive = mocker.MagicMock(
        return_value='SOMETHING_OTHER_THAN_USB_CONNECTED')

    with pytest.raises(ExportError):
        export._run_usb_test('mock_archive_dir')
Beispiel #4
0
def test__run_disk_test_raises_ExportError_if_not_USB_ENCRYPTED(mocker):
    """
    Ensure ExportError is raised if _run_disk_test returns anything other than 'USB_ENCRYPTED'.
    """
    export = Export()
    export._create_archive = mocker.MagicMock(return_value="mock_archive_path")
    export._export_archive = mocker.MagicMock(
        return_value="SOMETHING_OTHER_THAN_USB_ENCRYPTED")

    with pytest.raises(ExportError):
        export._run_disk_test("mock_archive_dir")
Beispiel #5
0
def test__run_print_raises_ExportError_if_not_empty_string(mocker):
    '''
    Ensure ExportError is raised if _run_print returns anything other than ''.
    '''
    export = Export()
    export._create_archive = mocker.MagicMock(return_value='mock_archive_path')
    export._export_archive = mocker.MagicMock(
        return_value='SOMETHING_OTHER_THAN_EMPTY_STRING')

    with pytest.raises(ExportError):
        export._run_print('mock_archive_dir', ['mock_filepath'])
Beispiel #6
0
def test__create_archive(mocker):
    """
    Ensure _create_archive creates an archive in the supplied directory.
    """
    export = Export()
    archive_path = None
    with TemporaryDirectory() as temp_dir:
        archive_path = export._create_archive(temp_dir, "mock.sd-export", {})
        assert archive_path == os.path.join(temp_dir, "mock.sd-export")
        assert os.path.exists(archive_path)  # sanity check

    assert not os.path.exists(archive_path)
Beispiel #7
0
def test__run_disk_export_raises_ExportError_if_not_empty_string(mocker):
    """
    Ensure ExportError is raised if _run_disk_test returns anything other than ''.
    """
    export = Export()
    export._create_archive = mocker.MagicMock(return_value="mock_archive_path")
    export._export_archive = mocker.MagicMock(
        return_value="SOMETHING_OTHER_THAN_EMPTY_STRING")

    with pytest.raises(ExportError):
        export._run_disk_export("mock_archive_dir", ["mock_filepath"],
                                "mock_passphrase")
Beispiel #8
0
def test__create_archive_with_multiple_export_files(mocker):
    """
    Ensure an archive
    """
    export = Export()
    archive_path = None
    with TemporaryDirectory() as temp_dir, NamedTemporaryFile(
    ) as export_file_one, NamedTemporaryFile() as export_file_two:  # noqa
        archive_path = export._create_archive(
            temp_dir, "mock.sd-export", {},
            [export_file_one.name, export_file_two.name])
        assert archive_path == os.path.join(temp_dir, "mock.sd-export")
        assert os.path.exists(archive_path)  # sanity check

    assert not os.path.exists(archive_path)
Beispiel #9
0
def test__run_printer_preflight(mocker):
    """
    Ensure _export_archive and _create_archive are called with the expected parameters,
    _export_archive is called with the return value of _create_archive, and
    _run_disk_test returns without error if 'USB_CONNECTED' is the return value of _export_archive.
    """
    export = Export()
    export._create_archive = mocker.MagicMock(return_value="mock_archive_path")
    export._export_archive = mocker.MagicMock(return_value="")

    export._run_printer_preflight("mock_archive_dir")

    export._export_archive.assert_called_once_with("mock_archive_path")
    export._create_archive.assert_called_once_with(
        "mock_archive_dir", "printer-preflight.sd-export",
        {"device": "printer-preflight"})
Beispiel #10
0
def test__run_disk_test(mocker):
    """
    Ensure _export_archive and _create_archive are called with the expected parameters,
    _export_archive is called with the return value of _create_archive, and
    _run_disk_test returns without error if 'USB_ENCRYPTED' is the ouput status of _export_archive.
    """
    export = Export()
    export._create_archive = mocker.MagicMock(return_value="mock_archive_path")
    export._export_archive = mocker.MagicMock(return_value="USB_ENCRYPTED")

    export._run_disk_test("mock_archive_dir")

    export._export_archive.assert_called_once_with("mock_archive_path")
    export._create_archive.assert_called_once_with("mock_archive_dir",
                                                   "disk-test.sd-export",
                                                   {"device": "disk-test"})
Beispiel #11
0
def test__run_print(mocker):
    """
    Ensure _export_archive and _create_archive are called with the expected parameters and
    _export_archive is called with the return value of _create_archive.
    """
    export = Export()
    export._create_archive = mocker.MagicMock(return_value="mock_archive_path")
    export._export_archive = mocker.MagicMock(return_value="")

    export._run_print("mock_archive_dir", ["mock_filepath"])

    export._export_archive.assert_called_once_with("mock_archive_path")
    export._create_archive.assert_called_once_with("mock_archive_dir",
                                                   "print_archive.sd-export",
                                                   {"device": "printer"},
                                                   ["mock_filepath"])
Beispiel #12
0
def test__run_printer_preflight(mocker):
    '''
    Ensure _export_archive and _create_archive are called with the expected parameters,
    _export_archive is called with the return value of _create_archive, and
    _run_disk_test returns without error if 'USB_CONNECTED' is the return value of _export_archive.
    '''
    export = Export()
    export._create_archive = mocker.MagicMock(return_value='mock_archive_path')
    export._export_archive = mocker.MagicMock(return_value='')

    export._run_printer_preflight('mock_archive_dir')

    export._export_archive.assert_called_once_with('mock_archive_path')
    export._create_archive.assert_called_once_with(
        'mock_archive_dir', 'printer-preflight.sd-export',
        {'device': 'printer-preflight'})
Beispiel #13
0
def test__run_disk_test(mocker):
    '''
    Ensure _export_archive and _create_archive are called with the expected parameters,
    _export_archive is called with the return value of _create_archive, and
    _run_disk_test returns without error if 'USB_ENCRYPTED' is the ouput status of _export_archive.
    '''
    export = Export()
    export._create_archive = mocker.MagicMock(return_value='mock_archive_path')
    export._export_archive = mocker.MagicMock(return_value='USB_ENCRYPTED')

    export._run_disk_test('mock_archive_dir')

    export._export_archive.assert_called_once_with('mock_archive_path')
    export._create_archive.assert_called_once_with('mock_archive_dir',
                                                   'disk-test.sd-export',
                                                   {'device': 'disk-test'})
Beispiel #14
0
def test__run_print(mocker):
    '''
    Ensure _export_archive and _create_archive are called with the expected parameters and
    _export_archive is called with the return value of _create_archive.
    '''
    export = Export()
    export._create_archive = mocker.MagicMock(return_value='mock_archive_path')
    export._export_archive = mocker.MagicMock(return_value='')

    export._run_print('mock_archive_dir', ['mock_filepath'])

    export._export_archive.assert_called_once_with('mock_archive_path')
    export._create_archive.assert_called_once_with('mock_archive_dir',
                                                   'print_archive.sd-export', {
                                                       'device': 'printer',
                                                   }, ['mock_filepath'])
Beispiel #15
0
def test__run_disk_export(mocker):
    '''
    Ensure _export_archive and _create_archive are called with the expected parameters,
    _export_archive is called with the return value of _create_archive, and
    _run_disk_test returns without error if '' is the ouput status of _export_archive.
    '''
    export = Export()
    export._create_archive = mocker.MagicMock(return_value='mock_archive_path')
    export._export_archive = mocker.MagicMock(return_value='')

    export._run_disk_export('mock_archive_dir', ['mock_filepath'],
                            'mock_passphrase')

    export._export_archive.assert_called_once_with('mock_archive_path')
    export._create_archive.assert_called_once_with(
        'mock_archive_dir', 'archive.sd-export', {
            'encryption_key': 'mock_passphrase',
            'device': 'disk',
            'encryption_method': 'luks'
        }, ['mock_filepath'])
Beispiel #16
0
def test__run_disk_export(mocker):
    """
    Ensure _export_archive and _create_archive are called with the expected parameters,
    _export_archive is called with the return value of _create_archive, and
    _run_disk_test returns without error if '' is the ouput status of _export_archive.
    """
    export = Export()
    export._create_archive = mocker.MagicMock(return_value="mock_archive_path")
    export._export_archive = mocker.MagicMock(return_value="")

    export._run_disk_export("mock_archive_dir", ["mock_filepath"],
                            "mock_passphrase")

    export._export_archive.assert_called_once_with("mock_archive_path")
    export._create_archive.assert_called_once_with(
        "mock_archive_dir",
        "archive.sd-export",
        {
            "encryption_key": "mock_passphrase",
            "device": "disk",
            "encryption_method": "luks"
        },
        ["mock_filepath"],
    )