-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Assigning to @nithusha21 for first pass. |
There was a problem hiding this 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
@nithusha21 PTAL! |
There was a problem hiding this 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
|
||
suggestion_models.GeneralSuggestionModel.create( | ||
suggestion_models.SUGGESTION_TYPE_ADD_QUESTION, | ||
suggestion_models.TARGET_TYPE_QUESTION, self.EXP_ID, |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@nithusha21 your comments are addressed. PTAL! |
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! |
@nithusha21 addressed all comments. PTAL! |
There was a problem hiding this 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.
core/controllers/suggestion_test.py
Outdated
|
||
self.logout() | ||
|
||
def test_reject_suggestion(self): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@nithusha21 @seanlip PTAL! |
There was a problem hiding this 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 :)
@nithusha21 PTAL as codeowner. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
Explanation
Fixes part of #6550: Write tests for controllers/suggestion
Checklist
python scripts/pre_commit_linter.py
andbash scripts/run_frontend_tests.sh
.