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

Test : Create unit tests for User Info #94

Closed
wants to merge 3 commits into from

Conversation

decon-harsh
Copy link
Member

Description

Created Test database test_osp
Added few unit tests for User Info Get & Post, Login & Register routes.

Fixes #78

Type of Change:

  • Code
  • Quality Assurance
  • Documentation

Code/Quality Assurance Only

  • This change requires a documentation update (software upgrade on readme file)
  • New feature (non-breaking change which adds functionality pre-approved by mentors)

How Has This Been Tested?

Automated tests

Screenshot from 2021-02-15 03-02-55

Formatted with ./osp-qa-checks

Checklist:

  • My PR follows the style guidelines of this project
  • I have performed a self-review of my own code or materials
  • I have commented on my code or provided relevant documentation, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Code/Quality Assurance Only

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@decon-harsh
Copy link
Member Author

@codesankalp I don't know why my build test is failing it is successfully running on my local

@codesankalp
Copy link
Member

@codesankalp I don't know why my build test is failing it is successfully running on my local

Don't worry about the test build. It will fail for all pull requests for now.
@decon-harsh

@decon-harsh
Copy link
Member Author

decon-harsh commented Feb 20, 2021

@codesankalp can you tell me what should have been done to avoid the previous mistake?

I rebased everything which added new commits of other contributers .

Then ran the linters which modified the files so i created a new commit thought of merging it with my previous commit

It got merged with all of them.

@decon-harsh
Copy link
Member Author

decon-harsh commented Feb 20, 2021

@codesankalp nvm i got it i should have reordered commits and then squashed them

@codesankalp
Copy link
Member

@decon-harsh Actually you added commits after your commit. This is the previous mistake.

@codesankalp codesankalp added the Status: Needs Review PR needs an additional review or a maintainer's review. label Feb 21, 2021
Copy link
Member

@codesankalp codesankalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write another test for providing the wrong zulip id in the POST request for testing validation error?
I think it must be included in this test pr 🤔

Tested locally:
tests are working fine.
Screenshots:
image

main/settings.py Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
tests/test_api_user_info.py Show resolved Hide resolved
@decon-harsh
Copy link
Member Author

@codesankalp Umm but what should I compare??

  • The username , they might be diff
  • The email , zulip has diff email

@codesankalp
Copy link
Member

@codesankalp Umm but what should I compare??

  • The username , they might be diff
  • The email , zulip has diff email

Use the data of test_user for comparing, get and post request.

@decon-harsh
Copy link
Member Author

@codesankalp Umm but what should I compare??

  • The username , they might be diff
  • The email , zulip has diff email

Use the data of test_user for comparing, get and post request.

We can't, cause the data of test_user and Zulip user isn't the same.
For ex: Test data's full name is Test User 1 Full name whereas, Zulip User id is my personal id and username is Harsh Singh, the email is not the same.

@codesankalp

@codesankalp
Copy link
Member

@codesankalp Umm but what should I compare??

  • The username , they might be diff
  • The email , zulip has diff email

Use the data of test_user for comparing, get and post request.

We can't, cause the data of test_user and Zulip user isn't the same.
For ex: Test data's full name is Test User 1 Full name whereas, Zulip User id is my personal id and username is Harsh Singh, the email is not the same.

@codesankalp

Add assertion for the response you get is not empty list in test_get_user_info_successfully.

Copy link
Member

@codesankalp codesankalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested some changes @decon-harsh

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
tests/test_api_user_info.py Show resolved Hide resolved
@devkapilbansal
Copy link
Member

@codesankalp these tests should only run when pushed to master, not on pull request. As discussed with @isabelcosta tests related to zulip api will not be done on pull request because it will require API Key. However, we can ensure that these tests passed locally or on the fork of the contributor.

@isabelcosta
Copy link
Member

@codesankalp these tests should only run when pushed to master, not on pull request. As discussed with @isabelcosta tests related to zulip api will not be done on pull request because it will require API Key. However, we can ensure that these tests passed locally or on the fork of the contributor.

we should still be able to test zulip functionalities without using a real key 🤔 not sure how though

@devkapilbansal
Copy link
Member

@codesankalp these tests should only run when pushed to master, not on pull request. As discussed with @isabelcosta tests related to zulip api will not be done on pull request because it will require API Key. However, we can ensure that these tests passed locally or on the fork of the contributor.

we should still be able to test zulip functionalities without using a real key not sure how though

@isabelcosta We can't fetch the details without passing the key. However, may be we can run these cases only on push if needed. Else you have to create an environment to pass the tokens.

@decon-harsh
Copy link
Member Author

decon-harsh commented Feb 26, 2021

Question: Can we run specific test files on PR? On the terminal, I do python3 manage.py test tests.{filename} or ignore some failures?.

As @devkapilbansal suggested we should run these tests only on push to master, a forked user must have zulip_key to run tests.

cc @codesankalp @isabelcosta
Screenshot from 2021-02-26 18-31-21

@decon-harsh
Copy link
Member Author

I have done the necessary changes , was waiting for the approach on zulip_tests thought will do it together .

Please Let me know what should i need to do next!

@devkapilbansal
Copy link
Member

@decon-harsh you need to mock the function calls of zulip APIs in test cases. Doing so will remove dependency of tests on zulip_api_key.
Cc:- @codesankalp @isabelcosta

@codesankalp
Copy link
Member

@decon-harsh Take reference from this: #102 (comment)
And Let me know if you need any help.

@isabelcosta
Copy link
Member

@decon-harsh can you please update this branch with develop to make sure we don't see errors on GitHub actions because of zulip key issue :)

@decon-harsh decon-harsh force-pushed the Issue78 branch 2 times, most recently from 6e82848 to 86d4a53 Compare March 7, 2021 22:02
@decon-harsh
Copy link
Member Author

@isabelcosta I updated my branch with develop , which created this merge commit (the second one), How should I avoid it ?

by doing git pull --rebase ?

@codesankalp
Copy link
Member

@decon-harsh As you have made the merge commit git pull --rebase will show you updated.
To remove merge-commit you can try this:

git reset --soft 129064c0b71b1f34dd64faf9f8b39b6aa80264ce
git add .
git commit
git push -f

This will remove your merge commit and will squash your commits also.

@decon-harsh
Copy link
Member Author

I will definitely try this @codesankalp thank you

@isabelcosta
Copy link
Member

I see now the problem 🤦🏾‍♀️ it's because of a recent PR. Will have a think about it!

@codesankalp
Copy link
Member

@decon-harsh You can use my implementation of mocking the API: #109

@decon-harsh
Copy link
Member Author

decon-harsh commented Mar 12, 2021

@decon-harsh You can use my implementation of mocking the API: #109

I am afraid i can't use this directly as I have to mock zulip client . For this I think I have to use patch.

For some reasons I had to reinstall Postgres and now I am having some errors! I can't run server.

@codesankalp
Copy link
Member

@decon-harsh You can use my implementation of mocking the API: #109

I am afraid i can't use this directly as I have to mock zulip client . For this I think I have to use patch.

For some reasons I had to reinstall Postgres and now I am having some errors! I can't run server.

What did you try @decon-harsh? Using my implementation will work, I have tried it.
But you can use any method of mocking.

@devkapilbansal
Copy link
Member

@decon-harsh @codesankalp I would suggest using responses module to patch the responses.

@decon-harsh
Copy link
Member Author

@codesankalp @devkapilbansal help me in understanding me this.

I have to mock the responses of a client . There is no endpoint to mock right? So I can't use responses.add(endpoint,...). There is a function get_self_zulip_id(). So i have to mock it's response. I mean the client.get_profile().

What should i do in this case?

@codesankalp
Copy link
Member

@decon-harsh @codesankalp I would suggest using responses module to patch the responses.

Yes, that is the thing I have also used @devkapilbansal.

@codesankalp
Copy link
Member

codesankalp commented Mar 12, 2021

@codesankalp @devkapilbansal help me in understanding me this.

I have to mock the responses of a client . There is no endpoint to mock right? So I can't use responses.add(endpoint,...). There is a function get_self_zulip_id(). So i have to mock it's response. I mean the client.get_profile().

What should i do in this case?

But you have the endpoint for zulip, right?
Just mock it.
URL: http://127.0.0.1:8000/api/zulip_stat/

@devkapilbansal devkapilbansal added Status: Changes Requested Changes are required to be done by the PR author. and removed Status: Needs Review PR needs an additional review or a maintainer's review. labels Mar 16, 2021
@codesankalp
Copy link
Member

@decon-harsh Any update on this?

@decon-harsh
Copy link
Member Author

@decon-harsh Any update on this?

Sorry to keep you waiting I will do this tommorow.

@codesankalp
Copy link
Member

@decon-harsh Any update on this?

Sorry to keep you waiting I will do this tommorow.

@decon-harsh Please update this. Most of the work is done you have to just mock the API.

@codesankalp
Copy link
Member

Closing this PR due to inactivity and not responding for giving updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Changes Requested Changes are required to be done by the PR author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create unit tests for User info API
4 participants