def test_card_create_with_parent(): card1 = Card() card2 = Card() card1.assign_parent(card2) assert card1.parent == card2.uid
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'
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
def test_repo_no_duplicate(): repo = JsonRepo('test') card = Card() repo.add(card) with pytest.raises(Exception): repo.add(card)
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()
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
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
def test_equality(): uid = uuid.uuid4() p_uid = uuid.uuid4() card = Card.from_dict({ 'uid': str(uid), 'text': 'hello world', 'title': 'test title', 'parent': str(p_uid), }) assert card == card
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'
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
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
def test_from_dict(): uid = uuid.uuid4() p_uid = uuid.uuid4() dic = { 'uid': str(uid), 'text': 'hello world', 'title': 'test title', 'parent': str(p_uid), } card = Card.from_dict(dic) assert card.uid == uid assert card.parent == p_uid assert card.text == 'hello world' assert card.title == 'test title'
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
def save_card(self, card: Card): filename = self.path + str(card.uid) + ".json" with open(filename, 'w') as file: file.write(json.dumps(card.to_dict()))
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)
def test_card_create(): card = Card() card.title = "Hello World" assert card.uid
def test_length_check_no_text(): card = Card() card.edit_text('') assert not card.text_exceeds_500
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
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)}
def load_card(filename): with open(filename, 'r') as file: return Card.from_dict(json.loads(file.read()))