|
16 | 16 | from behave import when, then |
17 | 17 |
|
18 | 18 |
|
19 | | -@when("the user retrieves the well 1") |
| 19 | +@when("the user retrieves the well 9999") |
20 | 20 | def step_impl(context): |
21 | | - context.response = context.client.get("thing/water-well/1") |
| 21 | + context.response = context.client.get("thing/water-well/9999") |
| 22 | + context.notes = {} |
22 | 23 |
|
23 | 24 |
|
24 | | -@when("the user retrieves the well 9999") |
| 25 | +@then("the response should include an error message indicating the well was not found") |
25 | 26 | def step_impl(context): |
26 | | - context.response = context.client.get("thing/water-well/9999") |
| 27 | + assert {"detail": "Thing with ID 9999 not found."} == context.response.json() |
27 | 28 |
|
28 | 29 |
|
29 | | -@then("the response should contain a current_location field") |
| 30 | +@then("the notes should be a non-empty string") |
30 | 31 | def step_impl(context): |
31 | | - assert "current_location" in context.response.json() |
| 32 | + for k, note in context.notes.items(): |
| 33 | + assert note, f"{k} Note is empty" |
32 | 34 |
|
33 | 35 |
|
34 | | -@then("the response should include notes") |
| 36 | +@when("the user retrieves the well by ID via path parameter") |
35 | 37 | def step_impl(context): |
36 | | - assert "notes" in context.response.json() |
37 | | - context.notes = context.response.json()["notes"] |
| 38 | + context.response = context.client.get( |
| 39 | + f"thing/water-well/{context.objects['wells'][0].id}" |
| 40 | + ) |
| 41 | + context.notes = {} |
38 | 42 |
|
39 | 43 |
|
40 | | -@then("the response should include an error message indicating the well was not found") |
| 44 | +@then( |
| 45 | + "null values in the response should be represented as JSON null (not placeholder strings)" |
| 46 | +) |
41 | 47 | def step_impl(context): |
42 | | - assert {"detail": "Thing with ID 9999 not found."} == context.response.json() |
| 48 | + data = context.response.json() |
| 49 | + for k, v in data.items(): |
| 50 | + if v == "": |
| 51 | + assert v is None, f"Value for key {k} is an empty string but should be null" |
43 | 52 |
|
44 | 53 |
|
45 | | -@then("the response should include well_construction_notes") |
| 54 | +@then( |
| 55 | + "the response should include location notes (i.e. driving directions and geographic well location notes)" |
| 56 | +) |
46 | 57 | def step_impl(context): |
47 | | - assert "well_construction_notes" in context.response.json() |
48 | | - context.notes = context.response.json()["well_construction_notes"] |
| 58 | + data = context.response.json() |
| 59 | + location = data["current_location"] |
| 60 | + assert "notes" in location, "Response does not include location notes" |
| 61 | + assert location["notes"] is not None, "Location notes is null" |
| 62 | + context.notes["location"] = location["notes"] |
49 | 63 |
|
50 | 64 |
|
51 | | -@then("the notes should be a non-empty string") |
| 65 | +@then( |
| 66 | + "the response should include construction notes (i.e. pump notes and other construction notes)" |
| 67 | +) |
| 68 | +def step_impl(context): |
| 69 | + data = context.response.json() |
| 70 | + assert ( |
| 71 | + "well_construction_notes" in data |
| 72 | + ), "Response does not include construction notes" |
| 73 | + assert data["well_construction_notes"] is not None, "Construction notes is null" |
| 74 | + context.notes["construction"] = data["well_construction_notes"] |
| 75 | + |
| 76 | + |
| 77 | +@then("the response should include general well notes (catch all notes field)") |
| 78 | +def step_impl(context): |
| 79 | + data = context.response.json() |
| 80 | + assert "notes" in data, "Response does not include notes" |
| 81 | + assert data["notes"] is not None, "Notes is null" |
| 82 | + context.notes["general"] = data["notes"] |
| 83 | + |
| 84 | + |
| 85 | +@then( |
| 86 | + "the response should include measuring notes (notes about measuring/visiting the well, on Access form)" |
| 87 | +) |
| 88 | +def step_impl(context): |
| 89 | + data = context.response.json() |
| 90 | + assert "measuring_notes" in data, "Response does not include measuring notes" |
| 91 | + assert data["measuring_notes"] is not None, "Measuring notes is null" |
| 92 | + context.notes["measuring"] = data["measuring_notes"] |
| 93 | + |
| 94 | + |
| 95 | +@then( |
| 96 | + "the response should include water notes (i.e. water bearing zone information and other info from ose reports)" |
| 97 | +) |
52 | 98 | def step_impl(context): |
53 | | - assert bool(context.notes) == True |
| 99 | + data = context.response.json() |
| 100 | + assert "water_notes" in data, "Response does not include water notes" |
| 101 | + assert data["water_notes"] is not None, "Water notes is null" |
| 102 | + context.notes["water"] = data["water_notes"] |
54 | 103 |
|
55 | 104 |
|
56 | 105 | # ============= EOF ============================================= |
0 commit comments