Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django Rest Framework Testing #18

Open
jcriddle-nci opened this issue Nov 3, 2020 · 0 comments
Open

Django Rest Framework Testing #18

jcriddle-nci opened this issue Nov 3, 2020 · 0 comments

Comments

@jcriddle-nci
Copy link

jcriddle-nci commented Nov 3, 2020

Hi,

I have gotten this working and am very grateful for your work, well done!

Something that I think needs to be done is the addition of testing. Could you add an example of how to go about using the Django testing framework to create user and login.

The part I get stuck at is that when I go to login(using the testing, I get the index.html page back and not the aceess and refresh token.

I have two functions:

def setUp(self):
        
    try:
        response = self.client.post('/user/create/', {"username":TEST_USER_LOGIN_NAME, "password":TEST_USER_LOGIN_PASSWORD, "email":TEST_USER_LOGIN_EMAIL}, format="json")
    except:
        print("Error occured while creating the user login")

and

    def test_GetListProducts(self):
        response = self.client.post("/token/obtain/", {"username":TEST_USER_LOGIN_NAME, "password":TEST_USER_LOGIN_PASSWORD}, format="json")
        # print(response) <-- This gives me back the index.html instead of the response with access and refresh tokens

        #self.client.credentials(HTTP_AUTHORIZATION='Token ' + response.data['access'])
        response = self.client.get('productss/')
        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual(True, True)

any help would be greatly appreciated. Or if you want to put up your own example it would be helpful too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant