Skip to content

Commit

Permalink
fix: test for runtime field data
Browse files Browse the repository at this point in the history
  • Loading branch information
irtazaakram committed Oct 25, 2023
1 parent a588282 commit cf3b5df
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions xblock/test/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
NoSuchHandlerError,
NoSuchServiceError,
NoSuchUsage,
NoSuchViewError
NoSuchViewError,
FieldDataDeprecationWarning,
)
from xblock.fields import BlockScope, Scope, String, ScopeIds, List, UserScope, Integer
from xblock.runtime import (
Expand All @@ -28,7 +29,7 @@
)
from xblock.field_data import DictFieldData, FieldData

from xblock.test.tools import unabc, TestRuntime
from xblock.test.tools import unabc, WarningTestMixin, TestRuntime


class TestMixin:
Expand Down Expand Up @@ -649,6 +650,28 @@ def test_missing_definition(self):
self.runtime.get_block(self.usage_id)


class TestRuntimeDeprecation(WarningTestMixin, TestCase):
"""
Tests to make sure that deprecated Runtime apis stay usable,
but raise warnings.
"""

def test_passed_field_data(self):
field_data = Mock(spec=FieldData)
with self.assertWarns(FieldDataDeprecationWarning):
runtime = TestRuntime(Mock(spec=IdReader), field_data=field_data)
with self.assertWarns(FieldDataDeprecationWarning):
self.assertEqual(runtime.field_data, field_data)

def test_set_field_data(self):
field_data = Mock(spec=FieldData)
runtime = TestRuntime(Mock(spec=IdReader), field_data=None)
with self.assertWarns(FieldDataDeprecationWarning):
runtime.field_data = field_data
with self.assertWarns(FieldDataDeprecationWarning):
self.assertEqual(runtime.field_data, field_data)


class RuntimeWithCustomCSS(TestRuntime): # pylint: disable=abstract-method
"""
A runtime that adds extra CSS classes to rendered XBlocks
Expand Down

0 comments on commit cf3b5df

Please sign in to comment.