From 2f9069c8af124409a765453ba3a607f3b85e8e09 Mon Sep 17 00:00:00 2001 From: Rebecca Graber Date: Fri, 15 Dec 2023 09:03:03 -0500 Subject: [PATCH 1/7] feat: add basic unit test --- .../requirements/test.in | 1 + .../tests/test_{{cookiecutter.package_name}}.py | 17 +++++++++++++++++ .../{{cookiecutter.repo_name}}/tox.ini | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py diff --git a/cookiecutter-xblock/{{cookiecutter.repo_name}}/requirements/test.in b/cookiecutter-xblock/{{cookiecutter.repo_name}}/requirements/test.in index 6797160b..3a923b40 100644 --- a/cookiecutter-xblock/{{cookiecutter.repo_name}}/requirements/test.in +++ b/cookiecutter-xblock/{{cookiecutter.repo_name}}/requirements/test.in @@ -6,3 +6,4 @@ pytest-cov # pytest extension for code coverage statistics pytest-django # pytest extension for better Django support code-annotations # provides commands used by the pii_check make target. +xblock-sdk # provides workbench settings for testing diff --git a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py new file mode 100644 index 00000000..4b393f11 --- /dev/null +++ b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py @@ -0,0 +1,17 @@ +""" +Tests for pipeline.py +""" + +from django.test import TestCase +from my_xblock import MyXBlock +from xblock.test.toy_runtime import ToyRuntime +from xblock.fields import ScopeIds + +class Test{{cookiecutter.class_name}}(TestCase): + def test_my_student_view(self): + scope_ids = ScopeIds('1','2','3','4') + block = MyXBlock(ToyRuntime(), scope_ids=scope_ids) + frag = block.student_view() + as_dict = frag.to_dict() + content = as_dict['content'] + self.assertIn('MyXBlock: count is now', content, 'XBlock did not render correct student view') diff --git a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini index d62fb3bc..c9b46479 100644 --- a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini +++ b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini @@ -31,7 +31,7 @@ ignore = D101,D200,D203,D212,D215,D404,D405,D406,D407,D408,D409,D410,D411,D412,D match-dir = (?!migrations) [pytest] -DJANGO_SETTINGS_MODULE = translation_settings +DJANGO_SETTINGS_MODULE = workbench.settings addopts = --cov {{ cookiecutter.package_name }} --cov-report term-missing --cov-report xml norecursedirs = .* docs requirements site-packages From 2e8aedc8536dae828ec315582b767e9081ef7f12 Mon Sep 17 00:00:00 2001 From: Rebecca Graber Date: Fri, 15 Dec 2023 09:18:20 -0500 Subject: [PATCH 2/7] fix: add var --- cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini index c9b46479..deddfbe0 100644 --- a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini +++ b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini @@ -41,6 +41,7 @@ deps = django40: Django>=4.0,<4.1 -r{toxinidir}/requirements/test.txt commands = + mkdir -p var pytest {posargs} [testenv:docs] From f5e4da560463e9f60a1b62ff19f8a83f2d3e9e7a Mon Sep 17 00:00:00 2001 From: Rebecca Graber Date: Fri, 15 Dec 2023 15:14:10 -0500 Subject: [PATCH 3/7] fixup!: allow mkdir --- cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini index deddfbe0..bf3ae14a 100644 --- a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini +++ b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini @@ -40,6 +40,8 @@ deps = django32: Django>=3.2,<4.0 django40: Django>=4.0,<4.1 -r{toxinidir}/requirements/test.txt +allowlist_externals = + mkdir commands = mkdir -p var pytest {posargs} From 87b003642ffd8e4cfa0e25692fbd68b5e874c082 Mon Sep 17 00:00:00 2001 From: Rebecca Graber Date: Fri, 15 Dec 2023 15:17:26 -0500 Subject: [PATCH 4/7] fixup!: changelog --- CHANGELOG.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ab49e8ca..e673f76e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,8 @@ Change Log Changed ======= - Remove incorrect build step from xblock ci template +- Fix docstrings +- Add a unit test so coverage can run 2023-12-13 ********** From 7cdfeec459d19242c2b304933af5552d888e77d4 Mon Sep 17 00:00:00 2001 From: Rebecca Graber Date: Fri, 15 Dec 2023 15:26:17 -0500 Subject: [PATCH 5/7] fixup!: quality --- .../tests/test_{{cookiecutter.package_name}}.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py index 4b393f11..aa82c293 100644 --- a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py +++ b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py @@ -1,14 +1,16 @@ """ -Tests for pipeline.py +Tests for {{cookiecutter.class_name}} """ from django.test import TestCase -from my_xblock import MyXBlock -from xblock.test.toy_runtime import ToyRuntime from xblock.fields import ScopeIds +from xblock.test.toy_runtime import ToyRuntime +from my_xblock import MyXBlock class Test{{cookiecutter.class_name}}(TestCase): + """Tests for {{cookiecutter.class_name}}""" def test_my_student_view(self): + """Test the basic view loads.""" scope_ids = ScopeIds('1','2','3','4') block = MyXBlock(ToyRuntime(), scope_ids=scope_ids) frag = block.student_view() From c082a0bda51569a717ac629f210bc1862a5edf5b Mon Sep 17 00:00:00 2001 From: Rebecca Graber Date: Fri, 15 Dec 2023 15:37:32 -0500 Subject: [PATCH 6/7] fixup!: more quality --- .../tests/test_{{cookiecutter.package_name}}.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py index aa82c293..04c25ac9 100644 --- a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py +++ b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py @@ -7,11 +7,12 @@ from xblock.test.toy_runtime import ToyRuntime from my_xblock import MyXBlock + class Test{{cookiecutter.class_name}}(TestCase): """Tests for {{cookiecutter.class_name}}""" def test_my_student_view(self): """Test the basic view loads.""" - scope_ids = ScopeIds('1','2','3','4') + scope_ids = ScopeIds('1', '2', '3', '4') block = MyXBlock(ToyRuntime(), scope_ids=scope_ids) frag = block.student_view() as_dict = frag.to_dict() From 8f286283c63d604d5f35a870d06ccd3b7a0796eb Mon Sep 17 00:00:00 2001 From: Rebecca Graber Date: Fri, 15 Dec 2023 15:44:47 -0500 Subject: [PATCH 7/7] fixup!: imports again --- .../tests/test_{{cookiecutter.package_name}}.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py index 04c25ac9..c98a3e74 100644 --- a/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py +++ b/cookiecutter-xblock/{{cookiecutter.repo_name}}/tests/test_{{cookiecutter.package_name}}.py @@ -5,6 +5,7 @@ from django.test import TestCase from xblock.fields import ScopeIds from xblock.test.toy_runtime import ToyRuntime + from my_xblock import MyXBlock