Enhancements

This commit is contained in:
Joren de Graaf
2026-10-11 20:46:55 +02:00
parent cb12c23732
commit 000ec834b0
26 changed files with 813 additions and 30 deletions
+55 -1
View File
@@ -118,6 +118,60 @@ class McpHttpTests(LiveServerTestCase):
await self._client(self.read_secret, read_only)
asyncio.run(check())
def test_hydration_tools_and_food_logging_share_totals(self):
drink = FoodProduct.objects.create(owner=self.a, product_name='Orange juice', base_unit='ml')
async def check(client):
food = await client.call_tool('food_log', {'food': {'meal': 'lunch', 'amount': '200',
'unit': 'ml', 'product_id': str(drink.api_id)}})
self.assertFalse(food.is_error, food)
daily = (await client.call_tool('hydration_get_daily')).structured_content
self.assertEqual(daily['food_ml'], '200.000')
manual = (await client.call_tool('hydration_log', {'amount_ml': '125',
'idempotency_key': 'mcp-hydration-1'})).structured_content
self.assertEqual(manual['amount_ml'], '125')
again = (await client.call_tool('hydration_log', {'amount_ml': '125',
'idempotency_key': 'mcp-hydration-1'})).structured_content
self.assertEqual(again['id'], manual['id'])
daily = (await client.call_tool('hydration_get_daily')).structured_content
self.assertEqual(Decimal(daily['total_ml']), 325)
self.assertFalse((await client.call_tool('hydration_delete',
{'entry_id': manual['id']})).is_error)
self.assertEqual(Decimal((await client.call_tool('hydration_get_daily')).structured_content['total_ml']), 200)
asyncio.run(self._client(self.secret, check))
def test_inventory_update_partial_quantity_and_structured_validation(self):
product = FoodProduct.objects.create(owner=self.a, product_name='Meatballs',
package_amount=Decimal('400'), package_unit='g')
location = InventoryLocation.objects.create(user=self.a, name='Fridge')
package = KitchenInventoryItem.objects.create(user=self.a, product=product, location=location,
original_amount=Decimal('400'), remaining_amount=Decimal('400'), inventory_unit='g')
async def check(client):
changed = (await client.call_tool('inventory_update', {'item_id': str(package.api_id),
'changes': {'opened': True, 'remaining_amount': 280,
'notes': 'Used 120 g for dinner.'}})).structured_content
self.assertTrue(changed['success'])
self.assertEqual(Decimal(changed['item']['remaining_amount']), 280)
self.assertEqual(changed['item']['unit'], 'g')
stock = (await client.call_tool('inventory_get_stock',
{'product_id': str(product.api_id)})).structured_content
self.assertEqual(stock['products'][0]['totals']['g'], '280.000')
invalid = (await client.call_tool('inventory_update', {'item_id': str(package.api_id),
'changes': {'remaining_amount': 401}})).structured_content
self.assertFalse(invalid['success'])
self.assertEqual(invalid['error']['details']['field'], 'remaining_amount')
self.assertTrue((await client.call_tool('inventory_update', {'item_id': str(package.api_id),
'changes': {'remaining_amount': -1}})).is_error)
self.assertTrue((await client.call_tool('inventory_update', {'item_id': str(self.b_item.api_id),
'changes': {'notes': 'Unauthorized'}})).is_error)
unrelated = (await client.call_tool('inventory_update', {'item_id': str(package.api_id),
'changes': {'notes': 'Still in fridge'}})).structured_content
self.assertEqual(unrelated['item']['notes'], 'Still in fridge')
asyncio.run(self._client(self.secret, check))
def test_oauth_issued_pat_authenticates_mcp(self):
application = Application.objects.create(user=self.a, name='Test ChatGPT style client',
client_type=Application.CLIENT_PUBLIC, authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE,
@@ -157,7 +211,7 @@ class McpHttpTests(LiveServerTestCase):
async def check(client):
names = {tool.name for tool in (await client.list_tools()).tools}
self.assertEqual(len(names), 20)
self.assertEqual(len(names), 26)
self.assertTrue({'food_lookup_product', 'food_create_product', 'food_import_product',
'inventory_import_groceries'} <= names)
today = (await client.call_tool('food_get_today')).structured_content