From 204f7b81c3d38228790b73e8a9af254c0c570733 Mon Sep 17 00:00:00 2001 From: Mojib Wali <44528277+mb-wali@users.noreply.github.com> Date: Thu, 10 Dec 2020 12:25:52 +0100 Subject: [PATCH] test: adding tests * test: removed no cover * tests: adding tests for functions. * test_make_dict_like * test_cast_to_dict --- invenio_theme_tugraz/views.py | 6 +++--- setup.py | 3 ++- tests/ui/conftest.py | 22 ++++++++++++++++++++++ tests/ui/test_views.py | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 tests/ui/conftest.py create mode 100644 tests/ui/test_views.py diff --git a/invenio_theme_tugraz/views.py b/invenio_theme_tugraz/views.py index bcad55b..107f815 100644 --- a/invenio_theme_tugraz/views.py +++ b/invenio_theme_tugraz/views.py @@ -29,7 +29,7 @@ def index(): return render_template( "invenio_theme_tugraz/index.html", records=FrontpageRecordsSearch()[:5].sort("-created").execute(), - ) # pragma: no cover + ) @blueprint.app_template_filter("make_dict_like") @@ -38,10 +38,10 @@ def make_dict_like(value: str, key: str) -> Dict[str, str]: in the form of a key -> value pair. """ - return {key: value} # pragma: no cover + return {key: value} @blueprint.app_template_filter("cast_to_dict") def cast_to_dict(attr_dict): """Return the dict structure of AttrDict variable.""" - return AttrDict.to_dict(attr_dict) # pragma: no cover + return AttrDict.to_dict(attr_dict) diff --git a/setup.py b/setup.py index 92fc012..bc1c6f7 100644 --- a/setup.py +++ b/setup.py @@ -17,8 +17,9 @@ history = open("CHANGES.rst").read() tests_require = [ "pytest-invenio>=1.4.0", + 'invenio-app>=1.3.0,<2.0.0', # TODO: remove once a new release is out - 'docker-services-cli>=0.2.1,<0.3.0', + 'docker-services-cli>=0.2.1,<0.3.0' ] extras_require = { diff --git a/tests/ui/conftest.py b/tests/ui/conftest.py new file mode 100644 index 0000000..a7421b5 --- /dev/null +++ b/tests/ui/conftest.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2020 mojib wali. +# +# invenio-theme-tugraz is free software; you can redistribute it and/or +# modify it under the terms of the MIT License; see LICENSE file for more +# details. + +"""Pytest configuration. + +See https://pytest-invenio.readthedocs.io/ for documentation on which test +fixtures are available. +""" + +import pytest +from invenio_app.factory import create_ui + + +@pytest.fixture(scope='module') +def create_app(instance_path): + """Application factory fixture.""" + return create_ui diff --git a/tests/ui/test_views.py b/tests/ui/test_views.py new file mode 100644 index 0000000..8ae544f --- /dev/null +++ b/tests/ui/test_views.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2020 mojib wali. +# +# invenio-theme-tugraz is free software; you can redistribute it and/or +# modify it under the terms of the MIT License; see LICENSE file for more +# details. + +"""Test views.""" + +from elasticsearch_dsl.utils import AttrDict + +from invenio_theme_tugraz.views import cast_to_dict, make_dict_like + + +def test_make_dict_like(): + """Test make_dict_like.""" + access = { + "access_right" : "open" + } + dicts = make_dict_like("open", "access_right") + assert access == dicts + + +def test_cast_to_dict(): + """Test cast_to_dict.""" + resource_type = { + "subtype" : "publication-datamanagementplan", + "type" : "publication" + } + expected = {'subtype': 'publication-datamanagementplan', 'type': 'publication'} + attr = cast_to_dict(AttrDict(resource_type)) + assert expected == attr