Skip to content

Commit

Permalink
test: add test for delete item site
Browse files Browse the repository at this point in the history
Reviewed-by: andriac
[Refs_ticket]: #5 , #6
  • Loading branch information
andriacap authored and Maxime Vergez committed Apr 25, 2023
1 parent 9b17a2f commit 0b2f1bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions backend/gn_module_monitoring/routes/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ def post_sites():

@blueprint.route("/sites/<int:_id>", methods=["DELETE"])
def delete_site(_id):
item_schema = MonitoringSitesSchema()
item = TMonitoringSites.find_by_id(_id)
TMonitoringSites.query.filter_by(id_g=_id).delete()
db.session.delete(item)
db.session.commit()
return item_schema.dump(item), 201
return {
"success": f"Item with {item.id_g} from table {item.__tablename__} is successfully deleted"
}, 200
15 changes: 15 additions & 0 deletions backend/gn_module_monitoring/tests/test_routes/test_site.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from flask import url_for

from gn_module_monitoring.monitoring.models import TMonitoringSites
from gn_module_monitoring.monitoring.schemas import BibTypeSiteSchema, MonitoringSitesSchema
from gn_module_monitoring.monitoring.models import TMonitoringSites

Expand Down Expand Up @@ -175,3 +176,17 @@ def test_post_sites(self, site_to_post_with_types, types_site, site_group_withou
res.as_dict()["base_site_name"]
== site_to_post_with_types["properties"]["base_site_name"]
)

def test_delete_site(self, sites):
site = list(sites.values())[0]
id_base_site = site.id_base_site
item = TMonitoringSites.find_by_id(id_base_site)
r = self.client.delete(url_for("monitorings.delete_site", _id=id_base_site))

assert (
r.json["success"]
== f"Item with {item.id_g} from table {item.__tablename__} is successfully deleted"
)
with pytest.raises(Exception) as e:
TMonitoringSites.query.get_or_404(id_base_site)
assert "404 Not Found" in str(e.value)

0 comments on commit 0b2f1bc

Please sign in to comment.