-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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 #5134: Add tests to core_storage_story #5644
Conversation
fix linting on push fix linting on push fix linting on push fix linting befor import order on push fix hanging indent on push fix hanging indent on push
Codecov Report
@@ Coverage Diff @@
## develop #5644 +/- ##
===========================================
- Coverage 45.79% 45.74% -0.05%
===========================================
Files 513 515 +2
Lines 29872 29954 +82
Branches 4519 4522 +3
===========================================
+ Hits 13679 13702 +23
- Misses 16193 16252 +59
Continue to review full report at Codecov.
|
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.
Some comments on code styles.
class StoryModelTest(test_utils.GenericTestBase): | ||
"""Tests for Oppia story models.""" | ||
|
||
def test_story_model(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.
Add docstring explaining what is being tested here and in other functions.
commit_cmds = [{'cmd': 'test_command'}] | ||
|
||
resp = story_models.StoryModel( | ||
id='id', title='title', |
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.
I think this looks better if each arg is on a new line, like in the test function below.
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 @JoyLubega. Thanks for the PR. This looks great! A few comments from my side :)
commit_message = "test_commit_message" | ||
commit_cmds = [{'cmd': 'test_command'}] | ||
|
||
resp = story_models.StoryModel( |
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.
I am not sure what resp stands for. Could you use a more descriptive name? Probably story_model, or story_instance or similar would make it more readable.
|
||
def test_story_summary_model(self): | ||
|
||
resp = story_models.StorySummaryModel( |
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.
Ditto, regarding variable name
language_code='language_code') | ||
resp.commit(committer_id, commit_message, commit_cmds) | ||
resp = resp.key.get() | ||
self.assertEqual(resp.description, "description") |
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.
Maybe add checks for the other parameters also?
node_count=2, | ||
version=1) | ||
resp.put() | ||
resp = resp.key.get() |
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 is an interesting way to get an element by it's key. However, I think in most of the codebase, we use something similar to "story_models.StoryModel.get_by_id(story_id)". I would suggest using the get_by_id function as this is how the model gets queried in practice, and we need the test to assert that querying how we normally would should work fine without errors.
Also, one thing to note is that, to get the instance, you are using the already existing instance (which isn't how code would work in practice).
(Please make a similar change in the previous test 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.
okay, let me fix that
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.
@nithusha21 the story model does not have "get_by_id". Do I need to first write the function in the models?
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.
Nope. It is a function present in ndb.Model (see here). ndb.Model is inherited by base_model.VersionedModel which is then inherited by the story model. So these functions already exist for every model class.
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.
Thanks alot...
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.
@nithusha21 I have made all the changes but just stuck on this comment you added at the end.
Also, one thing to note is that, to get the instance, you are using the already existing instance (which isn't how code would work in practice).
Help me elaborate on this so that i push my comit.
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 @JoyLubega, I was referring to the general situation that will occur on the server. The query will be either the id, or any of the parameters of the object (in this case the id). So, the target task is to fetch the object from the datastore given just the id of the object. So I was looking for something along the lines of get_by_id(object_id).
In the earlier code where you did resp.key.get(), it was something like you know that resp is the object, you get its key and then get it again from the datastore. I was just saying that it would be better to do story_models.StoryModel.get_by_id('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.
Okay, thanks it clear now. Let me push the changes
Fix linting issue on push Fix linting issue on push
@nithusha21, @hoangviet1993 |
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.
Please reply to each review comments once you submitted your changes.
Thanks!
|
||
class StoryModelTest(test_utils.GenericTestBase): | ||
"""Tests for Oppia story models.""" | ||
def test_story_model(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.
Function docstring?
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
class StorySummaryModelTest(test_utils.GenericTestBase): | ||
"""Tests for Oppia story summary models.""" | ||
|
||
def test_story_summary_model(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.
Ditto (Re: Function docstring)
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
notes='notes', | ||
language_code='language_code') | ||
story_instance.commit(committer_id, commit_message, commit_cmds) | ||
story_by_id = story_models.StoryModel.get_by_id('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.
I feel like there should be a newline here for better readability.
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
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.
@JoyLubega I don't see the newline over here. Did you push all your changes?
node_count=2, | ||
version=1) | ||
story_summary.put() | ||
story_summary_by_id = story_models.StorySummaryModel.get_by_id('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.
Insert newline here maybe?
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
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.
Ditto, regarding newline
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.
Thanks @JoyLubega! This looks great! After making review changes, please reply "Done" on each of the review comments, so that it is easier for a reviewer to track the comments. (As mentioned in point 5 here)
Just one comment from my side.
|
||
def test_story_summary_model(self): | ||
|
||
story_summary = story_models.StorySummaryModel( |
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.
Add a "model" at the end of this variable name. We typically refer to domain objects by the noun and the models by noun with a model suffix. If you look at story_domain, you'll see a StorySummary domain class, and typically instances of that class would be referred to as story_summary. So I would prefer you make the clear distinction between models and domain objects by adding a model suffix to this variable.
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
Hi @JoyLubega, I'm going to mark this PR as stale because it hasn't had any updates for 10 days. If no further activity occurs within 7 days, it will be automatically closed so that others can take up the issue. |
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 @JoyLubega This looks great! Just a few minor details and I think this PR is good to go!
notes='notes', | ||
language_code='language_code') | ||
story_instance.commit(committer_id, commit_message, commit_cmds) | ||
story_by_id = story_models.StoryModel.get_by_id('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.
@JoyLubega I don't see the newline over here. Did you push all your changes?
node_count=2, | ||
version=1) | ||
story_summary.put() | ||
story_summary_by_id = story_models.StorySummaryModel.get_by_id('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.
Ditto, regarding newline
"""Tests for Oppia story summary models.""" | ||
|
||
def test_story_summary_model(self): | ||
"""Method to test the story_summary_model.""" |
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.
I think story_summary_model should be changed to StorySummaryModel (That's how the model class is named 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.
@nithusha21 Done>
LGTM. Thanks @JoyLubega! Congrats on your PR! |
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.
Sorry about that. Accidentally closed. Approving!
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.
Can provide more details in function docstring but that's minor. LGTM!
Merging. Congrats on your first PR, @JoyLubega! |
Thanks alot @nithusha21 @hoangviet1993 @seanlip |
Add tests to core_storage_story
Checklist
python scripts/pre_commit_linter.py
andbash scripts/run_frontend_tests.sh
.