def test_inheritable_attribute(self): # days_early_for_beta isn't a basic attribute of Sequence assert_false(hasattr(SequenceDescriptor, 'days_early_for_beta')) # days_early_for_beta is added by InheritanceMixin assert_true(hasattr(InheritanceMixin, 'days_early_for_beta')) root = SequenceFactory.build(policy={'days_early_for_beta': '2'}) ProblemFactory.build(parent=root) # InheritanceMixin will be used when processing the XML assert_in(InheritanceMixin, root.xblock_mixins) seq = self.process_xml(root) assert_equals(seq.unmixed_class, SequenceDescriptor) assert_not_equals(type(seq), SequenceDescriptor) # days_early_for_beta is added to the constructed sequence, because # it's in the InheritanceMixin assert_equals(2, seq.days_early_for_beta) # days_early_for_beta is a known attribute, so we shouldn't include it # in xml_attributes assert_not_in('days_early_for_beta', seq.xml_attributes)
def check_inheritable_attribute(self, attribute, value): # `attribute` isn't a basic attribute of Sequence assert_false(hasattr(SequenceDescriptor, attribute)) # `attribute` is added by InheritanceMixin assert_true(hasattr(InheritanceMixin, attribute)) root = SequenceFactory.build(policy={attribute: str(value)}) ProblemFactory.build(parent=root) # InheritanceMixin will be used when processing the XML assert_in(InheritanceMixin, root.xblock_mixins) seq = self.process_xml(root) assert_equals(seq.unmixed_class, SequenceDescriptor) assert_not_equals(type(seq), SequenceDescriptor) # `attribute` is added to the constructed sequence, because # it's in the InheritanceMixin assert_equals(value, getattr(seq, attribute)) # `attribute` is a known attribute, so we shouldn't include it # in xml_attributes assert_not_in(attribute, seq.xml_attributes)
def check_inheritable_attribute(self, attribute, value): # `attribute` isn't a basic attribute of Sequence assert not hasattr(SequenceDescriptor, attribute) # `attribute` is added by InheritanceMixin assert hasattr(InheritanceMixin, attribute) root = SequenceFactory.build(policy={attribute: str(value)}) ProblemFactory.build(parent=root) # InheritanceMixin will be used when processing the XML assert InheritanceMixin in root.xblock_mixins seq = self.process_xml(root) assert seq.unmixed_class == SequenceDescriptor assert type(seq) != SequenceDescriptor # `attribute` is added to the constructed sequence, because # it's in the InheritanceMixin assert getattr(seq, attribute) == value # `attribute` is a known attribute, so we shouldn't include it # in xml_attributes assert attribute not in seq.xml_attributes
def test_video_attr(self): """ Test that video's definition_from_xml handles unknown attrs w/o choking """ # Fixes LMS-11491 root = CourseFactory.build() sequence = SequenceFactory.build(parent=root) video = XmlImportFactory( parent=sequence, tag="video", attribs={"parent_url": "foo", "garbage": "asdlk", "download_video": "true"} ) video_block = self.process_xml(video) assert_in("garbage", video_block.xml_attributes)
def test_rerandomize_in_policy(self): # Rerandomize isn't a basic attribute of Sequence assert_false(hasattr(SequenceDescriptor, 'rerandomize')) root = SequenceFactory.build(policy={'rerandomize': 'never'}) ProblemFactory.build(parent=root) seq = self.process_xml(root) # Rerandomize is added to the constructed sequence via the InheritanceMixin assert_equals('never', seq.rerandomize) # Rerandomize is a known value coming from policy, and shouldn't appear # in xml_attributes assert_not_in('rerandomize', seq.xml_attributes)
def test_null_string(self): # Test that the string inherited fields are passed through 'deserialize_field', # which converts the string "null" to the python value None root = CourseFactory.build(days_early_for_beta="null") sequence = SequenceFactory.build(parent=root) ProblemFactory.build(parent=sequence) course = self.process_xml(root) assert_equals(None, course.days_early_for_beta) sequence = course.get_children()[0] assert_equals(None, sequence.days_early_for_beta) problem = sequence.get_children()[0] assert_equals(None, problem.days_early_for_beta)
def test_rerandomize_in_policy(self): # Rerandomize isn't a basic attribute of Sequence assert not hasattr(SequenceBlock, 'rerandomize') root = SequenceFactory.build(policy={'rerandomize': 'never'}) ProblemFactory.build(parent=root) seq = self.process_xml(root) # Rerandomize is added to the constructed sequence via the InheritanceMixin assert seq.rerandomize == 'never' # Rerandomize is a known value coming from policy, and shouldn't appear # in xml_attributes assert 'rerandomize' not in seq.xml_attributes
def test_video_attr(self): """ Test that video's definition_from_xml handles unknown attrs w/o choking """ # Fixes LMS-11491 root = CourseFactory.build() sequence = SequenceFactory.build(parent=root) video = XmlImportFactory(parent=sequence, tag='video', attribs={ 'parent_url': 'foo', 'garbage': 'asdlk', 'download_video': 'true', }) video_block = self.process_xml(video) assert 'garbage' in video_block.xml_attributes
def test_attempts_in_policy(self): # attempts isn't a basic attribute of Sequence assert_false(hasattr(SequenceDescriptor, 'attempts')) root = SequenceFactory.build(policy={'attempts': '1'}) ProblemFactory.build(parent=root) seq = self.process_xml(root) # attempts isn't added to the constructed sequence, because # it's not in the InheritanceMixin assert_false(hasattr(seq, 'attempts')) # attempts is an unknown attribute, so we should include it # in xml_attributes so that it gets written out (despite the misleading # name) assert_in('attempts', seq.xml_attributes)
def test_video_attr(self): """ Test that video's definition_from_xml handles unknown attrs w/o choking """ # Fixes LMS-11491 root = CourseFactory.build() sequence = SequenceFactory.build(parent=root) video = XmlImportFactory( parent=sequence, tag='video', attribs={ 'parent_url': 'foo', 'garbage': 'asdlk', 'download_video': 'true', } ) video_block = self.process_xml(video) assert 'garbage' in video_block.xml_attributes