本文整理汇总了Python中models.settings.course_metadata.CourseMetadata.validate_and_update_from_json方法的典型用法代码示例。如果您正苦于以下问题:Python CourseMetadata.validate_and_update_from_json方法的具体用法?Python CourseMetadata.validate_and_update_from_json怎么用?Python CourseMetadata.validate_and_update_from_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.settings.course_metadata.CourseMetadata
的用法示例。
在下文中一共展示了CourseMetadata.validate_and_update_from_json方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_validate_and_update_from_json_wrong_inputs
# 需要导入模块: from models.settings.course_metadata import CourseMetadata [as 别名]
# 或者: from models.settings.course_metadata.CourseMetadata import validate_and_update_from_json [as 别名]
def test_validate_and_update_from_json_wrong_inputs(self):
# input incorrectly formatted data
is_valid, errors, test_model = CourseMetadata.validate_and_update_from_json(
self.course,
{
"advertised_start": {"value": 1, "display_name": "Course Advertised Start Date", },
"days_early_for_beta": {"value": "supposed to be an integer",
"display_name": "Days Early for Beta Users", },
"advanced_modules": {"value": 1, "display_name": "Advanced Module List", },
},
user=self.user
)
# Check valid results from validate_and_update_from_json
self.assertFalse(is_valid)
self.assertEqual(len(errors), 3)
self.assertFalse(test_model)
error_keys = set([error_obj['model']['display_name'] for error_obj in errors])
test_keys = set(['Advanced Module List', 'Course Advertised Start Date', 'Days Early for Beta Users'])
self.assertEqual(error_keys, test_keys)
# try fresh fetch to ensure no update happened
fresh = modulestore().get_course(self.course.id)
test_model = CourseMetadata.fetch(fresh)
self.assertNotEqual(test_model['advertised_start']['value'], 1, 'advertised_start should not be updated to a wrong value')
self.assertNotEqual(test_model['days_early_for_beta']['value'], "supposed to be an integer",
'days_early_for beta should not be updated to a wrong value')
示例2: test_validate_update_filtered_edxnotes_on
# 需要导入模块: from models.settings.course_metadata import CourseMetadata [as 别名]
# 或者: from models.settings.course_metadata.CourseMetadata import validate_and_update_from_json [as 别名]
def test_validate_update_filtered_edxnotes_on(self):
"""
If feature flag is on, then edxnotes must not be filtered.
"""
# pylint: disable=unused-variable
is_valid, errors, test_model = CourseMetadata.validate_and_update_from_json(
self.course,
{
"edxnotes": {"value": "true"},
},
user=self.user
)
self.assertIn('edxnotes', test_model)
示例3: test_validate_update_filtered_on
# 需要导入模块: from models.settings.course_metadata import CourseMetadata [as 别名]
# 或者: from models.settings.course_metadata.CourseMetadata import validate_and_update_from_json [as 别名]
def test_validate_update_filtered_on(self):
"""
If feature flag is on, then giturl must not be filtered.
"""
# pylint: disable=unused-variable
is_valid, errors, test_model = CourseMetadata.validate_and_update_from_json(
self.course,
{
"giturl": {"value": "http://example.com"},
},
user=self.user
)
self.assertIn('giturl', test_model)
示例4: test_validate_from_json_correct_inputs
# 需要导入模块: from models.settings.course_metadata import CourseMetadata [as 别名]
# 或者: from models.settings.course_metadata.CourseMetadata import validate_and_update_from_json [as 别名]
def test_validate_from_json_correct_inputs(self):
is_valid, errors, test_model = CourseMetadata.validate_and_update_from_json(
self.course,
{
"advertised_start": {"value": "start A"},
"days_early_for_beta": {"value": 2},
"advanced_modules": {"value": ['combinedopenended']},
},
user=self.user
)
self.assertTrue(is_valid)
self.assertTrue(len(errors) == 0)
self.update_check(test_model)
# Tab gets tested in test_advanced_settings_munge_tabs
self.assertIn('advanced_modules', test_model, 'Missing advanced_modules')
self.assertEqual(test_model['advanced_modules']['value'], ['combinedopenended'], 'advanced_module is not updated')
示例5: test_validate_and_update_from_json_correct_inputs
# 需要导入模块: from models.settings.course_metadata import CourseMetadata [as 别名]
# 或者: from models.settings.course_metadata.CourseMetadata import validate_and_update_from_json [as 别名]
def test_validate_and_update_from_json_correct_inputs(self):
is_valid, errors, test_model = CourseMetadata.validate_and_update_from_json(
self.course,
{
"advertised_start": {"value": "start A"},
"days_early_for_beta": {"value": 2},
"advanced_modules": {"value": ["combinedopenended"]},
},
user=self.user,
)
self.assertTrue(is_valid)
self.assertTrue(len(errors) == 0)
self.update_check(test_model)
# fresh fetch to ensure persistence
fresh = modulestore().get_course(self.course.id)
test_model = CourseMetadata.fetch(fresh)
self.update_check(test_model)
# Tab gets tested in test_advanced_settings_munge_tabs
self.assertIn("advanced_modules", test_model, "Missing advanced_modules")
self.assertEqual(
test_model["advanced_modules"]["value"], ["combinedopenended"], "advanced_module is not updated"
)