def reload_widgets(): """Reload the default classifiers and widgets.""" Classifier.delete_all_classifiers() Classifier.load_default_classifiers() Widget.delete_all_widgets() InteractiveWidget.load_default_widgets() NonInteractiveWidget.load_default_widgets()
def test_loading_and_deletion_of_classifiers(self): """Test loading and deletion of the default classifiers.""" self.assertEqual(Classifier.objects.count(), 0) Classifier.load_default_classifiers() classifiers = Classifier.objects.all() classifier_ids = [classifier.id for classifier in classifiers] self.assertIn('Coord2DClassifier', classifier_ids) self.assertEqual(classifiers.count(), 7) Classifier.delete_all_classifiers() self.assertEqual(Classifier.objects.count(), 0)
def test_parameterized_widget(self): """Test that parameterized widgets are correctly handled.""" self.assertEqual(InteractiveWidget.objects.count(), 0) Classifier.load_default_classifiers() InteractiveWidget.load_default_widgets() MUSIC_STAFF_ID = 'interactive-MusicStaff' widget = InteractiveWidget.get(MUSIC_STAFF_ID) self.assertEqual(widget.id, MUSIC_STAFF_ID) self.assertEqual(widget.name, 'Music staff') code = InteractiveWidget.get_raw_code(MUSIC_STAFF_ID) self.assertIn('GLOBALS.noteToGuess = JSON.parse(\'\\"', code) code = InteractiveWidget.get_raw_code(MUSIC_STAFF_ID, {'noteToGuess': 'abc'}) self.assertIn('GLOBALS.noteToGuess = JSON.parse(\'abc\');', code) # The get_with_params() method cannot be called directly on Widget. # It must be called on a subclass. with self.assertRaises(AttributeError): parameterized_widget_dict = Widget.get_with_params( MUSIC_STAFF_ID, {'noteToGuess': 'abc'}) with self.assertRaises(NotImplementedError): parameterized_widget_dict = Widget._get_with_params( MUSIC_STAFF_ID, {'noteToGuess': 'abc'}) parameterized_widget_dict = InteractiveWidget.get_with_params( MUSIC_STAFF_ID, {'noteToGuess': 'abc'}) self.assertItemsEqual(parameterized_widget_dict.keys(), [ 'id', 'name', 'category', 'description', 'template', 'static_template', 'params', 'handlers', 'raw']) self.assertEqual(parameterized_widget_dict['id'], MUSIC_STAFF_ID) self.assertIn('GLOBALS.noteToGuess = JSON.parse(\'abc\');', parameterized_widget_dict['raw']) self.assertEqual(parameterized_widget_dict['params'], {'noteToGuess': 'abc'}) InteractiveWidget.delete_all_widgets()
def setUp(self): """Loads the default classifiers.""" Classifier.load_default_classifiers()