Example #1
0
def test_delete(setup_teardown):
    env = 'test'
    args = {
        'action': 'create',
        'card': {
            'title': 'test title',
            'text': 'test text'
        }
    }

    response = run(env, args)
    target_uid = response['card_uid']
    print(target_uid)

    args = {
        'action': 'delete',
        'card': {
            'uid': str(target_uid),
        }
    }

    response = run(env, args)

    assert response['message'] == 'Card deleted'
    assert response['uid'] == str(target_uid)

    assert len(run(env, {'action': "read"})['cards']) == 0
Example #2
0
def test_retrieve_multi_card(setup_teardown):
    env = 'test'

    args = {
        'action': 'create',
        'card': {
            'title': 'test title',
            'text': 'test text'
        }
    }

    response = run(env, args)
    first_uid = response['card_uid']

    args['card']['title'] = '2nd test'
    args['card']['text'] = '2nd test'
    response = run(env, args)
    second_uid = response['card_uid']

    args = {
        'action': 'read',
    }

    read_response = run(env, args)

    assert len(read_response['cards']) == 2
    uids = [c['uid'] for c in read_response['cards']]
    assert first_uid in uids
    assert second_uid in uids
Example #3
0
def test_edit_card(setup_teardown):
    env = 'test'
    args = {
        'action': 'create',
        'card': {
            'title': 'test title',
            'text': 'test text'
        }
    }

    response = run(env, args)
    target_uid = response['card_uid']
    print(target_uid)

    args = {
        'action': 'update',
        'card': {
            'uid': str(target_uid),
            'title': 'updated title',
            'text': 'updated text'
        }
    }

    response = run(env, args)

    assert response['message'] == 'Card updated'
    assert response['new_card']['title'] == 'updated title'
    assert response['new_card']['text'] == 'updated text'
Example #4
0
def create_card(**kwargs) -> str:
    card = {}
    for key, value in kwargs.items():
        card[key] = value
    args = {'action': 'create', 'card': card}
    response = run('test', args)
    return response['card_uid']
Example #5
0
def test_cant_delete_card_with_children(setup_teardown):
    uid = create_card()
    create_card(parent=str(uid))

    response = run('test', {'action': 'delete', 'card': {'uid': str(uid)}})
    print(response)
    expected = 'This card has existing children cards, cannot delete'
    assert response['message'] == expected
Example #6
0
def test_update_card_doesnt_delete_existing_params(setup_teardown):
    uid = create_card(title='test title', text='test text')

    args = {
        'action': 'update',
        'card': {
            'uid': str(uid),
            'text': 'updated text'
        }
    }

    run('test', args)

    card = read_repo()['cards'][0]

    assert card['title'] == 'test title'
    assert card['text'] == 'updated text'
Example #7
0
def main():
    action = True

    while action != 'Exit app':
        all_cards = run('prod', {'action': 'read'})['cards']
        selected, action = get_selection_and_action(all_cards)

        while action not in ['Go back to main', 'Exit app']:
            action, selected = perform_action(action, selected, all_cards)
Example #8
0
def test_delete_of_no_card(setup_teardown):
    uid = '821c9390-845f-4d95-91af-10b654bc6ab9'
    env = 'test'
    args = {'action': 'delete', 'card': {'uid': uid}}

    response = run(env, args)

    expected = f'No card with uid "{uid}" was found in the repo'
    assert response['message'] == expected
Example #9
0
def create_child(selected_pearl):
    inputs_for_create = pi.prompt(CREATE_QS)
    response = run(
        'prod', {
            'action': 'create',
            'card': {
                'title': inputs_for_create['title'],
                'text': inputs_for_create['text'],
                'parent': selected_pearl['uid']
            }
        })
    return response
Example #10
0
def test_retrieve_by_uid(setup_teardown):
    env = 'test'
    args = {
        'action': 'create',
        'card': {
            'title': 'test title',
            'text': 'test text'
        }
    }

    response = run(env, args)
    target_uid = response['card_uid']

    args = {'action': 'create', 'card': {'title': 'not this one'}}

    run(env, args)

    args = {'action': 'read', 'filters': {'uid__eq': str(target_uid)}}

    read_response = run(env, args)

    assert len(read_response['cards']) == 1
Example #11
0
def test_create_and_retrieve_one_card(setup_teardown):
    env = 'test'
    args = {
        'action': 'create',
        'card': {
            'title': 'test title',
            'text': 'test text'
        }
    }

    response = run(env, args)
    expected_uid = response['card_uid']

    args = {
        'action': 'read',
    }

    read_response = run(env, args)

    assert 'cards' in read_response
    assert read_response['cards'][0]['title'] == 'test title'
    assert read_response['cards'][0]['text'] == 'test text'
    assert read_response['cards'][0]['uid'] == expected_uid
Example #12
0
def test_create(setup_teardown):
    env = 'test'
    args = {
        'action': 'create',
        'card': {
            'title': 'test title',
            'text': 'test text'
        }
    }

    response = run(env, args)

    assert response['message'] == 'Card created'
    assert 'card_uid' in response
Example #13
0
def update(card):
    inputs_for_update = pi.prompt(CREATE_QS)

    card = {
        'uid': card['uid'],
    }

    if inputs_for_update['title'] != "":
        card['title'] = inputs_for_update['title']

    if inputs_for_update['text'] != "":
        card['text'] = inputs_for_update['text']

    response = run('prod', {'action': 'update', 'card': card})
    return response
Example #14
0
def delete(card):
    return run('prod', {'action': 'delete', 'card': {'uid': card['uid']}})
Example #15
0
def read_repo(filters=None) -> list:
    args = {'action': 'read'}
    if filters:
        args['filters'] = filters
    return run('test', args)