Example #1
0
def test_file_exists(storage: object):
    assert isinstance(storage, storages.LocalStorage)

    # prepare
    file_path = storage.base_path / TEST_TOUCH_FILE_NAME
    (exitcode, _) = subprocess.getstatusoutput(f'touch {file_path}')
    assert exitcode == 0
    assert file_path.is_file()

    # test
    assert info.file_exists(storage, file_name=TEST_TOUCH_FILE_NAME)
    assert not info.file_exists(storage,
                                file_name=TEST_FILE_NOT_EXISTS_FILE_NAME)
Example #2
0
def test_delete_file_command(storage: object):
    command = shell.write_file_command(storage,
                                       file_name=TEST_DELETE_FILE_NAME)
    assert command

    (exitcode,
     _) = subprocess.getstatusoutput(f'echo "{TEST_CONTENT}" | {command}')
    assert exitcode == 0
    assert info.file_exists(storage, file_name=TEST_DELETE_FILE_NAME)

    command = shell.delete_file_command(storage,
                                        file_name=TEST_DELETE_FILE_NAME)
    assert command

    (exitcode, _) = subprocess.getstatusoutput(command)
    assert exitcode == 0
    assert not info.file_exists(storage, file_name=TEST_DELETE_FILE_NAME)
Example #3
0
def test_read_file_command(storage: object):
    command = shell.write_file_command(storage, file_name=TEST_READ_FILE_NAME)
    assert command

    (exitcode,
     _) = subprocess.getstatusoutput(f'echo "{TEST_CONTENT}" | {command}')
    assert exitcode == 0
    assert info.file_exists(storage, file_name=TEST_READ_FILE_NAME)

    command = shell.read_file_command(storage, file_name=TEST_READ_FILE_NAME)
    assert command

    (exitcode, stdout) = subprocess.getstatusoutput(command)
    assert exitcode == 0
    assert stdout == TEST_CONTENT
def test_last_modification_date(storage: object):
    assert isinstance(storage, storages.GoogleCloudStorage)

    # prepare
    command = f'echo "" | {shell.write_file_command(storage, file_name=TEST_TOUCH_FILE_NAME)}'
    (exitcode, _) = subprocess.getstatusoutput(command)
    assert exitcode == 0
    assert info.file_exists(storage, file_name=TEST_TOUCH_FILE_NAME)

    #test
    storage_client = GoogleCloudStorageShellClient(storage)
    assert storage_client

    last_modification_date = storage_client.last_modification_timestamp(TEST_TOUCH_FILE_NAME)

    assert last_modification_date
    assert isinstance(last_modification_date, datetime.datetime)
    assert last_modification_date.tzinfo
    assert (datetime.datetime.now().astimezone() - last_modification_date).total_seconds() <= 10