Skip to content

Commit

Permalink
update organization filter test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Jan 18, 2024
1 parent 2ab83db commit 2d088a5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
9 changes: 7 additions & 2 deletions apps/assessment_registry/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin
from admin_auto_filters.filters import AutocompleteFilterFactory

from .models import (
AssessmentRegistry,
Expand Down Expand Up @@ -101,8 +102,12 @@ class SummaryIssueAdmin(admin.ModelAdmin):

@admin.register(AssessmentRegistry)
class AssessmentRegistryAdmin(admin.ModelAdmin):
list_display = ('id', 'lead', 'project', 'coordinated_joint', 'created_at')

list_display = ('id', 'lead', 'project', 'created_at')
list_filter = (
AutocompleteFilterFactory('Project', 'project'),
AutocompleteFilterFactory('Created By', 'created_by'),
'created_at',
)
inlines = [
MethodologyAttributeInline,
ScoreInline,
Expand Down
30 changes: 18 additions & 12 deletions apps/assessment_registry/dashboard_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,11 @@ def resolve_assessment_count(root: AssessmentDashboardStat, info):
)

@staticmethod
# @node_cache(CacheKey.AssessmentDashboard.STAKEHOLDER_COUNT)
@node_cache(CacheKey.AssessmentDashboard.STAKEHOLDER_COUNT)
def resolve_stakeholder_count(root: AssessmentDashboardStat, info):
return (
root.assessment_registry_qs.values(stakeholder=models.F('stakeholders__organization_type__title'))
root.assessment_registry_qs.filter(stakeholders__organization_type__title__isnull=False)
.values(stakeholder=models.F('stakeholders__organization_type__title'))
.annotate(count=Count('id'))
.order_by('stakeholder')
.values('count', 'stakeholder')
Expand Down Expand Up @@ -494,7 +495,7 @@ def resolve_total_singlesector_assessment(root: AssessmentDashboardStat, info) -
@node_cache(CacheKey.AssessmentDashboard.ASSESSMENT_BY_GEOAREA)
def resolve_assessment_geographic_areas(root: AssessmentDashboardStat, info):
return (
root.assessment_registry_qs.values("locations")
root.assessment_registry_qs.filter(locations__isnull=False).values("locations")
.annotate(
region=models.F("locations__admin_level__region"),
count=Count("locations__id"),
Expand All @@ -510,6 +511,7 @@ def resolve_assessment_geographic_areas(root: AssessmentDashboardStat, info):
'geo_area',
'admin_level_id',
'code',
'region',
)
.order_by("locations")
)
Expand Down Expand Up @@ -703,73 +705,77 @@ def resolve_sample_size_per_data_collection_technique(root: AssessmentDashboardS
@node_cache(CacheKey.AssessmentDashboard.DATA_COLLECTION_TECHNIQUE_AND_GEOLOCATION)
def resolve_assessment_by_data_collection_technique_and_geolocation(root: AssessmentDashboardStat, info):
return (
root.methodology_attribute_qs.values(
root.methodology_attribute_qs.filter(assessment_registry__locations__isnull=False)
.values(
"data_collection_technique",
geo_area=models.F("assessment_registry__locations"),
region=models.F("assessment_registry__locations__admin_level__region"),
admin_level_id=models.F("assessment_registry__locations__admin_level_id"),
)
.annotate(count=Count("assessment_registry__locations"))
.values('data_collection_technique', 'geo_area', 'region', 'admin_level_id')
.values('data_collection_technique', 'geo_area', 'region', 'admin_level_id', 'count')
.order_by("assessment_registry__locations")
)

@staticmethod
@node_cache(CacheKey.AssessmentDashboard.SAMPLING_APPROACH_AND_GEOLOCATION)
def resolve_assessment_by_sampling_approach_and_geolocation(root: AssessmentDashboardStat, info):
return (
root.methodology_attribute_qs.values(
root.methodology_attribute_qs.filter(assessment_registry__locations__isnull=False)
.values(
"sampling_approach",
geo_area=models.F("assessment_registry__locations"),
region=models.F("assessment_registry__locations__admin_level__region"),
admin_level_id=models.F("assessment_registry__locations__admin_level_id"),
)
.annotate(count=Count("assessment_registry__locations"))
.values('sampling_approach', 'geo_area', 'region', 'admin_level_id')
.values('sampling_approach', 'geo_area', 'region', 'admin_level_id', 'count')
.order_by("assessment_registry__locations")
)

@staticmethod
@node_cache(CacheKey.AssessmentDashboard.PROXIMITY_AND_GEOLOCATION)
def resolve_assessment_by_proximity_and_geolocation(root: AssessmentDashboardStat, info):
return (
root.methodology_attribute_qs.values(
root.methodology_attribute_qs.filter(assessment_registry__locations__isnull=False)
.values(
"proximity",
geo_area=models.F("assessment_registry__locations"),
region=models.F("assessment_registry__locations__admin_level__region"),
admin_level_id=models.F("assessment_registry__locations__admin_level_id"),
)
.annotate(count=Count("assessment_registry__locations"))
.values('proximity', 'geo_area', 'region', 'admin_level_id')
.values('proximity', 'geo_area', 'region', 'admin_level_id', 'count')
.order_by("assessment_registry__locations")
)

@staticmethod
@node_cache(CacheKey.AssessmentDashboard.UNIT_OF_ANALYSIS_AND_GEOLOCATION)
def resolve_assessment_by_unit_of_analysis_and_geolocation(root: AssessmentDashboardStat, info):
return (
root.methodology_attribute_qs.values(
root.methodology_attribute_qs.filter(assessment_registry__locations__isnull=False).values(
"unit_of_analysis",
geo_area=models.F("assessment_registry__locations"),
region=models.F("assessment_registry__locations__admin_level__region"),
admin_level_id=models.F("assessment_registry__locations__admin_level_id"),
)
.annotate(count=Count("assessment_registry__locations"))
.values('geo_area', 'region', 'admin_level_id', 'unit_of_analysis', 'count')
.order_by("assessment_registry__locations")
)

@staticmethod
@node_cache(CacheKey.AssessmentDashboard.UNIT_REPORTING_AND_GEOLOCATION)
def resolve_assessment_by_unit_of_reporting_and_geolocation(root: AssessmentDashboardStat, info):
return (
root.methodology_attribute_qs.values(
root.methodology_attribute_qs.filter(assessment_registry__locations__isnull=False).values(
"unit_of_reporting",
geo_area=models.F("assessment_registry__locations"),
region=models.F("assessment_registry__locations__admin_level__region"),
admin_level_id=models.F("assessment_registry__locations__admin_level_id"),
)
.annotate(count=Count("assessment_registry__locations"))
.values('unit_of_reporting' 'geo_area', 'region', 'admin_level_id')
.values('unit_of_reporting', 'count', 'geo_area', 'region', 'admin_level_id')
.order_by("assessment_registry__locations")
)

Expand Down
6 changes: 6 additions & 0 deletions apps/assessment_registry/filter_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ def filter_focuses(self, qs, _, value):
def filter_sectors(self, qs, _, value):
return qs if value is None else qs.filter(sectors__overlap=value)

def filter_details_type(self, qs, _, value):
return qs if value is None else qs.filter(details_type__overlap=value)

def filter_coordinated_joint(self, qs, _, value):
return qs if value is None else qs.filter(coordinated_joint__overlap=value)


AssessmentDashboardFilterDataType, AssessmentDashboardFilterDataInputType = generate_type_for_filter_set(
AssessmentDashboardFilterSet,
Expand Down
10 changes: 5 additions & 5 deletions apps/assessment_registry/tests/test_dashboard_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ def _query_check(filter=None, **kwargs):
self.assertEqual(content["collectionTechniqueCount"][1]["dataCollectionTechnique"], "KEY_INFORMAT_INTERVIEW")
self.assertEqual(content["assessmentByOverTime"][0]["count"], 1)
self.assertEqual(content["assessmentByOverTime"][0]["date"], str(date.today()))
self.assertEqual(content["assessmentGeographicAreas"][0]["geoArea"], self.geo_area1.id)
self.assertEqual(content["assessmentGeographicAreas"][1]["geoArea"], self.geo_area2.id)
self.assertEqual(content["assessmentGeographicAreas"][0]["geoArea"], str(self.geo_area1.id))
self.assertEqual(content["assessmentGeographicAreas"][1]["geoArea"], str(self.geo_area2.id))
self.assertEqual(content["assessmentByOverTime"][0]["count"], 1)
self.assertEqual(content["assessmentByOverTime"][0]["date"], str(date.today()))
self.assertEqual(content["assessmentPerFrameworkPillar"][0]["date"], str(date.today()))
Expand All @@ -356,13 +356,13 @@ def _query_check(filter=None, **kwargs):
self.assertEqual(
content['assessmentByDataCollectionTechniqueAndGeolocation'][1]['dataCollectionTechnique'],
"KEY_INFORMAT_INTERVIEW")
self.assertEqual(content['assessmentByDataCollectionTechniqueAndGeolocation'][0]['geoArea'], self.geo_area1.id)
self.assertEqual(content['assessmentByDataCollectionTechniqueAndGeolocation'][1]['geoArea'], self.geo_area1.id)
self.assertEqual(content['assessmentByDataCollectionTechniqueAndGeolocation'][0]['geoArea'], str(self.geo_area1.id))
self.assertEqual(content['assessmentByDataCollectionTechniqueAndGeolocation'][1]['geoArea'], str(self.geo_area1.id))
self.assertEqual(content['assessmentByDataCollectionTechniqueAndGeolocation'][0]['count'], 1)
self.assertEqual(content['assessmentByDataCollectionTechniqueAndGeolocation'][1]['count'], 1)
self.assertEqual(content['assessmentByProximityAndGeolocation'][0]['count'], 2)
self.assertEqual(content['assessmentByProximityAndGeolocation'][0]['proximity'], "FACE_TO_FACE")
self.assertEqual(content['assessmentByProximityAndGeolocation'][0]['geoArea'], self.geo_area1.id)
self.assertEqual(content['assessmentByProximityAndGeolocation'][0]['geoArea'], str(self.geo_area1.id))
# assessment Dashboard tab 3
self.assertEqual(content['medianQualityScoreByAnalyticalDensityDate'][0]['sector'], "FOOD_SECURITY")
self.assertEqual(content['medianQualityScoreByAnalyticalDensityDate'][0]['sectorDisplay'], "Food Security")
Expand Down
8 changes: 4 additions & 4 deletions apps/organization/tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def test_organization_query(self):
query MyQuery (
$verified: Boolean
$search: String
$usedInProject: ID
$usedInProjectByLead: ID
) {
organizations(
search: $search
verified: $verified
usedInProject: $usedInProject
usedInProjectByLead: $usedInProjectByLead
ordering: DESC_TITLE
) {
results {
Expand Down Expand Up @@ -96,10 +96,10 @@ def test_organization_query(self):
'verified': False,
}, [org6, org5, org3, org1]),
(user, {
'usedInProject': str(project.id),
'usedInProjectByLead': str(project.id),
}, [org6, org5, org3, org2, org1]),
(non_member_user, {
'usedInProject': str(project.id),
'usedInProjectByLead': str(project.id),
# Return all the organizations (Filter not applied)
}, [org6, org5, org4, org3, org2, org1]),
]:
Expand Down
4 changes: 2 additions & 2 deletions apps/project/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from deep.admin import linkify
from lead.models import Lead
from entry.models import Entry
from ary.models import Assessment
from assessment_registry.models import AssessmentRegistry

from .tasks import generate_viz_stats, generate_project_stats_cache
from .forms import ProjectRoleForm
Expand Down Expand Up @@ -128,7 +128,7 @@ def _count_subquery(Model, count_field='id'):
).annotate(
leads_count=_count_subquery(Lead),
entries_count=_count_subquery(Entry),
assessment_count=_count_subquery(Assessment),
assessment_count=_count_subquery(AssessmentRegistry),
members_count=_count_subquery(ProjectMembership, count_field='member'),
associated_regions_count=models.Count('regions', distinct=True),
associated_regions=StringAgg('regions__title', ',', distinct=True),
Expand Down

0 comments on commit 2d088a5

Please sign in to comment.