Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
philipkcl committed Apr 15, 2024
1 parent 3dcc38d commit 96ac2eb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
6 changes: 5 additions & 1 deletion doajtest/fixtures/accounts.py
Expand Up @@ -83,7 +83,11 @@ def create_publisher_a():
return publisher


def create_maned_a():
def create_maned_a(is_save=False):
from portality import models
maned = models.Account(**AccountFixtureFactory.make_managing_editor_source())
maned.set_password("password")
if is_save:
maned.save(blocking=True)
return maned

4 changes: 2 additions & 2 deletions doajtest/helpers.py
Expand Up @@ -410,9 +410,9 @@ def assert_expected_dict(test_case: TestCase, target, expected: dict):
test_case.assertDictEqual(actual, expected)


def login(app_client, username, password, follow_redirects=True):
def login(app_client, email, password, follow_redirects=True):
return app_client.post(url_for('account.login'),
data=dict(user=username, password=password),
data=dict(user=email, password=password),
follow_redirects=follow_redirects)


Expand Down
5 changes: 2 additions & 3 deletions doajtest/unit/api_tests/test_api_crud_returnvalues.py
@@ -1,3 +1,4 @@
from doajtest import helpers
from doajtest.helpers import DoajTestCase, with_es
from portality import models
from doajtest.fixtures import ApplicationFixtureFactory, ArticleFixtureFactory, JournalFixtureFactory
Expand Down Expand Up @@ -205,9 +206,7 @@ def test_04_article_structure_exceptions(self):

@staticmethod
def login(app, username, password):
return app.post('/account/login',
data=dict(username=username, password=password),
follow_redirects=True)
return helpers.login(app, username, password)

@staticmethod
def logout(app):
Expand Down
37 changes: 37 additions & 0 deletions doajtest/unit/test_view_admin.py
@@ -0,0 +1,37 @@
import json

from doajtest import helpers
from doajtest.fixtures import JournalFixtureFactory
from doajtest.fixtures.accounts import create_maned_a
from doajtest.helpers import DoajTestCase
from portality import models
from portality.util import url_for


class TestViewAdmin(DoajTestCase):

def setUp(self):
super().setUp()
self.acc = create_maned_a(is_save=True)

def test_journal_article_info(self):
journal = models.Journal(
**JournalFixtureFactory.make_journal_source()
)
journal.save(blocking=True)
models.Journal.refresh()

with self.app_test.test_client() as client:
resp = helpers.login(client, self.acc.email, 'password')
assert resp.status_code == 200

resp = client.get(url_for("admin.journal_article_info", journal_id=journal.id))
assert resp.status_code == 200
assert json.loads(resp.data) == {'n_articles': 0}

def test_journal_article_info__not_found(self):
with self.app_test.test_client() as client:
helpers.login(client, self.acc.email, 'password')

resp = client.get(url_for("admin.journal_article_info", journal_id='aksjdlaksjdlkajsdlkajsdlk'))
assert resp.status_code == 404
1 change: 1 addition & 0 deletions portality/view/admin.py
Expand Up @@ -322,6 +322,7 @@ def journals_bulk_reinstate():
#####################################################################

@blueprint.route("/journal/<journal_id>/article-info/", methods=["GET"])
@login_required
def journal_article_info(journal_id):
j = models.Journal.pull(journal_id)
if j is None:
Expand Down

0 comments on commit 96ac2eb

Please sign in to comment.