fix: do not update none values

master
Pierre-Louis Guhur 10 months ago
parent 799c207875
commit 5f5aea6bf3

@ -294,6 +294,8 @@ def update_election(
"hide_results",
"force_close",
]:
if getattr(election, key) is None:
continue
if getattr(db_election, key) != getattr(election, key):
setattr(db_election, key, getattr(election, key))

@ -494,6 +494,30 @@ def test_update_election():
assert response.status_code == 403, response.text
def test_close_election2():
"""
Test we can partially update an election
"""
# Create a random election
body = _random_election(10, 5)
response = client.post("/elections", json=body)
assert response.status_code == 200, response.content
data = response.json()
new_name = f'{data["name"]}_MODIFIED'
data["name"] = new_name
token = data["admin"]
election_ref = data["ref"]
close_response = client.put(
f"/elections",
headers={"Authorization": f"Bearer {token}"},
json={"force_close": True, "ref": election_ref},
)
assert close_response.status_code == 200, close_response.json()
close_data = close_response.json()
assert close_data["force_close"] == True
def test_close_election():
# Create a random election
body = _random_election(10, 5)

Loading…
Cancel
Save