Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Sistem Informasi Zakat
Sizakat 5.0 (Refactoring)
Sizakat Backend
Commits
df13252d
Commit
df13252d
authored
Sep 03, 2020
by
Naufal Alauddin Hilmi
🍦
Browse files
PBI 16 TASK: Pencarian mustahik dengan sdm
parent
6657d991
Changes
2
Hide whitespace changes
Inline
Side-by-side
sizakat/mustahik/query.py
View file @
df13252d
...
...
@@ -11,7 +11,8 @@ class MustahikQuery(graphene.ObjectType):
mustahiks
=
graphene
.
List
(
MustahikType
,
statuses
=
graphene
.
List
(
graphene
.
String
),
name_contains
=
graphene
.
String
()
name_contains
=
graphene
.
String
(),
data_sources
=
graphene
.
List
(
graphene
.
ID
)
)
mustahik
=
graphene
.
Field
(
MustahikType
,
id
=
graphene
.
ID
(
required
=
True
))
data_sources
=
graphene
.
List
(
...
...
@@ -23,15 +24,22 @@ class MustahikQuery(graphene.ObjectType):
def
resolve_mustahiks
(
self
,
info
,
**
kwargs
):
statuses
=
kwargs
.
get
(
'statuses'
,
None
)
data_sources
=
kwargs
.
get
(
'data_sources'
,
None
)
name_contains
=
kwargs
.
get
(
'name_contains'
,
None
)
filter_query
=
Q
()
if
statuses
and
len
(
statuses
)
>
0
:
filter_query
|
=
reduce
(
filter_query
&
=
reduce
(
lambda
a
,
b
:
a
|
b
,
[
Q
(
status
=
status
)
for
status
in
statuses
]
)
if
data_sources
and
len
(
data_sources
)
>
0
:
filter_query
&=
reduce
(
lambda
a
,
b
:
a
|
b
,
[
Q
(
data_source
=
data_source
)
for
data_source
in
data_sources
]
)
if
name_contains
:
filter_query
&=
Q
(
name__icontains
=
name_contains
)
...
...
sizakat/mustahik/tests.py
View file @
df13252d
...
...
@@ -361,6 +361,44 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
len
(
content
[
'data'
][
'mustahiks'
]),
0
)
def
test_mustahiks_query_if_data_sources_provided_should_return_mustahiks_with_coresponding_data_sources
(
self
):
dataSourceId
=
DataSource
.
objects
.
all
()[
0
].
id
response
=
self
.
query
(
'''
query mustahiks($dataSources: [ID]) {
mustahiks(dataSources: $dataSources) {
dataSource {
id
}
}
}
'''
,
op_name
=
'mustahiks'
,
variables
=
{
'dataSources'
:
[
dataSourceId
]}
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
int
(
content
[
'data'
][
'mustahiks'
][
0
][
'dataSource'
][
'id'
]),
dataSourceId
)
def
test_mustahiks_query_if_data_sources_provided_has_no_corresponding_mustahiks_it_should_return_empty_list
(
self
):
dataSourceId
=
99999
response
=
self
.
query
(
'''
query mustahiks($dataSources: [ID]) {
mustahiks(dataSources: $dataSources) {
dataSource {
id
}
}
}
'''
,
op_name
=
'mustahiks'
,
variables
=
{
'dataSources'
:
[
dataSourceId
]}
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
len
(
content
[
'data'
][
'mustahiks'
]),
0
)
def
test_data_sources_query_should_return_list_data_sources
(
self
):
response
=
self
.
query
(
'''
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment