Skip to content

Commit

Permalink
fix: fix bug with deleted inventory records reappearing after deletin…
Browse files Browse the repository at this point in the history
…g profiles (#44)
  • Loading branch information
wojtekzyla committed Sep 11, 2023
1 parent 2383ada commit 599f475
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/SC4SNMP_UI_backend/common/inventory_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def update_profiles_in_inventory(profile_to_search: str, process_record: Callabl
:param kwargs: additional variables which user can pass to process_record function
:return:
"""
inventory_records = list(mongo_inventory.find({"profiles": {"$regex": f'.*{profile_to_search}.*'}}))
inventory_records = list(mongo_inventory.find({"profiles": {"$regex": f'.*{profile_to_search}.*'}, "delete": False}))
for record in inventory_records:
record_id = record["_id"]
record_updated = inventory_conversion.backend2ui(record, inventory_type=None) # inventory_type isn't used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_delete_profile_record(m_update, m_delete, m_find, client):

response = client.post(f'/profiles/delete/{common_id}')

calls = [call({'_id': ObjectId(common_id)}, {"_id": 0}), call({"profiles": {"$regex": '.*profile_1.*'}})]
calls = [call({'_id': ObjectId(common_id)}, {"_id": 0}), call({"profiles": {"$regex": '.*profile_1.*'}, "delete": False})]
m_find.assert_has_calls(calls)
assert m_delete.call_args == call({"_id": ObjectId(common_id)})
assert m_update.call_args == call({"_id": ObjectId(common_id)}, {"$set": backend_inventory_update})
Expand Down Expand Up @@ -232,7 +232,7 @@ def test_update_profile_record_with_name_change_success(m_find, m_update, client

calls_find = [call({f"profile_1_edit": {"$exists": True}, "_id": {"$ne": ObjectId(common_id)}}),
call({'_id': ObjectId(common_id)}, {"_id": 0}),
call({"profiles": {"$regex": '.*profile_1.*'}})]
call({"profiles": {"$regex": '.*profile_1.*'}, "delete": False})]

calls_update = [call({'_id': ObjectId(common_id)}, {"$rename": {"profile_1": "profile_1_edit"}}),
call({"_id": ObjectId(common_id)}, {"$set": backend_inventory_update}),
Expand Down

0 comments on commit 599f475

Please sign in to comment.