Пример #1
0
def test_card_create_with_parent():
    card1 = Card()
    card2 = Card()

    card1.assign_parent(card2)

    assert card1.parent == card2.uid
Пример #2
0
def test_load_by_id(setup_teardown):
    repo = JsonRepo('test')
    card = Card()
    card.title = 'test title'
    id_to_fetch = str(card.uid)

    repo.add(card)
    repo.add(Card())
    repo.save()

    new_repo = JsonRepo('test')
    new_repo.load({'uid__eq': id_to_fetch})

    assert len(new_repo.cards_in_memory) == 1
    assert new_repo.cards_in_memory[0].title == 'test title'
Пример #3
0
def test_repo_no_duplicate():
    repo = JsonRepo('test')
    card = Card()

    repo.add(card)
    with pytest.raises(Exception):
        repo.add(card)
Пример #4
0
def test_cant_delete_card_with_children(setup_teardown):
    card1 = Card()
    card2 = Card()

    card2.assign_parent(card1)

    repo = JsonRepo('test')
    repo.add(card1)
    repo.add(card2)
    repo.save()

    uid = str(card1.uid)
    repo.delete(uid)

    with pytest.raises(Exception):
        repo.save()
Пример #5
0
def test_card_to_dict():
    card = Card()
    card2 = Card()
    card.title = 'test title'
    card.edit_text('hello world')
    card.assign_parent(card2)

    dic = card.to_dict()
    expected = {
        'uid': str(card.uid),
        'text_exceeds_500': False,
        'title': card.title,
        'text': card.text,
        'parent': str(card.parent),
    }

    assert dic == expected
Пример #6
0
def test_repo_load_multi_card(setup_teardown):
    repo = JsonRepo('test')
    card = Card()
    card.text = 'hello world'
    card.title = 'test title'
    card2 = Card()
    card.assign_parent(card2)

    repo.add(card)
    repo.add(card2)

    repo.save()

    new_repo = JsonRepo('test')
    new_repo.load()

    assert len(new_repo.cards_in_memory) == 2
Пример #7
0
def test_load_repo(setup_teardown):
    repo = JsonRepo('test')
    card = Card()
    card.edit_text('hello world')
    card.title = 'test title'
    card2 = Card()
    card.assign_parent(card2)

    repo.add(card)
    repo.save()

    new_repo = JsonRepo('test')
    new_repo.load()

    assert len(new_repo.cards_in_memory) == 1

    assert new_repo.cards_in_memory[0] == card
Пример #8
0
def test_update_from_dict():
    card = Card()
    card.title = 'old title'
    card.edit_text('old text')

    card_dict = {'uid': str(card.uid), 'title': 'new title'}

    card.update_from_dict(card_dict)

    assert card.title == 'new title'
    assert card.text == 'old text'
Пример #9
0
def create_and_save_card(title, text=None):
    repo = JsonRepo('test')
    card = Card()
    card.title = title
    if text:
        card.text = text

    uid = str(card.uid)

    repo.add(card)
    repo.save()

    print('created and saved card with uid ' + uid)

    return uid
Пример #10
0
def test_repo_save(setup_teardown):
    repo = JsonRepo('test')
    card = Card()

    repo.add(card)
    repo.save()

    expected_file_name = repo.path + str(card.uid) + ".json"
    expected_dict = {
        'uid': str(card.uid),
    }

    with open(expected_file_name) as file:
        data = json.loads(file.read())

    assert data == expected_dict
Пример #11
0
def test_text_length_max_500():
    card = Card()
    card.title = 'title'

    long_string = ('Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
                   'Integer iaculis interdum diam vitae dapibus. Praesent '
                   'et dapibus eros, rutrum feugiat velit. Proin placerat '
                   'orci dignissim, eleifend dui quis, aliquet tellus. '
                   'Vestibulum ante ipsum primis in faucibus orci luctus et '
                   'ultrices posuere cubilia Curae; Cras vel tincidunt '
                   'velit. Fusce nulla erat, malesuada eu ultrices pulvinar,'
                   ' fringilla viverra nisi. Donec non rutrum velit, sed '
                   'rutrum mi. Praesent consequat, tellus eget sagittis '
                   'ornare, augue justo molestie mi, vel accumsan risus '
                   'turpis id est. Donec congue hendrerit urna, nec aliquet '
                   'quam hendrerit at. Integer eget dui nec arcu venenatis '
                   'viverra nec nec justo. Praesent.')

    card.edit_text(long_string)
    assert card.text_exceeds_500
Пример #12
0
def test_card_create():
    card = Card()
    card.title = "Hello World"

    assert card.uid
Пример #13
0
def test_length_check_no_text():
    card = Card()
    card.edit_text('')
    assert not card.text_exceeds_500
Пример #14
0
def test_repo_add():
    repo = JsonRepo('test')
    card = Card()
    repo.add(card)
    assert repo.cards_in_memory == [card]
    assert isinstance(repo.cards_in_memory[0].uid, uuid.UUID)
Пример #15
0
def test_memory_empties_on_save(setup_teardown):
    repo = JsonRepo('test')
    card = Card()
    repo.add(card)
    repo.save()
    assert len(repo.cards_in_memory) == 0