django-ninja-extra icon indicating copy to clipboard operation
django-ninja-extra copied to clipboard

How to Implement Testcase with NINJA JWT Authentication ?

Open recervictory opened this issue 3 years ago • 3 comments

I have implemented Ninja JWT Authentication with Ninja Extra.

@api_controller("post/", tags=["Post"])
class PostController:
        @route.post("", response=PostOut, auth=JWTAuth())
         def create_post(self, payload: PostIn):
                post = Post.Object.Create(**payload.dict())
                resturn post

I want to implement TestPostController But how I apply NINJA JWT with that?

recervictory avatar Jul 14 '22 06:07 recervictory

@recervictory please look at this issue and tell me if its helpful to you https://github.com/eadwinCode/django-ninja-extra/issues/3

eadwinCode avatar Jul 18 '22 09:07 eadwinCode

I am totally new to Django, I am not able to implement that. I want to add headers={'HTTP_AUTHORIZATION': 'Bearer' +self.access_token } in the response post method but is showing Unauthorized. My code is like this...

response= self.client.post("", json=dict(description="Sample Post", ,headers={'Authorization': 'Bearer' + access_token })

recervictory avatar Jul 18 '22 11:07 recervictory

@recervictory Your code is not enough to understand the problem you are facing

eadwinCode avatar Jul 18 '22 11:07 eadwinCode

@recervictory i posted my example of how i test the APIs with Ninja JWT in the issue too - maybe this helps :)

https://github.com/eadwinCode/django-ninja-extra/issues/3#issuecomment-1473551557

FabianClemenz avatar Mar 17 '23 09:03 FabianClemenz