def test_validator_adds_dependency_for_discretionary_fields( discretionary_field, expected_required_field): g11_content = content_loader.get_builder('g-cloud-11', 'declaration') g11_submission = {discretionary_field: True} validator = get_validator({"slug": 'g-cloud-11'}, g11_content, g11_submission) required_fields = validator.get_required_fields() assert expected_required_field in required_fields
def test_dependent_questions_still_error_with_answer_required(values): content = content_loader.get_builder('g-cloud-12', 'declaration') g12_declaration = get_g12_declaration(**values) errors = get_validator({ 'slug': 'g-cloud-12' }, content, g12_declaration).errors() assert 'dependent_question_error' not in errors.values() assert 'answer_required' in errors.values()
def test_dependent_questions_do_not_error_when_at_least_one_positive(values): content = content_loader.get_builder('g-cloud-12', 'declaration') g12_declaration = get_g12_declaration(**values) errors = get_validator({ 'slug': 'g-cloud-12' }, content, g12_declaration).errors() with pytest.raises(KeyError, match='servicesHaveOrSupportCloudHostingCloudSoftware'): errors['servicesHaveOrSupportCloudHostingCloudSoftware'] with pytest.raises(KeyError, match='servicesHaveOrSupportCloudSupport'): errors['servicesHaveOrSupportCloudSupport']
def test_validator_handles_multiquestion_fields(framework_slug): # Currently only DOS4 and G11 have multiquestion declaration questions (for modernSlavery) g11_content = content_loader.get_builder(framework_slug, 'declaration') g11_submission = { "modernSlaveryTurnover": True, "modernSlaveryReportingRequirements": False, } validator = get_validator({"slug": framework_slug}, g11_content, g11_submission) required_fields = validator.get_required_fields() assert 'mitigatingFactors3' in required_fields assert 'modernSlaveryStatement' not in required_fields
def test_word_limit_errors(dos4_submission): content = content_loader.get_builder('digital-outcomes-and-specialists-4', 'declaration') textbox_fields = [ "mitigatingFactors", "mitigatingFactors2", ] for field in textbox_fields: dos4_submission[field] = "a " * 501 validator = SharedValidator(content, dos4_submission) assert validator.errors() == {field: "under_word_limit"} dos4_submission[field] = "a " * 500 validator = SharedValidator(content, dos4_submission) assert validator.errors() == {}
def test_other_field_validation_still_works(): content = content_loader.get_builder('g-cloud-12', 'declaration') g12_declaration = get_g12_declaration( servicesHaveOrSupportCloudHostingCloudSoftware= ("My organisation isn't submitting cloud hosting (lot 1) or cloud software (lot 2) services" ), servicesHaveOrSupportCloudSupport= "My organisation isn't submitting cloud support (lot 3) services", servicesDoNotInclude=None, ) errors = get_validator({ 'slug': 'g-cloud-12' }, content, g12_declaration).errors() assert errors['servicesDoNotInclude'] == 'answer_required'
def test_validator_includes_dependent_fields(framework_slug, licence_type): content = content_loader.get_builder(framework_slug, 'declaration') submission = { "tradingStatus": "other (please specify)", "establishedInTheUK": False, "appropriateTradeRegisters": True, "licenceOrMemberRequired": licence_type } validator = get_validator({"slug": framework_slug}, content, submission) required_fields = validator.get_required_fields() for expected_dependent_field in [ "tradingStatusOther", "appropriateTradeRegisters", "appropriateTradeRegistersNumber", "licenceOrMemberRequiredDetails" ]: assert expected_dependent_field in required_fields
def test_dependent_questions_both_error_when_both_negative(): content = content_loader.get_builder('g-cloud-12', 'declaration') g12_declaration = get_g12_declaration( servicesHaveOrSupportCloudHostingCloudSoftware= ("My organisation isn't submitting cloud hosting (lot 1) or cloud software (lot 2) services" ), servicesHaveOrSupportCloudSupport= "My organisation isn't submitting cloud support (lot 3) services", ) errors = get_validator({ 'slug': 'g-cloud-12' }, content, g12_declaration).errors() assert errors[ 'servicesHaveOrSupportCloudHostingCloudSoftware'] == 'dependent_question_error' assert errors[ 'servicesHaveOrSupportCloudSupport'] == 'dependent_question_error'
def content(): return content_loader.get_builder('g-cloud-8', 'declaration')
def content(): return content_loader.get_builder('digital-outcomes-and-specialists', 'declaration')