Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add unit test to xblock so there is a coverage file to upload #426

Merged
merged 7 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
**********
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Tests for {{cookiecutter.class_name}}
"""

from django.test import TestCase
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()
as_dict = frag.to_dict()
content = as_dict['content']
self.assertIn('MyXBlock: count is now', content, 'XBlock did not render correct student view')
5 changes: 4 additions & 1 deletion cookiecutter-xblock/{{cookiecutter.repo_name}}/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -40,7 +40,10 @@ 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}

[testenv:docs]
Expand Down