Skip to content

Commit

Permalink
Add test case for filter in assessment registry issues list.
Browse files Browse the repository at this point in the history
- Add heirarchy level and child count for assessment registry issues.
  • Loading branch information
Rup-Narayan-Rajbanshi committed Oct 9, 2023
1 parent 60d8e80 commit 644c8a6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apps/assessment_registry/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ def filter_assessment_registry_issues(self, qs, name, value):
)

def filter_is_parent(self, qs, name, value):
if not value:
if value is None:
return qs
return qs.filter(
parent__isnull=True
)
if value:
# for parent
return qs.filter(parent__isnull=True)
# for child
return qs.filter(parent__isnull=False)
9 changes: 9 additions & 0 deletions apps/assessment_registry/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Answer,
AssessmentRegistryOrganization,
)
from .utils import get_hierarchy_level
from .filters import AssessmentRegistryGQFilterSet, AssessmentRegistryIssueGQFilterSet
from .enums import (
AssessmentRegistryCrisisTypeEnum,
Expand Down Expand Up @@ -260,6 +261,8 @@ class AssessmentRegistrySummaryIssueType(DjangoObjectType, UserResourceMixin):
sub_pillar_display = EnumDescription(source='get_sub_pillar_display', required=False)
sub_dimension = graphene.Field(AssessmentRegistrySummarySubDimensionTypeEnum, required=False)
sub_dimension_display = EnumDescription(source='get_sub_dimension_display', required=False)
child_count = graphene.Int(required=True)
level = graphene.Int(required=True)

class Meta:
model = SummaryIssue
Expand All @@ -270,6 +273,12 @@ class Meta:
'full_label',
]

def resolve_child_count(root, info, **kwargs):
return SummaryIssue.objects.filter(parent=root).count()

def resolve_level(root, info, **kwargs):
return get_hierarchy_level(root)


class AssessmentRegistrySummaryIssueListType(CustomDjangoListObjectType):
class Meta:
Expand Down
36 changes: 36 additions & 0 deletions apps/assessment_registry/tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,39 @@ def _query_check(**kwargs):
self.force_login(non_confidential_member_user)
content = _query_check(okay=False)
self.assertEqual(content['data']['project']['assessmentRegistries']['totalCount'], 3)

def test_issue_list_query_filter(self):
query = '''
query MyQuery (
$isParent: Boolean
$label: String
) {
assessmentRegSummaryIssues(
isParent: $isParent
label: $label
) {
results {
id
}
}
}
'''

member_user = UserFactory.create()
self.force_login(member_user)

parent_issue1, parent_issue2, parent_issue3 = SummaryIssueFactory.create_batch(3, parent=None)
child_issue1 = SummaryIssueFactory.create(parent=parent_issue1)
child_issue2 = SummaryIssueFactory.create(parent=parent_issue2)

for filter_data, expected_issues in [
({}, [child_issue1, child_issue2, parent_issue1, parent_issue2, parent_issue3]),
({'isParent': True}, [parent_issue1, parent_issue2, parent_issue3]),
({'isParent': False}, [child_issue1, child_issue2,]),
]:
content = self.query_check(query, variables={**filter_data})

self.assertListIds(
content['data']['assessmentRegSummaryIssues']['results'], expected_issues,
{'response': content, 'filter': filter_data}
)
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,8 @@ type AssessmentRegistrySummaryIssueType {
subPillarDisplay: EnumDescription
subDimension: AssessmentRegistrySummarySubDimensionTypeEnum
subDimensionDisplay: EnumDescription
childCount: Int!
level: Int!
}

enum AssessmentRegistrySummaryPillarTypeEnum {
Expand Down

0 comments on commit 644c8a6

Please sign in to comment.