def test_update_work(self): data = self.build_data(True, True) tagType = TagType(label='one') db.session.add(tagType) tagType = TagType(label='two') db.session.add(tagType) tag_one = Tag(tag_type_id=1, text='one') tag_two = Tag(tag_type_id=2, text='two') workObj = Work() workObj.title = "Beginning Title" workObj.user_id = 1 db.session.add(workObj) work.add_chapters(workObj, data["chapters"]) db.session.commit() data['work_id'] = workObj.id data['chapters'][0]['id'] = workObj.chapters[0].id work.update_work(data) workObj = Work.query.filter_by(id=workObj.id).first() self.assertTrue(workObj.title == "A Tale of Two Poor Students")
def test_delete_work(self): self.build_data(False, False) workObj = Work() workObj.user_id = 1 db.session.add(workObj) db.session.commit() work.delete_work(1, 1) works = Work.query.all() self.assertTrue(len(works) == 0)
def test_add_chapters(self): data = self.build_data(False, True) workObj = Work() db.session.add(workObj) db.session.commit() work.add_chapters(workObj, data["chapters"]) new_id = Chapter.query.filter_by(work_id=1) self.assertTrue(new_id.first().title == "Chapter One Title") self.assertTrue(new_id.count() == 1)
def test_add_comments(self): data = self.build_data(True, True) workObj = Work() db.session.add(workObj) db.session.commit() work.add_chapters(workObj, data["chapters"]) comment = Comment(user_id=1, text='hello world', chapter_id=1) db.session.add(comment) db.session.commit() commentTwo = Comment(user_id=1, text='goodbye world', chapter_id=1) comment.comments.append(commentTwo) db.session.add(comment) db.session.commit()
def test_add_tags(self): data = self.build_data(True, True) workObj = Work() db.session.add(workObj) db.session.commit() tagType = TagType() db.session.add(tagType) tagTypeTwo = TagType() db.session.add(tagTypeTwo) db.session.commit() new_id = work.add_tags(workObj, data["work_tags"]) expected_len = [x for x in new_id if x.tag_type_id == 1] self.assertTrue(new_id[0].text == "one") self.assertTrue(len(expected_len) == 3)
def test_get_works(self): tagType = TagType(label='one') db.session.add(tagType) tagType = TagType(label='two') db.session.add(tagType) tag_one = Tag(tag_type_id=1, text='one') tag_two = Tag(tag_type_id=2, text='two') workObj = Work() workObj.tags.append(tag_one) workObj.tags.append(tag_two) db.session.add(workObj) db.session.commit() tag.get_tagged_data(1, 'one')
def test_build_work_tags(self): self.add_user() tagType = TagType(label='one') db.session.add(tagType) tagType = TagType(label='two') db.session.add(tagType) tag_one = Tag(tag_type_id=1, text='one') tag_two = Tag(tag_type_id=2, text='two') workObj = Work() workObj.tags.append(tag_one) workObj.tags.append(tag_two) db.session.add(workObj) db.session.commit() tags = work.build_work_tags(workObj) self.assertTrue(len(tags) == 2) self.assertTrue(tags[0]['tags'][0] == 'one')
def add_chapter(self): work = Work(title="test") db.session.add(work) work.chapters.append(Chapter(title="test chap")) db.session.commit()