Пример #1
0
def should_support_in_operator():
    storage = Storage('name', 'namespace')
    step = storage['some step']
    assert 'some step' in storage

    # ensure it works across restore
    restored = Storage('name', 'namespace')
    restored.decode(storage.encode())
    assert 'some step' in restored
Пример #2
0
def should_support_in_operator():
    storage = Storage('name', 'namespace')
    step = storage['some step']
    assert 'some step' in storage

    # ensure it works across restore
    restored = Storage('name', 'namespace')
    restored.decode(storage.encode())
    assert 'some step' in restored
Пример #3
0
def should_encode_and_decode_properly(temp):
    file_storage = FileSystemStorage(location=temp)

    storage = Storage('name', 'namespace', file_storage)
    assert storage.encode() == {'current_step': None, 'steps': {}}
    restored = Storage('name', 'namespace', file_storage)
    restored.decode(storage.encode())
    assert storage.encode() == restored.encode()

    storage.current_step = storage['step1']
    restored.decode(storage.encode())
    assert storage.encode() == restored.encode()

    storage.steps = {'step1': storage['step1']}
    restored.decode(storage.encode())
    assert storage.encode() == restored.encode()

    step = storage['step1']
    step.data = {}
    assert storage.encode() == {
        'current_step': 'step1',
        'steps': {
            'step1': {
                'files': None,
                'data': {},
            },
        }
    }
    restored.decode(storage.encode())
    assert storage.encode() == restored.encode()

    with open(__file__, 'rb') as handle:
        expected = handle.read()

    step = storage['step1']
    step.files = {'file1': InMemoryUploadedFile(file=open(__file__, 'rb'),
                                                field_name="file1",
                                                name="filename",
                                                content_type="text/plain",
                                                size=len(expected),
                                                charset="utf-8")}

    restored.decode(storage.encode())
    restored_step = restored['step1']
    actual = restored_step.files['file1'].read()
    assert actual == expected
Пример #4
0
def should_encode_and_decode_properly(temp):
    file_storage = FileSystemStorage(location=temp)

    storage = Storage('name', 'namespace', file_storage)
    assert storage.encode() == {'current_step': None, 'steps': {}}
    restored = Storage('name', 'namespace', file_storage)
    restored.decode(storage.encode())
    assert storage.encode() == restored.encode()

    storage.current_step = storage['step1']
    restored.decode(storage.encode())
    assert storage.encode() == restored.encode()

    storage.steps = {'step1': storage['step1']}
    restored.decode(storage.encode())
    assert storage.encode() == restored.encode()

    step = storage['step1']
    step.data = {}
    assert storage.encode() == {
        'current_step': 'step1',
        'steps': {
            'step1': {
                'files': None,
                'data': {},
            },
        }
    }
    restored.decode(storage.encode())
    assert storage.encode() == restored.encode()

    with open(__file__, 'rb') as handle:
        expected = handle.read()

    step = storage['step1']
    step.files = {
        'file1':
        InMemoryUploadedFile(file=open(__file__, 'rb'),
                             field_name="file1",
                             name="filename",
                             content_type="text/plain",
                             size=len(expected),
                             charset="utf-8")
    }

    restored.decode(storage.encode())
    restored_step = restored['step1']
    actual = restored_step.files['file1'].read()
    assert actual == expected