def test_delete_keywords(entry_id, delete_keywords): """test: delete_keywords""" old_keywords = api.get_keywords(session=session, entry_id=entry_id) api.delete_keywords(session, entry_id, *delete_keywords) new_keywords = api.get_keywords(session=session, entry_id=entry_id) [old_keywords.pop(k) for k in delete_keywords if k in old_keywords] assert new_keywords == old_keywords
def test_update_keywords(entry_id, added_keywords): """test: update_keywords""" old_keywords = api.get_keywords(session=session, entry_id=entry_id) api.update_keywords(session=session, entry_id=entry_id, **added_keywords) new_keywords = api.get_keywords(session=session, entry_id=entry_id) expected_keywords = old_keywords expected_keywords.update(added_keywords) assert new_keywords == map_obj_to_string(expected_keywords)
def test_add_single_keywords(entry_id, name, value, unique): """test: add_single_keyword""" old_keywords = api.get_keywords(session=session, entry_id=entry_id) api.add_single_keyword(session=session, entry_id=entry_id, name=name, value=value, unique=unique) new_keywords = api.get_keywords(session=session, entry_id=entry_id) expected_keywords = dict([(name, value)] + list(old_keywords.items())) assert new_keywords == map_obj_to_string(expected_keywords)
def test_delete_all_keywords(entry_id, result): """ Test `delete_all_keywords` Parameters ---------- entry_id : str Keyword name to test result : dict or Exception List of expected results. """ with context_backup_keywords(entry_id=entry_id) as exists: try: # delete api.delete_all_keywords(session=session, entry_id=entry_id) except Exception as e: if type(e) == type(result) and e.args == result.args: return raise e if exists: # get results res = api.get_keywords(session=session, entry_id=entry_id) # check assert type(res) == type(result) and set(res.items()) == set( result.items())
def test_delete_keywords(entry_id, keyword_names, result): """ Test `delete_keywords` Parameters ---------- entry_id : str Keyword name to test keyword_names : list Dictionary with keyword arguments of `delete_keywords`. result : dict or Exception List of expected results. """ with context_backup_keywords(entry_id=entry_id) as exists: try: # delete api.delete_keywords(session=session, entry_id=entry_id, keyword_names=keyword_names) except Exception as e: print("DASDASDAS") if type(e) == type(result) and e.args == result.args: return raise e if exists: # get results res = api.get_keywords(session=session, entry_id=entry_id) # check assert type(res) == type(result) and set(res.items()) == set( result.items())
def test_update_keywords(entry_id, keywords, result): """ Test `update_keywords` Parameters ---------- entry_id : str Keyword name to test keywords : dict Dictionary with keyword arguments of `update_keywords`. result : dict or Exception List of expected results. """ with context_backup_keywords(entry_id=entry_id): try: # update api.update_keywords(session=session, entry_id=entry_id, keywords=keywords) except Exception as e: if type(e) == type(result) and e.args == result.args: return raise e # get results res = api.get_keywords(session=session, entry_id=entry_id) # check assert type(res) == type(result) and set(res.items()) == set( result.items())
def detail(db_id, entry_id): # get the path to selected DB path = db.session.query(DBPath).filter(DBPath.id == db_id).one().path session = api.connect_database(db_path=path) # render template return render_template( 'details.html', sim=api.get_entry_details(session=session, entry_id=entry_id), meta=api.get_meta_groups(session, entry_id, as_list=True), keywords=api.get_keywords(session=session, entry_id=entry_id), )
def test_get_keywords(entry_id, result): """ Test `get_keywords` Parameters ---------- entry_id : str Entry ID result : dict or Exception List of expected results. """ # get results try: res = api.get_keywords(session=session, entry_id=entry_id) except Exception as e: if type(e) == type(result) and e.args == result.args: return raise e # check assert type(res) == type(result) and set(res.items()) == set( result.items())
def context_backup_keywords(entry_id): """ Context manger to back up keywords Parameters ---------- entry_id : str Entry ID """ exists = session.query( api.exists().where(api.Main.entry_id == entry_id)).scalar() if exists: # save old old_keywords = api.get_keywords(session=session, entry_id=entry_id) yield exists if exists: # reset api.set_keywords(session=session, entry_id=entry_id, keywords=old_keywords)
for sim in sims: assert test_same_keywords(test_sims[sim.entry_id]['keywords'], sim.keywords) print() query = session.query( Keywords.name, Keywords.value).join(Main).filter(Main.entry_id == 'TEST01') print(dict(query.all())) #print(sim.keywords) query = session.query( Keywords.name, Keywords.value).join(Main).filter(Keywords.main_id == 'TEST04') print(dict(query.all())) print(api.get_keywords(session, 'TEST01')) def add_keyword(session, entry_id, name, value=None): main_id = None query = session.query(Keywords).join(Main).filter( Keywords.name == name).filter(Main.entry_id == entry_id) keyword = query.one_or_none() if keyword is None: if main_id is None: main_id = session.query( Main.id).filter(Main.entry_id == entry_id).one()[0] keyword = Keywords(name=name, value=value, main_id=main_id) else: keyword.value = value session.add(keyword)
def test_get_keywords(entry_id, expected_keywords): """test: get_keywords""" keywords = api.get_keywords(session=session, entry_id=entry_id) assert keywords == expected_keywords
def test_delete_all_keywords(entry_id): """test: delete_all_keywords""" api.delete_all_keywords(session, entry_id) new_keywords = api.get_keywords(session=session, entry_id=entry_id) assert new_keywords == {}
def test_set_keywords(entry_id, added_keywords): """test: set_keywords""" api.set_keywords(session=session, entry_id=entry_id, **added_keywords) new_keywords = api.get_keywords(session=session, entry_id=entry_id) assert new_keywords == map_obj_to_string(added_keywords)
q = session.query(Keywords) keywords = [e.name for e in q.filter(Keywords.value != None).all()] key_dict = {} for k in np.unique(keywords): key_dict[k] = np.unique([ e.value for e in q.filter(Keywords.value != None, Keywords.name == k).all() ]) print(key_dict) print("len: ", len(key_dict)) #=========================================================# # unique tags per api print_caption("api keywords") api_keywords = api.get_keywords(db_path=db_path) print(api_keywords) print("len: ", len(api_keywords)) assert test_dict(api_keywords, key_dict) assert test_dict(api_keywords, unique_keywords) #=============================================================================# # tags #=========================================================# # all tags print_caption("all tags") query = session.query(Keywords.name).select_from(Keywords).filter( Keywords.value.is_(None)) all_tags = query.all() print(all_tags)