|
| 1 | + |
| 2 | +import copy |
| 3 | +from api.jobs import gears |
| 4 | + |
| 5 | +# DISCUSS: this basically asserts that the log helper doesn't throw, which is of non-zero but questionable value. |
| 6 | +# Could instead be marked for pytest et. al to ignore coverage? Desirability? Compatibility? |
| 7 | +def test_fill_defaults(): |
| 8 | + |
| 9 | + gear_config = { |
| 10 | + 'key_one': {'default': 1}, |
| 11 | + 'key_two': {'default': 2}, |
| 12 | + 'key_three': {'default': 3}, |
| 13 | + 'key_no_de': {} |
| 14 | + } |
| 15 | + |
| 16 | + gear = { |
| 17 | + 'gear': { |
| 18 | + 'config': gear_config |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + # test sending in complete config does not change |
| 23 | + config = { |
| 24 | + 'key_one': 4, |
| 25 | + 'key_two': 5, |
| 26 | + 'key_three': 6 |
| 27 | + } |
| 28 | + |
| 29 | + result = gears.fill_gear_default_values(gear, config) |
| 30 | + assert result['key_one'] == 4 |
| 31 | + assert result['key_two'] == 5 |
| 32 | + assert result['key_three'] == 6 |
| 33 | + |
| 34 | + # test sending in empty config |
| 35 | + result = gears.fill_gear_default_values(gear, {}) |
| 36 | + assert result['key_one'] == 1 |
| 37 | + assert result['key_two'] == 2 |
| 38 | + assert result['key_three'] == 3 |
| 39 | + |
| 40 | + # test sending in None config |
| 41 | + result = gears.fill_gear_default_values(gear, None) |
| 42 | + assert result['key_one'] == 1 |
| 43 | + assert result['key_two'] == 2 |
| 44 | + assert result['key_three'] == 3 |
| 45 | + |
| 46 | + # test sending in semi-complete config |
| 47 | + config = { |
| 48 | + 'key_one': None, |
| 49 | + 'key_two': [] |
| 50 | + #'key_three': 6 # missing |
| 51 | + } |
| 52 | + |
| 53 | + result = gears.fill_gear_default_values(gear, config) |
| 54 | + assert result['key_one'] == None |
| 55 | + assert result['key_two'] == [] |
| 56 | + assert result['key_three'] == 3 |
0 commit comments