def test_video_keywords(es, api_project, keyword_1, keyword_2, users): """Tet video keywords.""" (project, video_1, video_2) = api_project # login owner login_user(User.query.filter_by(id=users[0]).first()) assert video_1['keywords'] == [] # try to add keywords video_1.add_keyword(keyword_1) video_1.add_keyword(keyword_2) video_1.add_keyword(keyword_1) assert video_1['keywords'] == [ { '$ref': keyword_1.ref }, { '$ref': keyword_2.ref }, ] video_1.commit() db.session.commit() CDSRecordIndexer().index(video_1) sleep(2) # check elasticsearch result = DepositSearch().filter( Q('match', **{'_deposit.id': video_1['_deposit']['id'] })).params(version=True).execute().to_dict()['hits']['hits'][0] kw_result = {k['key_id']: k['name'] for k in result['_source']['keywords']} kw_expect = {k['key_id']: k['name'] for k in [keyword_1, keyword_2]} assert kw_expect == kw_result # try to remove a key video_1.remove_keyword(keyword_1) assert video_1['keywords'] == [ { '$ref': keyword_2.ref }, ] video_1.commit() db.session.commit() CDSRecordIndexer().index(video_1) sleep(2) # check elasticsearch result = DepositSearch().filter( Q('match', **{'_deposit.id': video_1['_deposit']['id'] })).params(version=True).execute().to_dict()['hits']['hits'][0] kw_result = {k['key_id']: k['name'] for k in result['_source']['keywords']} kw_expect = {k['key_id']: k['name'] for k in [keyword_2]} assert kw_expect == kw_result
def test_project_keywords(es, api_project, keyword_1, keyword_2, users): """Tet project keywords.""" (project, video_1, video_2) = api_project # login owner login_user(User.query.filter_by(id=users[0]).first()) assert project['keywords'] == [] project.add_keyword(keyword_1) project.add_keyword(keyword_2) project.add_keyword(keyword_1) assert project['keywords'] == [ { '$ref': keyword_1.ref }, { '$ref': keyword_2.ref }, ] project.commit() sleep(2) # check elasticsearch result = DepositSearch().filter( Q('match', **{'_deposit.id': project['_deposit']['id'] })).params(version=True).execute().to_dict()['hits']['hits'][0] kw_result = {k['key_id']: k['name'] for k in result['_source']['keywords']} kw_expect = {k['key_id']: k['name'] for k in [keyword_1, keyword_2]} assert kw_expect == kw_result project.remove_keyword(keyword_1) assert project['keywords'] == [ { '$ref': keyword_2.ref }, ] project.commit() sleep(2) # check elasticsearch result = DepositSearch().filter( Q('match', **{'_deposit.id': project['_deposit']['id'] })).params(version=True).execute().to_dict()['hits']['hits'][0] kw_result = {k['key_id']: k['name'] for k in result['_source']['keywords']} kw_expect = {k['key_id']: k['name'] for k in [keyword_2]} assert kw_expect == kw_result