From b44957078c39c4a304cf2489d97ccae904ce140c Mon Sep 17 00:00:00 2001 From: Ramakrishna Date: Mon, 14 Aug 2023 10:11:22 +0530 Subject: [PATCH] Added test cases for testing notes for journal and application --- doajtest/unit/test_query.py | 191 ++++++++++++++++++++++++++++++------ 1 file changed, 160 insertions(+), 31 deletions(-) diff --git a/doajtest/unit/test_query.py b/doajtest/unit/test_query.py index 3685d2927c..2dc145acac 100644 --- a/doajtest/unit/test_query.py +++ b/doajtest/unit/test_query.py @@ -1,6 +1,7 @@ from portality import models -from doajtest.fixtures import AccountFixtureFactory, ArticleFixtureFactory +from doajtest.fixtures import AccountFixtureFactory, ArticleFixtureFactory, EditorGroupFixtureFactory, \ + ApplicationFixtureFactory from doajtest.helpers import DoajTestCase, deep_sort from portality.bll.services.query import QueryService, Query @@ -30,7 +31,12 @@ "auth" : True, "role" : "admin", "dao" : "portality.models.Journal" - } + }, + "suggestion" : { + "auth" : True, + "role" : "admin", + "dao" : "portality.models.Application" + }, }, "api_query" : { "article" : { @@ -53,6 +59,30 @@ "query_filters" : ["owner", "private_source"], "dao" : "portality.models.Suggestion" } + }, + "editor_query" : { + "journal" : { + "auth" : True, + "role" : "editor", + "dao" : "portality.models.Journal" + }, + "suggestion" : { + "auth" : True, + "role" : "editor", + "dao" : "portality.models.Application" + } + }, + "associate_query": { + "journal": { + "auth": True, + "role": "associate_editor", + "dao": "portality.models.Journal" + }, + "suggestion" : { + "auth" : True, + "role" : "associate_editor", + "dao" : "portality.models.Application" + } } } @@ -68,9 +98,13 @@ } QUERY_FILTERS = { + "non_public_fields_validator" : "portality.lib.query_filters.non_public_fields_validator", + # query filters "only_in_doaj" : "portality.lib.query_filters.only_in_doaj", "owner" : "portality.lib.query_filters.owner", + "associate" : "portality.lib.query_filters.associate", + "editor" : "portality.lib.query_filters.editor", # result filters "public_result_filter" : "portality.lib.query_filters.public_result_filter", @@ -101,6 +135,29 @@ def tearDown(self): self.app_test.config['QUERY_ROUTE'] = self.OLD_QUERY_ROUTE self.app_test.config['QUERY_FILTERS'] = self.OLD_QUERY_FILTERS + def get_application_with_notes(self): + source = ApplicationFixtureFactory.make_application_source() + app = models.Application(**source) + app.add_note("application test", "2015-01-01T00:00:00Z") + app.save() + return app + + def get_journal_with_notes(self): + j = models.Journal() + j.set_id("aabbccdd") + j.set_created("2010-01-01T00:00:00Z") + j.set_last_updated("2012-01-01T00:00:00Z") + j.set_last_manual_update("2014-01-01T00:00:00Z") + j.set_seal(True) + j.set_owner("rama") + j.set_editor_group("worldwide") + j.set_editor("eddie") + j.add_contact("rama", "rama@email.com") + j.add_note("testing", "2015-01-01T00:00:00Z") + j.set_bibjson({"title": "test"}) + j.save() + return j + def test_01_auth(self): with self.app_test.test_client() as t_client: response = t_client.get('/query/journal') # not in the settings above @@ -357,45 +414,19 @@ def test_public_query_notes(self): self.app_test.config['QUERY_ROUTE'] = JOURNAL_QUERY_ROUTE - j = models.Journal() - j.set_id("aabbccdd") - j.set_created("2010-01-01T00:00:00Z") - j.set_last_updated("2012-01-01T00:00:00Z") - j.set_last_manual_update("2014-01-01T00:00:00Z") - j.set_seal(True) - j.set_owner("rama") - j.set_editor_group("worldwide") - j.set_editor("eddie") - j.add_contact("rama", "rama@email.com") - j.add_note("testing", "2015-01-01T00:00:00Z") - j.set_bibjson({"title": "test"}) - j.save() + self.get_journal_with_notes() - maned = models.Account(**AccountFixtureFactory.make_managing_editor_source()) - maned.save(blocking=True) qsvc = QueryService() res = qsvc.search('query', 'journal', {'query': {'query_string': {'query': 'testing', 'default_operator': 'AND'}}, 'size': 0, 'aggs': {'country_publisher': {'terms': {'field': 'index.country.exact', 'size': 100, 'order': {'_count': 'desc'}}}}, - 'track_total_hits': True}, account=maned, additional_parameters={}) + 'track_total_hits': True}, account=None, additional_parameters={}) assert res['hits']['total']["value"] == 0, res['hits']['total']["value"] def test_admin_query_notes(self): - j = models.Journal() - j.set_id("aabbccdd") - j.set_created("2010-01-01T00:00:00Z") - j.set_last_updated("2012-01-01T00:00:00Z") - j.set_last_manual_update("2014-01-01T00:00:00Z") - j.set_seal(True) - j.set_owner("rama") - j.set_editor_group("worldwide") - j.set_editor("eddie") - j.add_contact("rama", "rama@email.com") - j.add_note("testing", "2015-01-01T00:00:00Z") - j.set_bibjson({"title": "test"}) - j.save() + self.get_journal_with_notes() maned = models.Account(**AccountFixtureFactory.make_managing_editor_source()) maned.save(blocking=True) @@ -406,3 +437,101 @@ def test_admin_query_notes(self): {'terms': {'field': 'index.country.exact', 'size': 100, 'order': {'_count': 'desc'}}}}, 'track_total_hits': True}, account=maned, additional_parameters={}) assert res['hits']['total']["value"] == 1, res['hits']['total']["value"] + + def test_editor_query_notes(self): + + self.get_journal_with_notes() + + editor = models.Account(**AccountFixtureFactory.make_editor_source()) + editor.save(blocking=True) + + eg_source = EditorGroupFixtureFactory.make_editor_group_source(maned=editor.id) + eg = models.EditorGroup(**eg_source) + eg.save(blocking=True) + + qsvc = QueryService() + + res = qsvc.search('editor_query', 'journal', {'query': {'query_string': {'query': 'testing', + 'default_operator': 'AND'}}, 'size': 0, 'aggs': {'country_publisher': + {'terms': {'field': 'index.country.exact', 'size': 100, 'order': {'_count': 'desc'}}}}, + 'track_total_hits': True}, account=editor, additional_parameters={}) + assert res['hits']['total']["value"] == 1, res['hits']['total']["value"] + + def test_associate_editor_query_notes(self): + + self.get_journal_with_notes() + + associate = models.Account(**AccountFixtureFactory.make_assed1_source()) + associate.save(blocking=True) + + eg_source = EditorGroupFixtureFactory.make_editor_group_source(maned=associate.id) + eg = models.EditorGroup(**eg_source) + eg.save(blocking=True) + + qsvc = QueryService() + + res = qsvc.search('associate_query', 'journal', {'query': {'query_string': {'query': 'testing', + 'default_operator': 'AND'}}, 'size': 0, 'aggs': {'country_publisher': + {'terms': {'field': 'index.country.exact', 'size': 100, 'order': {'_count': 'desc'}}}}, + 'track_total_hits': True}, account=associate, additional_parameters={}) + assert res['hits']['total']["value"] == 1, res['hits']['total']["value"] + + def test_associate_editor_application_query_notes(self): + + app = self.get_application_with_notes() + + associate = models.Account(**AccountFixtureFactory.make_assed1_source()) + associate.save(blocking=True) + + eg_source = EditorGroupFixtureFactory.make_editor_group_source(maned=associate.id) + eg = models.EditorGroup(**eg_source) + eg.set_name(app.editor_group) + eg.save(blocking=True) + + qsvc = QueryService() + + res = qsvc.search('associate_query', 'suggestion', {'query': {'query_string': {'query': 'application test', + 'default_operator': 'AND'}}, 'size': 0, 'aggs': {'country_publisher': + {'terms': {'field': 'index.country.exact', 'size': 100, 'order': {'_count': 'desc'}}}}, + 'track_total_hits': True}, account=associate, additional_parameters={}) + assert res['hits']['total']["value"] == 1, res['hits']['total']["value"] + + def test_editor_application_query_notes(self): + + app = self.get_application_with_notes() + + editor = models.Account(**AccountFixtureFactory.make_editor_source()) + editor.save(blocking=True) + + eg_source = EditorGroupFixtureFactory.make_editor_group_source(maned=editor.id) + eg = models.EditorGroup(**eg_source) + eg.set_name(app.editor_group) + eg.save(blocking=True) + + qsvc = QueryService() + + res = qsvc.search('editor_query', 'suggestion', {'query': {'query_string': {'query': 'application test', + 'default_operator': 'AND'}}, 'size': 0, 'aggs': {'country_publisher': + {'terms': {'field': 'index.country.exact', 'size': 100, 'order': {'_count': 'desc'}}}}, + 'track_total_hits': True}, account=editor, additional_parameters={}) + assert res['hits']['total']["value"] == 1, res['hits']['total']["value"] + + def test_editor_application_query_notes(self): + + app = self.get_application_with_notes() + + med = models.Account(**AccountFixtureFactory.make_managing_editor_source()) + med.save(blocking=True) + + eg_source = EditorGroupFixtureFactory.make_editor_group_source(maned=med.id) + eg = models.EditorGroup(**eg_source) + eg.set_name(app.editor_group) + eg.save(blocking=True) + + qsvc = QueryService() + + res = qsvc.search('admin_query', 'suggestion', {'query': {'query_string': {'query': 'application test', + 'default_operator': 'AND'}}, 'size': 0, 'aggs': {'country_publisher': + {'terms': {'field': 'index.country.exact', 'size': 100, 'order': {'_count': 'desc'}}}}, + 'track_total_hits': True}, account=med, additional_parameters={}) + assert res['hits']['total']["value"] == 1, res['hits']['total']["value"]