Skip to content

Commit

Permalink
Added test cases for testing notes for journal and application
Browse files Browse the repository at this point in the history
  • Loading branch information
RK206 committed Aug 14, 2023
1 parent d23ba4a commit b449570
Showing 1 changed file with 160 additions and 31 deletions.
191 changes: 160 additions & 31 deletions doajtest/unit/test_query.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,7 +31,12 @@
"auth" : True,
"role" : "admin",
"dao" : "portality.models.Journal"
}
},
"suggestion" : {
"auth" : True,
"role" : "admin",
"dao" : "portality.models.Application"
},
},
"api_query" : {
"article" : {
Expand All @@ -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"
}
}
}

Expand All @@ -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",
Expand Down Expand Up @@ -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", "[email protected]")
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
Expand Down Expand Up @@ -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", "[email protected]")
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", "[email protected]")
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)
Expand All @@ -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"]

0 comments on commit b449570

Please sign in to comment.