def test_wrapped_fielddata(self):
     defaults = mock.MagicMock()
     dfd1 = field_data.DateLookupFieldData(defaults,
                                           course_id=self.course_id,
                                           use_cached=False,
                                           user=self.user)
     dfd2 = field_data.DateLookupFieldData(dfd1,
                                           course_id=self.course_id,
                                           user=self.user)
     assert dfd1._defaults == dfd2._defaults  # pylint: disable=protected-access
    def test_field_data_get(self):
        defaults = mock.MagicMock()
        dfd = field_data.DateLookupFieldData(defaults,
                                             course_id=self.course_id,
                                             use_cached=False,
                                             user=self.user)
        block = MockBlock(self.items[0][0])

        date = dfd.get(block, 'due')
        assert date == self.items[0][1]['due']

        # non-date
        dfd.get(block, b'foo')
        assert defaults.get.called_once_with(block.location, 'foo')

        # non-existent value
        defaults.has.return_value = False
        badblock = MockBlock('foo')
        assert dfd.has(badblock, 'foo') is False

        # block with parent with date
        child = MockBlock('child', block)
        date = dfd.get(child, 'due')
        assert dfd.get(child, 'due') is defaults.get(child, 'due')
        assert dfd.default(child, 'due') == self.items[0][1]['due']

        assert dfd.get(badblock, 'due') is defaults.get(badblock, 'due')
 def test_field_data_set_delete(self):
     defaults = mock.MagicMock()
     dfd = field_data.DateLookupFieldData(defaults,
                                          course_id=self.course_id,
                                          use_cached=False,
                                          user=self.user)
     dfd.set('foo', 'bar', 'x')
     assert defaults.called_once_with('foo', 'bar', 'x')
     dfd.delete('baz', 'boing')
     assert defaults.called_once_with('baz', 'boing')
Esempio n. 4
0
    def test_field_data_has(self):
        defaults = mock.MagicMock()
        dfd = field_data.DateLookupFieldData(defaults,
                                             course_id=self.course_id,
                                             use_cached=False,
                                             user=self.user)
        block = MockBlock(self.items[0][0])

        assert dfd.has(block, 'due') is True
        assert dfd.has(block, 'foo') is defaults.has(block, 'foo')
        child = MockBlock('child', block)
        assert dfd.has(child, 'due') is False
        assert dfd.default(child, 'due') == self.items[0][1]['due']
        assert dfd.default(child, 'foo') is defaults.default(child, 'foo')