Fakultas Ilmu Komputer UI

Commit 9cd582e4 authored by Ade Azurat's avatar Ade Azurat
Browse files

Merge branch 'PBI-15-pencatatan_mustahik' into 'testing'

PBI 15 Pencatatan Mustahik: Query Search Data Source

See merge request !13
parents 8ab2c376 f8fabebd
Pipeline #51367 failed with stages
in 68 minutes and 14 seconds
......@@ -14,7 +14,10 @@ class MustahikQuery(graphene.ObjectType):
name_contains=graphene.String()
)
mustahik = graphene.Field(MustahikType, id=graphene.ID(required=True))
data_sources = graphene.List(DataSourceType, category=graphene.String())
data_sources = graphene.List(
DataSourceType, category=graphene.String(),
name_contains=graphene.String()
)
data_source = graphene.Field(DataSourceType, id=graphene.ID(required=True))
def resolve_mustahiks(self, info, **kwargs):
......@@ -37,11 +40,22 @@ class MustahikQuery(graphene.ObjectType):
return Mustahik.objects.get(pk=id)
def resolve_data_sources(self, info, **kwargs):
category = kwargs.get('category')
category = kwargs.get('category', None)
query = kwargs.get('name_contains', None)
filter_query = Q()
if category:
filter_query &= Q(category=category)
if query:
filter_query &= (
Q(datasourceinstitusi__name__icontains=query)
| Q(datasourcepekerja__profession__icontains=query)
| Q(datasourcepekerja__location__icontains=query)
| Q(datasourcewarga__rt__icontains=query)
| Q(datasourcewarga__rw__icontains=query)
| Q(datasourcewarga__village__icontains=query)
)
return DataSource.objects.filter(filter_query)
def resolve_data_source(self, info, id):
......
......@@ -838,3 +838,36 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
content = json.loads(response.content)
self.assertTrue(content['data']['deleteDataSource']['deleted'])
self.assertEquals(DataSource.objects.count(), count-1)
def test_query_search_data_source_by_name(self):
response = self.query(
'''
{
dataSources(nameContains:"pinangranti") {
id
category
dataSourceDetail {
__typename
... on DataSourceInstitusiType {
name
}
... on DataSourcePekerjaType {
profession
location
}
... on DataSourceWargaType {
rt
rw
village
}
}
}
}
'''
)
self.assertResponseNoErrors(response)
datasources = json.loads(response.content)['data']['dataSources']
for datasource in datasources:
datasource_warga = datasource['dataSourceDetail']
kelurahan = datasource_warga.get('village', None)
self.assertIn(kelurahan, ['pinangranti', None])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment