Skip to content

Commit

Permalink
ran black
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiaqi Liu committed Jan 3, 2020
1 parent 4cb77e8 commit 8b58566
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 32 deletions.
32 changes: 20 additions & 12 deletions peregrine/resources/submission/graphql/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,24 +276,32 @@ def apply_query_args(q, args, info):
q = apply_arg_quicksearch(q, args, info)

# created_after: filter by created datetime
if 'created_after' in args:
q = q.filter(q.entity()._props['created_datetime'].cast(sa.String).cast(sa.DateTime)
> parse(args['created_after']))
if "created_after" in args:
q = q.filter(
q.entity()._props["created_datetime"].cast(sa.String).cast(sa.DateTime)
> parse(args["created_after"])
)

# created_before: filter by created datetime
if 'created_before' in args:
q = q.filter(q.entity()._props['created_datetime'].cast(sa.String).cast(sa.DateTime)
< parse(args['created_before']))
if "created_before" in args:
q = q.filter(
q.entity()._props["created_datetime"].cast(sa.String).cast(sa.DateTime)
< parse(args["created_before"])
)

# updated_after: filter by update datetime
if 'updated_after' in args:
q = q.filter(q.entity()._props['updated_datetime'].cast(sa.String).cast(sa.DateTime)
> parse(args['updated_after']))
if "updated_after" in args:
q = q.filter(
q.entity()._props["updated_datetime"].cast(sa.String).cast(sa.DateTime)
> parse(args["updated_after"])
)

# updated_before: filter by update datetime
if 'updated_before' in args:
q = q.filter(q.entity()._props['updated_datetime'].cast(sa.String).cast(sa.DateTime)
< parse(args['updated_before']))
if "updated_before" in args:
q = q.filter(
q.entity()._props["updated_datetime"].cast(sa.String).cast(sa.DateTime)
< parse(args["updated_before"])
)

# with_links: (AND) (filter for those with given links)
if "with_links" in args:
Expand Down
77 changes: 57 additions & 20 deletions tests/graphql/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,13 +1714,16 @@ def test_boolean_filter(client, submitter, pg_driver_clean, cgci_blgsp):
assert len(r.json["data"]["experiment"]) == 1


<<<<<<< HEAD
def test_datetime_filters(client, submitter, pg_driver_clean, cgci_blgsp):
post_example_entities_together(client, pg_driver_clean, submitter)

# make sure the existing data is what is expected
r = client.post(path, headers=submitter, data=json.dumps({
'query': """
r = client.post(
path,
headers=submitter,
data=json.dumps(
{
"query": """
{
experiment {
id
Expand All @@ -1729,7 +1732,9 @@ def test_datetime_filters(client, submitter, pg_driver_clean, cgci_blgsp):
}
}
"""
}))
}
),
)
print("in DB:", r.data)
assert len(r.json["data"]["experiment"]) == 1
experiment_id = r.json["data"]["experiment"][0]["id"]
Expand All @@ -1743,56 +1748,88 @@ def test_datetime_filters(client, submitter, pg_driver_clean, cgci_blgsp):
yesterday_str = (created_datetime - timedelta(days=1)).strftime(date_format)

# test created_after filter
r = client.post(path, headers=submitter, data=json.dumps({
'query': """
r = client.post(
path,
headers=submitter,
data=json.dumps(
{
"query": """
{{
experiment (created_after: "{}") {{
id
}}
}}
""".format(yesterday_str)
}))
""".format(
yesterday_str
)
}
),
)
print("created_after query result:", r.data)
assert len(r.json["data"]["experiment"]) == 1
assert r.json["data"]["experiment"][0]["id"] == experiment_id

# test created_before filter
r = client.post(path, headers=submitter, data=json.dumps({
'query': """
r = client.post(
path,
headers=submitter,
data=json.dumps(
{
"query": """
{{
experiment (created_before: "{}") {{
id
}}
}}
""".format(yesterday_str)
}))
""".format(
yesterday_str
)
}
),
)
print("created_before query result:", r.data)
assert len(r.json["data"]["experiment"]) == 0

# test updated_after filter
r = client.post(path, headers=submitter, data=json.dumps({
'query': """
r = client.post(
path,
headers=submitter,
data=json.dumps(
{
"query": """
{{
experiment (updated_after: "{}") {{
id
}}
}}
""".format(yesterday_str)
}))
""".format(
yesterday_str
)
}
),
)
print("updated_after query result:", r.data)
assert len(r.json["data"]["experiment"]) == 1
assert r.json["data"]["experiment"][0]["id"] == experiment_id

# test updated_before filter
r = client.post(path, headers=submitter, data=json.dumps({
'query': """
r = client.post(
path,
headers=submitter,
data=json.dumps(
{
"query": """
{{
experiment (updated_before: "{}") {{
id
}}
}}
""".format(yesterday_str)
}))
""".format(
yesterday_str
)
}
),
)
print("updated_before query result:", r.data)
assert len(r.json["data"]["experiment"]) == 0

Expand Down

0 comments on commit 8b58566

Please sign in to comment.