Beispiel #1
0
def test_delete_with_invalid_uuid_fails(setup_teardown):
    uid = "hello world"

    repo = JsonRepo('test')

    with pytest.raises(ValueError):
        repo.delete(uid)
Beispiel #2
0
def test_delete_deletes(setup_teardown):
    uid = create_and_save_card('test title')

    repo = JsonRepo('test')
    repo.delete(uid)
    repo.save()

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

    assert len(test_repo.cards_in_memory) == 0
Beispiel #3
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()
Beispiel #4
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
Beispiel #5
0
def test_repo_no_duplicate():
    repo = JsonRepo('test')
    card = Card()

    repo.add(card)
    with pytest.raises(Exception):
        repo.add(card)
Beispiel #6
0
def test_delete_non_existant_card_fails(setup_teardown):
    uid = str(uuid.uuid4())

    repo = JsonRepo('test')
    repo.delete(uid)

    with pytest.raises(FileNotFoundError):
        repo.save()
Beispiel #7
0
def update_card_command(env, card_dict: dict) -> dict:
    repo = JsonRepo(env)
    repo.load({'uid__eq': str(card_dict['uid'])})

    card = repo.cards_in_memory[0]
    card.update_from_dict(card_dict)
    repo.save()

    return {
        'message': 'Card updated',
        'new_card': card.to_dict(),
    }
Beispiel #8
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
Beispiel #9
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
Beispiel #10
0
def delete_card_command(env, card_dict: dict) -> dict:
    uid = card_dict['uid']

    repo = JsonRepo(env)
    repo.delete(uid)
    try:
        repo.save()

    except FileNotFoundError:
        return {
            'message': 'No card with uid "%s" was found in the repo' % uid
        }

    except ValueError:
        return {'message': 'This card has existing children cards, cannot delete'}

    return {
        'message': 'Card deleted',
        'uid': str(uid)
    }
Beispiel #11
0
def test_delete_mem_empties_on_save(setup_teardown):
    uid = create_and_save_card('test title')
    repo = JsonRepo('test')
    repo.delete(uid)
    repo.save()
    assert len(repo.cards_to_delete) == 0
Beispiel #12
0
def read_cards_command(env, filters=None) -> dict:
    repo = JsonRepo(env)
    repo.load(filters)
    return {'cards': [card.to_dict() for card in repo.cards_in_memory]}
Beispiel #13
0
def create_card_command(env, card_dict: dict) -> dict:
    repo = JsonRepo(env)
    card = Card.from_dict(card_dict)
    repo.add(card)
    repo.save()
    return {'message': 'Card created', 'card_uid': str(card.uid)}
Beispiel #14
0
 def create_card_command(self, card):
     repo = JsonRepo(self.env)
     repo.add(card)
     repo.save()
     return card.uid
Beispiel #15
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'
Beispiel #16
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
Beispiel #17
0
def test_repo_create():
    repo = JsonRepo('test')
    assert repo.env == 'test'
    assert repo.path == 'files/test/'
Beispiel #18
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
Beispiel #19
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)