async def test_instance_of(self): obj = await Person.create(**INIT_DATA.get("person", [])[0]) elements = { "Hello World": str, 1: int, obj: Person, (1, 2, 3, 4): tuple, } for el, instance in elements.items(): assert API_functools.instance_of(el, instance) is True assert API_functools.instance_of("Hello", int) is False
async def test__insert_default_data(self): # Insert a Person user_to_create = INIT_DATA.get("person", [])[0] user_created = await API_functools._insert_default_data( "person", user_to_create) assert API_functools.instance_of(user_created, Person) is True # Insert a Comment comment_to_create = { **INIT_DATA.get("comment", [])[0], "user": user_created.id, } comment_created = await API_functools._insert_default_data( "comment", comment_to_create) assert API_functools.instance_of(comment_created, Comment) is True # Insert a Vote vote_to_create = { "user": user_created.id, "comment": comment_created.id, } vote_created = await API_functools._insert_default_data( "vote", vote_to_create) assert API_functools.instance_of(vote_created, Vote) is True
async def users_by_ID(res: Response, user_ID: int) -> Dict[str, Any]: """Get user by ID Args: user_ID (int): user ID Returns: Dict[str, Any]: user found or Error """ user = await Person_Pydantic.from_queryset(Person.filter(pk=user_ID)) data = { "success": True, "user": API_functools.get_or_default(user, 0, {}), } if not API_functools.instance_of(data["user"], Person): res.status_code = status.HTTP_404_NOT_FOUND data["success"] = False data["detail"] = "Not Found" return data