def test_removeDefault(self): s = models.getModelSource('simple_test_type') self.assertIn('<defaultFactory>collective.ambidexterity.default</defaultFactory>', s) models.removeDefaultFactory('simple_test_type', 'test_integer_field') models.removeDefaultFactory('simple_test_type', 'test_string_field') s = models.getModelSource('simple_test_type') self.assertNotIn('<defaultFactory>collective.ambidexterity.default</defaultFactory>', s)
def test_schemaChangeSubscriber(self): # damage the FTI models.removeDefaultFactory('simple_test_type', 'test_string_field') # audit: we expect a problem self.assertFalse(audit.auditIsClean(audit.auditResourceModelMatch())) # Notify our subscriber that the schema has changed notify(SchemaModifiedEvent(self.portal.portal_types.simple_test_type)) # Now, we expect a clean audit self.assertTrue(audit.auditIsClean(audit.auditResourceModelMatch()))
def test_readableReportWithModelErrors(self): # destroy synchronization. models.removeAmbidexterityView('simple_test_type') models.removeDefaultFactory('simple_test_type', 'test_string_field') models.removeValidator('simple_test_type', 'test_string_field') models.removeVocabulary('simple_test_type', 'test_choice_field') report = audit.readableAuditReport() # Now, we should have an example of every FTI warning message. errors = [ audit.NO_VIEW_IN_FTI, audit.NO_DEFAULT_IN_FTI, audit.NO_VALIDATOR_IN_FTI, audit.NO_VOCABULARY_IN_FTI, ] for err in errors: self.assertIn(audit.WARNING_MESSAGES[err], report)
def test_auditFailFTI(self): # damage synchronization models.removeAmbidexterityView('simple_test_type') models.removeDefaultFactory('simple_test_type', 'test_string_field') models.removeValidator('simple_test_type', 'test_string_field') models.removeVocabulary('simple_test_type', 'test_choice_field') arez = audit.auditResourceModelMatch() self.assertFalse(audit.auditIsClean(arez)) # and, check the details self.assertEqual(arez['simple_test_type']['problems'], [audit.NO_VIEW_IN_FTI]) self.assertEqual( arez['simple_test_type']['fields']['test_string_field'], [audit.NO_DEFAULT_IN_FTI, audit.NO_VALIDATOR_IN_FTI]) self.assertEqual( arez['simple_test_type']['fields']['test_choice_field'], [audit.NO_VOCABULARY_IN_FTI])
def test_resynchronize(self): # damage fti in all available ways models.removeAmbidexterityView('simple_test_type') models.removeDefaultFactory('simple_test_type', 'test_string_field') models.removeValidator('simple_test_type', 'test_string_field') models.removeVocabulary('simple_test_type', 'test_choice_field') audit.resynchronize_all() self.assertTrue(audit.auditIsClean(audit.auditResourceModelMatch())) # Remove all our scripts and templates view.rmViewTemplate('simple_test_type', ) default_script.rmDefaultScript('simple_test_type', 'test_string_field') validator_script.rmValidatorScript('simple_test_type', 'test_string_field') vocabulary_script.rmVocabularyScript('simple_test_type', 'test_choice_field') audit.resynchronize_all() report = audit.auditResourceModelMatch() self.assertTrue(audit.auditIsClean(report))
def button_action(self): """ Respond to button clicks. """ PostOnly(self.request) CheckAuthenticator(self.request) form = self.request.form button_id = form['button_id'] content_type = form['content_type'] field_name = form['field_name'] result = {} if button_id == 'add_default': default_script.addDefaultScript(content_type, field_name) models.setDefaultFactory(content_type, field_name) elif button_id == 'remove_default': default_script.rmDefaultScript(content_type, field_name) models.removeDefaultFactory(content_type, field_name) elif button_id == 'edit_default': result = dict( action='edit', source=getAmbidexterityFile(content_type, field_name, 'default.py'), ) elif button_id == 'add_validator': validator_script.addValidatorScript(content_type, field_name) models.setValidator(content_type, field_name) elif button_id == 'remove_validator': validator_script.rmValidatorScript(content_type, field_name) models.removeValidator(content_type, field_name) elif button_id == 'edit_validator': result = dict( action='edit', source=getAmbidexterityFile(content_type, field_name, 'validate.py'), ) elif button_id == 'add_vocabulary': vocabulary_script.addVocabularyScript(content_type, field_name) models.setVocabulary(content_type, field_name) elif button_id == 'remove_vocabulary': vocabulary_script.rmVocabularyScript(content_type, field_name) models.removeVocabulary(content_type, field_name) elif button_id == 'edit_vocabulary': result = dict( action='edit', source=getAmbidexterityFile(content_type, field_name, 'vocabulary.py'), ) elif button_id == 'add_view': ad_view.addViewTemplate(content_type) models.setAmbidexterityView(content_type) elif button_id == 'edit_view': result = dict( action='edit', source=getAmbidexterityFile(content_type, None, 'view.pt'), ) elif button_id == 'remove_view': ad_view.rmViewTemplate(content_type) models.removeAmbidexterityView(content_type) self.request.RESPONSE.setHeader('Content-Type', 'application/json') self.request.RESPONSE.setHeader('Cache-Control', 'no-cache') return json.dumps(result)