Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:unicef/etools into ch33354-UNICE…
Browse files Browse the repository at this point in the history
…F-cash-unfunded
  • Loading branch information
emaciupe committed Jun 14, 2023
2 parents 665077f + c0b8fab commit 7d27a6d
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 18 deletions.
8 changes: 7 additions & 1 deletion src/etools/applications/audit/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ def labels(self):
lambda c: c.blueprints.all(),
RiskCategory.objects.get(code='ma_subject_areas', parent__isnull=True).children.all()
)):
labels['subject_areas.{}'.format(blueprint.id)] = 'Tested Subject Areas - {}'.format(blueprint.header)
labels['subject_areas.{}'.format(blueprint.id)] = 'Tested Subject Areas v1 - {}'.format(blueprint.header)

for blueprint in itertools.chain(*map(
lambda c: c.blueprints.all(),
RiskCategory.objects.get(code='ma_subject_areas_v2', parent__isnull=True).children.all()
)):
labels['subject_areas_v2.{}'.format(blueprint.id)] = 'Tested Subject Areas v2 - {}'.format(blueprint.header)

for blueprint in itertools.chain(*map(
lambda c: itertools.chain(
Expand Down
7 changes: 7 additions & 0 deletions src/etools/applications/audit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,13 @@ def get_questionnaire_code(version: int):
2: 'ma_questionnaire_v2'
}[version]

@staticmethod
def get_subject_areas_code(version: int):
return {
1: 'ma_subject_areas',
2: 'ma_subject_areas_v2'
}[version]

@transition(
'status',
source=Engagement.STATUSES.partner_contacted, target=Engagement.STATUSES.report_submitted,
Expand Down
3 changes: 2 additions & 1 deletion src/etools/applications/audit/serializers/engagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ class MicroAssessmentSerializer(ActivePDValidationMixin, RiskCategoriesUpdateMix
required=False,
)
test_subject_areas = RiskRootSerializer(
code='ma_subject_areas', required=False, label=_('Tested Subject Areas')
lambda ma: MicroAssessment.get_subject_areas_code(ma.questionnaire_version),
required=False, label=_('Tested Subject Areas')
)
overall_risk_assessment = RiskRootSerializer(
code='ma_global_assessment', required=False, label=_('Overall Risk Assessment'),
Expand Down
13 changes: 12 additions & 1 deletion src/etools/applications/audit/serializers/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class MicroAssessmentPDFSerializer(EngagementPDFSerializer):
required=False,
)
test_subject_areas = RiskRootSerializer(
code='ma_subject_areas', required=False, label=_('Tested Subject Areas')
lambda ma: MicroAssessment.get_subject_areas_code(ma.questionnaire_version),
required=False, label=_('Tested Subject Areas')
)
overall_risk_assessment = RiskRootSerializer(
code='ma_global_assessment', required=False, label=_('Overall Risk Assessment')
Expand Down Expand Up @@ -312,6 +313,7 @@ def get_subject_area(self, obj):
class MicroAssessmentDetailCSVSerializer(EngagementBaseDetailCSVSerializer):
overall_risk_assessment = serializers.SerializerMethodField()
subject_areas = serializers.SerializerMethodField()
subject_areas_v2 = serializers.SerializerMethodField()
questionnaire = serializers.SerializerMethodField()
questionnaire_v2 = serializers.SerializerMethodField()

Expand All @@ -331,6 +333,15 @@ def get_subject_areas(self, obj):
for b in itertools.chain(*map(lambda c: c['blueprints'], subject_areas['children']))
)

def get_subject_areas_v2(self, obj):
serializer = RiskRootSerializer(code='ma_subject_areas_v2')
subject_areas = serializer.to_representation(serializer.get_attribute(instance=obj))

return OrderedDict(
(b['id'], b['risk']['value_display'] if b['risk'] else 'N/A')
for b in itertools.chain(*map(lambda c: c['blueprints'], subject_areas['children']))
)

def get_questionnaire(self, obj):
serializer = AggregatedRiskRootSerializer(code='ma_questionnaire')
questionnaire = serializer.to_representation(serializer.get_attribute(instance=obj))
Expand Down
13 changes: 5 additions & 8 deletions src/etools/applications/audit/tests/test_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ class MATransitionsTestCaseMixin(EngagementTransitionsTestCaseMixin):

def _init_filled_engagement(self):
super()._init_filled_engagement()
self._fill_category('ma_questionnaire')
self._fill_category('ma_questionnaire_v2')
self._fill_category('ma_subject_areas', extra={"comments": "some info"})
self._fill_category('ma_subject_areas_v2', extra={"comments": "some info"})
self._fill_category('ma_global_assessment', extra={"comments": "some info"})


Expand Down Expand Up @@ -125,22 +124,20 @@ def test_submit_for_dummy_object(self):
def test_filled_questionnaire(self):
self._fill_date_fields()
self._test_submit(self.auditor, status.HTTP_400_BAD_REQUEST,
errors=['test_subject_areas', 'overall_risk_assessment', 'questionnaire'])
errors=['overall_risk_assessment', 'questionnaire', 'test_subject_areas'])

def test_missing_comments_subject_areas(self):
self._fill_date_fields()
self._fill_category('ma_questionnaire')
self._fill_category('ma_questionnaire_v2')
self._fill_category('ma_subject_areas')
self._fill_category('ma_subject_areas_v2')
self._fill_category('ma_global_assessment')
self._test_submit(self.auditor, status.HTTP_400_BAD_REQUEST,
errors=['test_subject_areas', 'overall_risk_assessment'])
errors=['overall_risk_assessment', 'test_subject_areas'])

def test_attachments_required(self):
self._fill_date_fields()
self._fill_category('ma_questionnaire')
self._fill_category('ma_questionnaire_v2')
self._fill_category('ma_subject_areas', extra={"comments": "some info"})
self._fill_category('ma_subject_areas_v2', extra={"comments": "some info"})
self._fill_category('ma_global_assessment', extra={"comments": "some info"})
self._test_submit(self.auditor, status.HTTP_400_BAD_REQUEST, errors=['report_attachments'])

Expand Down
4 changes: 2 additions & 2 deletions src/etools/applications/audit/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_ma_risks(self):
allowed_user=self.auditor
)
self._test_engagement_categories(
category_code='ma_subject_areas', field_name='test_subject_areas',
category_code='ma_subject_areas_v2', field_name='test_subject_areas',
allowed_user=self.auditor
)

Expand All @@ -253,7 +253,7 @@ def test_update_unexisted_blueprint(self):
allowed_user=self.auditor
)
self._update_unexisted_blueprint(
field_name='test_subject_areas', category_code='ma_subject_areas',
field_name='test_subject_areas', category_code='ma_subject_areas_v2',
allowed_user=self.auditor
)

Expand Down
21 changes: 16 additions & 5 deletions src/etools/applications/audit/transitions/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ def get_errors(self, instance, fields_to_check=None, *args, **kwargs):


class ValidateRiskExtra(BaseTransitionCheck):
VALIDATE_CATEGORIES = {}
VALIDATE_CATEGORIES_BEFORE_SUBMIT = {}
REQUIRED_EXTRA_FIELDS = []

def get_categories_to_validate_before_submit(self, instance):
return self.VALIDATE_CATEGORIES_BEFORE_SUBMIT

def get_errors(self, instance, *args, **kwargs):
errors = super().get_errors(*args, **kwargs)

for code, category in self.VALIDATE_CATEGORIES.items():
categories_to_validate = self.get_categories_to_validate_before_submit(instance)

for code, category in categories_to_validate.items():
answers = instance.risks.filter(blueprint__category__code=code)
for answer in answers:
extra_errors = {}
Expand Down Expand Up @@ -151,7 +156,6 @@ class AuditSubmitReportRequiredFieldsCheck(EngagementSubmitReportRequiredFieldsC

class ValidateMARiskCategories(ValidateRiskCategories):
VALIDATE_CATEGORIES_BEFORE_SUBMIT = {
'ma_subject_areas': 'test_subject_areas',
'ma_global_assessment': 'overall_risk_assessment',
}

Expand All @@ -160,12 +164,19 @@ def get_categories_to_validate_before_submit(self, instance):

categories = self.VALIDATE_CATEGORIES_BEFORE_SUBMIT
categories[MicroAssessment.get_questionnaire_code(instance.questionnaire_version)] = 'questionnaire'
categories[MicroAssessment.get_subject_areas_code(instance.questionnaire_version)] = 'test_subject_areas'
return categories


class ValidateMARiskExtra(ValidateRiskExtra):
VALIDATE_CATEGORIES = {
'ma_subject_areas': 'test_subject_areas',
VALIDATE_CATEGORIES_BEFORE_SUBMIT = {
'ma_global_assessment': 'overall_risk_assessment',
}
REQUIRED_EXTRA_FIELDS = ['comments']

def get_categories_to_validate_before_submit(self, instance):
from etools.applications.audit.models import MicroAssessment

categories = self.VALIDATE_CATEGORIES_BEFORE_SUBMIT
categories[MicroAssessment.get_subject_areas_code(instance.questionnaire_version)] = 'test_subject_areas'
return categories
171 changes: 171 additions & 0 deletions src/etools/applications/core/data/audit_risks_blueprints.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
"code": "ma_subject_areas"
}
},
{
"model": "audit.riskcategory",
"pk": 400,
"fields": {
"order": 1,
"header": "Tested Subject Areas",
"parent": null,
"category_type": "primary",
"code": "ma_subject_areas_v2"
}
},
{
"model": "audit.riskcategory",
"pk": 11,
Expand Down Expand Up @@ -3165,5 +3176,165 @@
"header": "Procurement",
"category": 38
}
},
{
"model": "audit.riskcategory",
"pk": 401,
"fields": {
"order": 0,
"header": "Organisation",
"parent": 400,
"category_type": "default",
"code": "ma_subject_areas_v2"
}
},
{
"model": "audit.riskblueprint",
"pk": 401,
"fields": {
"order": 0,
"header": "Organisation",
"category": 401
}
},
{
"model": "audit.riskcategory",
"pk": 402,
"fields": {
"order": 1,
"header": "People and behaviours",
"parent": 400,
"category_type": "default",
"code": "ma_subject_areas_v2"
}
},
{
"model": "audit.riskblueprint",
"pk": 402,
"fields": {
"order": 0,
"header": "People and behaviours",
"category": 402
}
},
{
"model": "audit.riskcategory",
"pk": 403,
"fields": {
"order": 2,
"header": "Activities",
"parent": 400,
"category_type": "default",
"code": "ma_subject_areas_v2"
}
},
{
"model": "audit.riskblueprint",
"pk": 403,
"fields": {
"order": 0,
"header": "Activities",
"category": 403
}
},
{
"model": "audit.riskcategory",
"pk": 404,
"fields": {
"order": 3,
"header": "Reporting and accountability",
"parent": 400,
"category_type": "default",
"code": "ma_subject_areas_v2"
}
},
{
"model": "audit.riskblueprint",
"pk": 404,
"fields": {
"order": 0,
"header": "Reporting and accountability",
"category": 404
}
},
{
"model": "audit.riskcategory",
"pk": 405,
"fields": {
"order": 4,
"header": "Assets and inventory",
"parent": 400,
"category_type": "default",
"code": "ma_subject_areas_v2"
}
},
{
"model": "audit.riskblueprint",
"pk": 405,
"fields": {
"order": 0,
"header": "Assets and inventory",
"category": 405
}
},
{
"model": "audit.riskcategory",
"pk": 406,
"fields": {
"order": 5,
"header": "Procurement",
"parent": 400,
"category_type": "default",
"code": "ma_subject_areas_v2"
}
},
{
"model": "audit.riskblueprint",
"pk": 406,
"fields": {
"order": 0,
"header": "Procurement",
"category": 406
}
},
{
"model": "audit.riskcategory",
"pk": 407,
"fields": {
"order": 6,
"header": "Sub-partners",
"parent": 400,
"category_type": "default",
"code": "ma_subject_areas_v2"
}
},
{
"model": "audit.riskblueprint",
"pk": 407,
"fields": {
"order": 0,
"header": "Sub-partners",
"category": 407
}
},
{
"model": "audit.riskcategory",
"pk": 408,
"fields": {
"order": 7,
"header": "Systems",
"parent": 400,
"category_type": "default",
"code": "ma_subject_areas_v2"
}
},
{
"model": "audit.riskblueprint",
"pk": 408,
"fields": {
"order": 0,
"header": "Systems",
"category": 408
}
}
]

0 comments on commit 7d27a6d

Please sign in to comment.