def list(): """ Search for all tags in TAG table using query. :return: on success 'items' contains a list of all tags on error 'msg' gives reason message """ session = db.session available_tags = Tag.query_find_all(session) return { 'items': tag_schema.dump(available_tags, many=True).data, }
def new(text: hug.types.text = None): """ Add a new tag, text is passed as query parameter. :return: on success new tag object is returned on error 'msg' gives reason message """ session = db.session if text is None or text == "": raise HTTPInvalidParam("text", "Text should not be empty") # Check if a tag with same tag already exists available_tags = Tag.query_find_all(session) if text in [t.text for t in available_tags]: raise HTTPInvalidParam("text", "Tag already exists") # create tag if not already present tag = Tag(text) session.add(tag) session.commit() # returns new tag return tag_schema.dump(tag).data
def test_query_find_all(self): m_session = MagicMock() Tag.query_find_all(m_session) m_session.query().all.assert_called_once()