search param in all conditional subarrays/objects and return the condition and found array/obj
(request, param)
| 49 | |
| 50 | |
| 51 | def search_key_in_conditional_array(request, param): |
| 52 | """search param in all conditional subarrays/objects and return the condition and found array/obj""" |
| 53 | one_of_many_array = request.get('oneOfMany', []) |
| 54 | paired_with_array = request.get('pairedWith', []) |
| 55 | |
| 56 | # Check if the same parameter is in both 'pairedWith' and 'oneOfMany' and throw an error if found |
| 57 | common_key = next((element_one for subarray_one in one_of_many_array for element_one in subarray_one for subarray_paired in paired_with_array if element_one in subarray_paired), '') |
| 58 | assert common_key == '', f'The same parameter "{common_key}" cannot be in both "pairedWith" and "oneOfMany"' |
| 59 | |
| 60 | # Search for the parameter in 'oneOfMany' array |
| 61 | for sub_array_one in one_of_many_array: |
| 62 | if param in sub_array_one: |
| 63 | return 'oneOfMany', sub_array_one |
| 64 | |
| 65 | # Search for the parameter in 'pairedWith' array |
| 66 | for sub_array_paired in paired_with_array: |
| 67 | if param in sub_array_paired: |
| 68 | return 'pairedWith', sub_array_paired |
| 69 | |
| 70 | # If param doesn't exist in any of the conditional arrays, return empty condition and None |
| 71 | return '', None |
| 72 | |
| 73 | |
| 74 | def output_conditional_params(conditional_sub_array, condition): |
no test coverage detected