def test_readableReportWithResourcesMissing(self): # destroy synchronization. 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') report = audit.readableAuditReport() # Now, we should have an example of every resource warning message. resource_errors = [ audit.VIEW_TEMPLATE_MISSING, audit.DEFAULT_SCRIPT_MISSING, audit.VALIDATOR_SCRIPT_MISSING, audit.VOCABULARY_SCRIPT_MISSING, ] for err in resource_errors: self.assertIn(audit.WARNING_MESSAGES[err], report)
def test_auditFailMissingResources(self): # damage synchronization 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') # and check audit results arez = audit.auditResourceModelMatch() self.assertFalse(audit.auditIsClean(arez)) self.assertEqual(arez['simple_test_type']['problems'], [audit.VIEW_TEMPLATE_MISSING]) self.assertEqual( arez['simple_test_type']['fields']['test_string_field'], [audit.DEFAULT_SCRIPT_MISSING, audit.VALIDATOR_SCRIPT_MISSING]) self.assertEqual( arez['simple_test_type']['fields']['test_choice_field'], [audit.VOCABULARY_SCRIPT_MISSING])
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)
def test_rm_vocabulary_script(self): addVocabularyScript('simple_test_type', 'test_choice_field') rmVocabularyScript('simple_test_type', 'test_choice_field') with self.assertRaises(KeyError): getAmbidexterityFile('simple_test_type', 'test_choice_field', 'vocabulary.py')