Skip to content

Commit 9cbe282

Browse files
committed
fixed the merge conflict
1 parent 3985b74 commit 9cbe282

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

backend/api/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,10 @@ async def update_datapoint(
419419

420420
# Check if the topic or jsonpath field is being updated
421421
if datapoint.topic != existing_datapoint['topic'] or datapoint.jsonpath != existing_datapoint['jsonpath']:
422-
raise HTTPException(status_code=422, detail="Updating the topic or jsonpath field is not allowed!")
422+
raise HTTPException(status_code=422,
423+
detail="Updating the topic or jsonpath field is not allowed!")
423424

424-
# Update the datapoint in the database
425+
# Update the datapoint in the database
425426
await conn.execute(
426427
"""UPDATE datapoints SET entity_id=$1, entity_type=$2, attribute_name=$3, description=$4 WHERE object_id=$5""",
427428
datapoint.entity_id,

tests/test_crud.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,9 @@ def test_update(self):
189189
datapoint_basis1.entity_id = None # Ensure this triggers a failure
190190
datapoint_basis1.entity_type = None # Ensure this triggers a failure
191191
datapoint_basis1.attribute_name = None # Ensure this triggers a failure
192-
193-
# List of forbidden fields that should not be included in the update
194-
forbidden_fields = ['object_id', 'jsonpath', 'topic']
195-
196-
# Convert the datapoint object to a dictionary
197-
update_data = datapoint_basis.model_dump()
198-
199-
# Remove forbidden fields from the update payload
200-
update_data = {key: value for key, value in update_data.items() if key not in forbidden_fields}
201-
202-
# Send the update request with the filtered update data
192+
update_data = datapoint_basis1.model_dump_json()
203193
response1 = requests.request("PUT", settings.GATEWAY_URL + "/data/" + object_id, headers=headers,
204-
data=json.dumps(update_data))
194+
data=update_data)
205195

206196
# Log the request and response for debugging
207197
print(f"Request data for update: {update_data}")
@@ -210,12 +200,13 @@ def test_update(self):
210200

211201
# Ensure the response indicates failure
212202
self.assertFalse(response1.ok)
213-
self.assertEqual(response1.status_code, 422)
203+
self.assertEqual(response1.status_code, 400)
214204
self.assertIn("entity_id, entity_type, and attribute_name cannot be null", response1.text)
215205

216-
print(f"Datapoint basis: {datapoint_basis}")
217206
# Perform a valid update with correct entity information
218-
datapoint_basis_update = DatapointUpdate(
207+
datapoint_basis_update = Datapoint(
208+
jsonpath=datapoint_basis.jsonpath,
209+
topic=datapoint_basis.topic,
219210
entity_id=self.test_entity.id,
220211
entity_type=self.test_entity.type,
221212
attribute_name=self.test_entity.get_attribute_names().pop(),

0 commit comments

Comments
 (0)