Skip to content

Commit

Permalink
test: test push mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouxm committed Oct 30, 2024
1 parent b1d68d6 commit b5fe246
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions terraso_backend/tests/graphql/mutations/test_soil_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
SoilData,
SoilDataDepthInterval,
)
from apps.soil_id.models.soil_data_history import SoilDataHistory

pytestmark = pytest.mark.django_db

Expand Down Expand Up @@ -780,3 +781,100 @@ def test_apply_to_all(client, project_site, project_manager):
db_intervals = SoilDataDepthInterval.objects.filter(soil_data=project_site.soil_data).all()
for interval in db_intervals:
assert interval.soil_texture_enabled


PUSH_SOIL_DATA_QUERY = """
mutation PushSoilDataMutation($input: SoilDataPushInput!) {
pushSoilData(input: $input) {
results {
siteId
result {
__typename
... on SoilDataPushEntryFailure {
reason
}
... on SoilDataPushEntrySuccess {
site {
soilData {
slopeAspect
depthDependentData {
depthInterval {
start
end
}
clayPercent
}
}
}
}
}
}
errors
}
}
"""


def test_push_soil_data(client, user):
sites = mixer.cycle(2).blend(Site, owner=user)

client.force_login(user)
response = graphql_query(
PUSH_SOIL_DATA_QUERY,
input_data={
"soilDataEntries": [
{
"siteId": str(sites[0].id),
"soilData": {
"slopeAspect": 10,
"depthDependentData": [],
"depthIntervals": [],
"deletedDepthIntervals": [],
},
},
{
"siteId": str(sites[1].id),
"soilData": {
"depthDependentData": [
{"depthInterval": {"start": 0, "end": 10}, "clayPercent": 5}
],
"depthIntervals": [],
"deletedDepthIntervals": [],
},
},
{
"siteId": str("c9df7deb-6b9d-4c55-8ba6-641acc47dbb2"),
"soilData": {
"depthDependentData": [],
"depthIntervals": [],
"deletedDepthIntervals": [],
},
},
]
},
client=client,
)

print(response.json())
result = response.json()["data"]["pushSoilData"]
assert result["errors"] is None
assert result["results"][2]["result"]["reason"] == "DOES_NOT_EXIST"

assert response.json()

sites[0].refresh_from_db()
sites[1].refresh_from_db()

assert sites[0].soil_data.slope_aspect == 10
assert (
sites[1]
.soil_data.depth_dependent_data.get(depth_interval_start=0, depth_interval_end=10)
.clay_percent
== 5
)

history_1 = SoilDataHistory.objects.get(site=sites[0])
assert history_1.soil_data_changes["soil_data"]["slope_aspect"] == 10

history_2 = SoilDataHistory.objects.get(site=sites[1])
assert history_2.soil_data_changes["soil_data"]["depth_dependent_data"][0]["clay_percent"] == 5

0 comments on commit b5fe246

Please sign in to comment.