Make testcase filtering on the API side aware of the duration fields#2530
Make testcase filtering on the API side aware of the duration fields#2530mfonism wants to merge 1 commit intokiwitcms:masterfrom
Conversation
The API method `TestCase.filter` is extended to work for queries that contain lookups on the fields `setup_duration`, `testing_duration` and `expected_duration`. It also returns the values of all three fields in its result. Refs kiwitcms#1923
| default=F("setup_duration") + F("testing_duration"), | ||
| ) | ||
| ) | ||
| .filter(**query) |
There was a problem hiding this comment.
It looks like there may be some confusion around this item. Being able to filter by the duration field is the last checklist item in #1923. That should not need special casing for setup_duration and testing_duration because these are model fields. The only special case is expected_duration.
OTOH the item "API method TestCase.filter returns the value of all 3 fields - tests are updated to match" refers only to making sure that the API method TestCase.filter includes the new fields in its results. That should be much easier and require a lot less changes.
There was a problem hiding this comment.
Oh oh. I was over thinking it.
I thought the current checklist item also meant that filtering with respect to the duration fields should be possible on the API side.
I will create a new PR to implement just the presence of the duration fields in the result.
I'll keep this one alive (closed) so one can refer to it if we ever need to add filtering with respect to the duration fields on the API side.
There was a problem hiding this comment.
It just occured to me that I can shorten the entire Case expression with Coalesce:
Coalesce("setup_duration", timedelta(0)) + Coalesce("testing_duration", timedelta(0))| if duration is None: | ||
| continue | ||
|
|
||
| query[key] = duration |
There was a problem hiding this comment.
I added this for loop because the values of the duration keys in the incoming dict query will always be strings as xmlrpc can't marshal them if they are datetime.duration objects. The loop parses these strings (if they are present) into datetime.duration objects -- so that QuerySet.filter() won't choke on them.
There was a problem hiding this comment.
Since we don't need to filter by duration fields on the API side, then I'll take this out.
Although if someone ever mistakenly sends in a lookup based on a duration field, it will choke.
| ) | ||
| for testcase_dict in qs.iterator() | ||
| ] | ||
|
|
There was a problem hiding this comment.
Here I loop through the list of dicts (representing testcases) and make sure that if the value of the duration keys are not null, they are converted from duration objects to strings as xmlrpc cannot marshal duration objects.
The API method
TestCase.filteris extended to work for queries that contain lookups on the fieldssetup_duration,testing_durationandexpected_duration.It also returns the values of all three fields in its result.
Refs #1923