MCPcopy
hub / github.com/hugapi/hug / test_transform

Method test_transform

tests/test_context_factory.py:288–320  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

286 assert "launched_delete_context" in custom_context
287
288 def test_transform(self):
289 custom_context = dict(test="context", test_number=43)
290
291 @hug.context_factory()
292 def return_context(**kwargs):
293 return custom_context
294
295 @hug.delete_context()
296 def delete_context(context, exception=None, errors=None, lacks_requirement=None):
297 assert not exception
298 assert context == custom_context
299 assert not errors
300 assert not lacks_requirement
301 custom_context["launched_delete_context"] = True
302
303 class UserSchema(Schema):
304 name = fields.Str()
305
306 @post_dump()
307 def check_context(self, data):
308 assert self.context["test"] == "context"
309 self.context["test_number"] += 1
310
311 @hug.cli()
312 def transform_cli_function() -> UserSchema():
313 custom_context["launched_cli_function"] = True
314 return {"name": "test"}
315
316 hug.test.cli(transform_cli_function)
317 assert "launched_cli_function" in custom_context
318 assert "launched_delete_context" in custom_context
319 assert "test_number" in custom_context
320 assert custom_context["test_number"] == 44
321
322 def test_exception(self):
323 custom_context = dict(test="context")

Callers

nothing calls this directly

Calls 1

cliMethod · 0.45

Tested by

no test coverage detected