test(meters): cover HTTP patrimony reassignment
This commit is contained in:
parent
d223931096
commit
47fbcc2cfe
1 changed files with 12 additions and 0 deletions
|
|
@ -102,6 +102,9 @@ def _edit_payload(meter, building, **extra):
|
||||||
def test_meter_edit_http_changes_and_removes_parent(app, authenticated_client):
|
def test_meter_edit_http_changes_and_removes_parent(app, authenticated_client):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
_, building, _ = _equipment()
|
_, building, _ = _equipment()
|
||||||
|
zone = Zone(name="TEST_UI_C1_FIX_ZONE", building=building)
|
||||||
|
db.session.add(zone)
|
||||||
|
db.session.flush()
|
||||||
root = create_meter(name="TEST_UI_C1_FIX_ROOT", building_id=building.id)
|
root = create_meter(name="TEST_UI_C1_FIX_ROOT", building_id=building.id)
|
||||||
child = create_meter(name="TEST_UI_C1_FIX_CHILD", building_id=building.id)
|
child = create_meter(name="TEST_UI_C1_FIX_CHILD", building_id=building.id)
|
||||||
response = authenticated_client.get(f"/meters/{child.id}/edit")
|
response = authenticated_client.get(f"/meters/{child.id}/edit")
|
||||||
|
|
@ -116,6 +119,15 @@ def test_meter_edit_http_changes_and_removes_parent(app, authenticated_client):
|
||||||
db.session.refresh(child)
|
db.session.refresh(child)
|
||||||
assert child.parent_id == root.id
|
assert child.parent_id == root.id
|
||||||
|
|
||||||
|
response = authenticated_client.post(
|
||||||
|
f"/meters/{child.id}/edit",
|
||||||
|
data=_edit_payload(child, building, scope_type="zone", scope_id=str(zone.id), parent_id=str(root.id)),
|
||||||
|
)
|
||||||
|
assert response.status_code == 302
|
||||||
|
db.session.refresh(child)
|
||||||
|
assert child.zone_id == zone.id
|
||||||
|
assert child.building_id is None
|
||||||
|
|
||||||
response = authenticated_client.post(
|
response = authenticated_client.post(
|
||||||
f"/meters/{child.id}/edit",
|
f"/meters/{child.id}/edit",
|
||||||
data=_edit_payload(child, building, parent_id=""),
|
data=_edit_payload(child, building, parent_id=""),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue