Example #1
0
class TestReadOnlyFieldData(object):
    def setUp(self):
        self.source = Mock()
        self.read_only = ReadOnlyFieldData(self.source)
        self.block = TestingBlock(
            runtime=Mock(),
            field_data=self.read_only,
            scope_ids=Mock(),
        )

    def test_get(self):
        assert_equals(self.source.get.return_value, self.read_only.get(self.block, 'content'))
        self.source.get.assert_called_once_with(self.block, 'content')

    def test_set(self):
        with assert_raises(InvalidScopeError):
            self.read_only.set(self.block, 'content', 'foo')

    def test_delete(self):
        with assert_raises(InvalidScopeError):
            self.read_only.delete(self.block, 'content')

    def test_set_many(self):
        with assert_raises(InvalidScopeError):
            self.read_only.set_many(self.block, {'content': 'foo', 'settings': 'bar'})

    def test_default(self):
        assert_equals(self.source.default.return_value, self.read_only.default(self.block, 'content'))
        self.source.default.assert_called_once_with(self.block, 'content')

    def test_has(self):
        assert_equals(self.source.has.return_value, self.read_only.has(self.block, 'content'))
        self.source.has.assert_called_once_with(self.block, 'content')
Example #2
0
class TestReadOnlyFieldData:
    """
    Tests of :ref:`ReadOnlyFieldData`.
    """

    # pylint: disable=attribute-defined-outside-init
    def setup_method(self):
        """
        Setup for each test case in this class.
        """
        self.source = Mock()
        self.read_only = ReadOnlyFieldData(self.source)
        self.runtime = TestRuntime(services={'field-data': self.read_only})
        self.block = TestingBlock(
            runtime=self.runtime,
            scope_ids=Mock(),
        )

    # pylint: enable=attribute-defined-outside-init

    def test_get(self):
        assert self.source.get.return_value == self.read_only.get(
            self.block, 'content')
        self.source.get.assert_called_once_with(self.block, 'content')

    def test_set(self):
        with pytest.raises(InvalidScopeError):
            self.read_only.set(self.block, 'content', 'foo')

    def test_delete(self):
        with pytest.raises(InvalidScopeError):
            self.read_only.delete(self.block, 'content')

    def test_set_many(self):
        with pytest.raises(InvalidScopeError):
            self.read_only.set_many(self.block, {
                'content': 'foo',
                'settings': 'bar'
            })

    def test_default(self):
        assert self.source.default.return_value == self.read_only.default(
            self.block, 'content')
        self.source.default.assert_called_once_with(self.block, 'content')

    def test_has(self):
        assert self.source.has.return_value == self.read_only.has(
            self.block, 'content')
        self.source.has.assert_called_once_with(self.block, 'content')
Example #3
0
class TestReadOnlyFieldData(object):
    """
    Tests of :ref:`ReadOnlyFieldData`.
    """
    def setUp(self):
        self.source = Mock()
        self.read_only = ReadOnlyFieldData(self.source)
        self.block = TestingBlock(
            runtime=Mock(),
            field_data=self.read_only,
            scope_ids=Mock(),
        )

    def test_get(self):
        assert_equals(self.source.get.return_value,
                      self.read_only.get(self.block, 'content'))
        self.source.get.assert_called_once_with(self.block, 'content')

    def test_set(self):
        with assert_raises(InvalidScopeError):
            self.read_only.set(self.block, 'content', 'foo')

    def test_delete(self):
        with assert_raises(InvalidScopeError):
            self.read_only.delete(self.block, 'content')

    def test_set_many(self):
        with assert_raises(InvalidScopeError):
            self.read_only.set_many(self.block, {
                'content': 'foo',
                'settings': 'bar'
            })

    def test_default(self):
        assert_equals(self.source.default.return_value,
                      self.read_only.default(self.block, 'content'))
        self.source.default.assert_called_once_with(self.block, 'content')

    def test_has(self):
        assert_equals(self.source.has.return_value,
                      self.read_only.has(self.block, 'content'))
        self.source.has.assert_called_once_with(self.block, 'content')
Example #4
0
class TestReadOnlyFieldData(object):
    """
    Tests of :ref:`ReadOnlyFieldData`.
    """
    # pylint: disable=attribute-defined-outside-init
    def setup_method(self):
        """
        Setup for each test case in this class.
        """
        self.source = Mock()
        self.read_only = ReadOnlyFieldData(self.source)
        self.runtime = TestRuntime(services={'field-data': self.read_only})
        self.block = TestingBlock(
            runtime=self.runtime,
            scope_ids=Mock(),
        )
    # pylint: enable=attribute-defined-outside-init

    def test_get(self):
        assert self.source.get.return_value == self.read_only.get(self.block, 'content')
        self.source.get.assert_called_once_with(self.block, 'content')

    def test_set(self):
        with pytest.raises(InvalidScopeError):
            self.read_only.set(self.block, 'content', 'foo')

    def test_delete(self):
        with pytest.raises(InvalidScopeError):
            self.read_only.delete(self.block, 'content')

    def test_set_many(self):
        with pytest.raises(InvalidScopeError):
            self.read_only.set_many(self.block, {'content': 'foo', 'settings': 'bar'})

    def test_default(self):
        assert self.source.default.return_value == self.read_only.default(self.block, 'content')
        self.source.default.assert_called_once_with(self.block, 'content')

    def test_has(self):
        assert self.source.has.return_value == self.read_only.has(self.block, 'content')
        self.source.has.assert_called_once_with(self.block, 'content')