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

Fix part of #6550: Write tests for controllers/suggestion #6822

Merged
merged 10 commits into from
Jun 15, 2019

Conversation

lilithxxx
Copy link
Contributor

@lilithxxx lilithxxx commented May 30, 2019

Explanation

Fixes part of #6550: Write tests for controllers/suggestion

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The linter/Karma presubmit checks have passed.
    • These should run automatically, but if not, you can manually trigger them locally using python scripts/pre_commit_linter.py and bash scripts/run_frontend_tests.sh.
  • The PR is made from a branch that's not called "develop".
  • The PR has an appropriate "CHANGELOG: ..." label (If you are unsure of which label to add, ask the reviewers for guidance).
  • The PR follows the style guide.
  • The PR addresses the points mentioned in the codeowner checks for the files/folders changed. (See the codeowner's wiki page.)
  • The PR is assigned to an appropriate reviewer.
    • If you're a new contributor, please ask on Gitter for someone to assign a reviewer and don't tick this checkbox.
    • If you're not sure who the appropriate reviewer is, please assign to the issue's "owner" -- see the "talk-to" label on the issue. Do not only request the review but also add the reviewer as an assignee.

@codecov
Copy link

codecov bot commented May 30, 2019

Codecov Report

Merging #6822 into develop will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6822      +/-   ##
===========================================
+ Coverage    95.68%   95.73%   +0.04%     
===========================================
  Files          371      371              
  Lines        51429    51604     +175     
===========================================
+ Hits         49212    49404     +192     
+ Misses        2217     2200      -17
Impacted Files Coverage Δ
core/controllers/acl_decorators.py 98.68% <100%> (+0.01%) ⬆️
core/controllers/suggestion_test.py 100% <100%> (ø) ⬆️
core/controllers/suggestion.py 100% <100%> (+21.62%) ⬆️
core/domain/suggestion_services.py 90.47% <0%> (+0.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3069fe6...91f7c15. Read the comment docs.

@seanlip
Copy link
Member

seanlip commented May 30, 2019

Assigning to @nithusha21 for first pass.

Copy link
Contributor

@nithusha21 nithusha21 left a comment

Choose a reason for hiding this comment

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

Hi @lilithxxx did a first pass. Overall looks good. Left some comments/questions

core/controllers/suggestion_test.py Outdated Show resolved Hide resolved
core/controllers/suggestion_test.py Show resolved Hide resolved
core/controllers/suggestion_test.py Show resolved Hide resolved
core/controllers/suggestion_test.py Show resolved Hide resolved
core/controllers/suggestion_test.py Outdated Show resolved Hide resolved
core/controllers/suggestion_test.py Outdated Show resolved Hide resolved
core/controllers/suggestion_test.py Show resolved Hide resolved
core/controllers/suggestion_test.py Show resolved Hide resolved
core/controllers/suggestion_test.py Show resolved Hide resolved
@nithusha21 nithusha21 assigned lilithxxx and unassigned nithusha21 Jun 1, 2019
@lilithxxx lilithxxx assigned nithusha21 and unassigned lilithxxx Jun 2, 2019
@lilithxxx
Copy link
Contributor Author

@nithusha21 PTAL!

Copy link
Contributor

@nithusha21 nithusha21 left a comment

Choose a reason for hiding this comment

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

Looks good... A few more comments.

core/controllers/suggestion_test.py Outdated Show resolved Hide resolved

suggestion_models.GeneralSuggestionModel.create(
suggestion_models.SUGGESTION_TYPE_ADD_QUESTION,
suggestion_models.TARGET_TYPE_QUESTION, self.EXP_ID,
Copy link
Contributor

Choose a reason for hiding this comment

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

This suggestion type is supposed to use suggestion_models.TARGET_TYPE_TOPIC. Don't use the creation functions in the models directly (here and elsewhere). Create the models using the services (which does these checks automatically).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a service called create_suggestion in suggestion_services but that does not allow us to choose the thread id -- it creates one of its own, and we need the thread id to send the request(get_json, post_json etc). The only way to use the service would be to do self.swap but I was confused which was the better choice (creating the model or doing self.swap). Should I use self.swap instead then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And why should the suggestion type necessarily has to be TARGET_TYPE_TOPIC. We are testing it with incorrect target type where the correct type is TARGET_TYPE_EXPLORATION. Hence any other types other than TARGET_TYPE_EXPLORATION should be fine, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

The correct type here is TARGET_TYPE_TOPIC (see suggestion_registry). We have one controller for every type of target. So what you should be testing is that a valid suggestion, passed to the wrong controller should raise an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could also get the thread ID by crafting a query to the suggestion list handler (an extra step, but prevents directly manipulating models. By directly adding models, we bypass the validations written in the domain/service layers).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes you are correct. Will fix this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

core/controllers/suggestion_test.py Show resolved Hide resolved
core/controllers/suggestion_test.py Show resolved Hide resolved
@lilithxxx
Copy link
Contributor Author

@nithusha21 your comments are addressed. PTAL!

@brianrodri brianrodri assigned seanlip and unassigned seanlip Jun 9, 2019
@nithusha21
Copy link
Contributor

Hi Rishav, sorry for the late response. Add question suggestions should have target as topic (You can look at the domain classes in suggestion_registry to see what the corresponding types are). I left a comment above, let me know if you want to discuss further!

@lilithxxx
Copy link
Contributor Author

@nithusha21 addressed all comments. PTAL!

Copy link
Contributor

@nithusha21 nithusha21 left a comment

Choose a reason for hiding this comment

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

One comment @lilithxxx. Other than this LGTM.


self.logout()

def test_reject_suggestion(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

test_reject_suggestion_to_topic maybe? Are we not testing the "accept" action? Though probably without that test too, the coverage might be a 100%, I would suggest adding a test for that too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@nithusha21 nithusha21 assigned lilithxxx and unassigned nithusha21 Jun 14, 2019
@lilithxxx
Copy link
Contributor Author

@nithusha21 @seanlip PTAL!

@lilithxxx lilithxxx assigned seanlip and nithusha21 and unassigned lilithxxx Jun 14, 2019
Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

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

@lilithxxx, these look fantastic to me. Thank you! LGTM :)

@seanlip seanlip removed their assignment Jun 14, 2019
@seanlip
Copy link
Member

seanlip commented Jun 14, 2019

@nithusha21 PTAL as codeowner.

Copy link
Contributor

@nithusha21 nithusha21 left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

@nithusha21 nithusha21 merged commit 7cdd42c into oppia:develop Jun 15, 2019
@lilithxxx lilithxxx deleted the suggestion_test branch June 15, 2019 09:53
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

Successfully merging this pull request may close these issues.

3 participants