Skip to content

Commit

Permalink
fix: add unit test to xblock so there is a coverage file to upload (#426
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Rebecca Graber authored Dec 18, 2023
1 parent 2915cb8 commit b3ad3b4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Changed
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

0 comments on commit b3ad3b4

Please sign in to comment.