Skip to content

Commit

Permalink
refactor: simplification of code
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino committed Nov 30, 2023
1 parent d4c09f2 commit fea46b9
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,12 @@ def create_instance(self, resource_cls: type[T_Object]) -> T_Object:
# DataPointSubscriptionCreate requires either timeseries_ids or filter
keyword_arguments.pop("filter", None)
if resource_cls is Query:
key_count = min(len(keyword_arguments["select"]), len(keyword_arguments["with_"]))
keyword_arguments["with_"] = {
k: v for no, (k, v) in enumerate(keyword_arguments["with_"].items()) if no < key_count
}
# keys in with must match keys in select
selects = list(keyword_arguments["select"].values())[:key_count]
new_selects = {}
for i, key in enumerate(keyword_arguments["with_"]):
new_selects[key] = selects[i]
keyword_arguments["select"] = new_selects
# The fake generator makes all dicts from 1-3 values, we need to make sure that the query is valid
# by making sure that the list of equal length, so we make both to length 1.
with_key, with_value = next(iter(keyword_arguments["with_"].items()))
select_value = next(iter(keyword_arguments["select"].values()))
keyword_arguments["with_"] = {with_key: with_value}
keyword_arguments["select"] = {with_key: select_value}
elif resource_cls is Relationship:
# Relationship must set the source and target type consistently with the source and target
keyword_arguments["source_type"] = type(keyword_arguments["source"]).__name__
Expand Down

0 comments on commit fea46b9

Please sign in to comment.