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 #5134: Add tests to core_storage_story #5644

Merged
merged 10 commits into from
Oct 7, 2018
Merged

Fix part of #5134: Add tests to core_storage_story #5644

merged 10 commits into from
Oct 7, 2018

Conversation

JoyLubega
Copy link
Contributor

Add tests to core_storage_story

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes.
  • The PR explanation includes the words "Fixes #bugnum: ...".
  • 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 follows the style guide.
  • The PR is assigned to an appropriate reviewer.
    • If you're a new contributor, please ask on Gitter for someone to assign a reviewer.
    • 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.

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-io
Copy link

codecov-io commented Sep 12, 2018

Codecov Report

Merging #5644 into develop will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
...ory_editor/StoryEditorNavbarBreadcrumbDirective.js 6.25% <0%> (-13.75%) ⬇️
...itor/editor_tab/SkillDescriptionEditorDirective.js 5.88% <0%> (-0.79%) ⬇️
...r/editor_tab/SkillMisconceptionsEditorDirective.js 2.22% <0%> (-0.16%) ⬇️
...s_and_skills_dashboard/TopicsAndSkillsDashboard.js 9.37% <0%> (-0.15%) ⬇️
...es/topic_editor/questions/QuestionsTabDirective.js 0.71% <0%> (-0.15%) ⬇️
...d/pages/skill_editor/SkillEditorNavbarDirective.js 1.81% <0%> (-0.11%) ⬇️
...itor/editor_tab/SkillConceptCardEditorDirective.js 1.51% <0%> (-0.1%) ⬇️
...plates/dev/head/components/CkEditorRteDirective.js 1.23% <0%> (-0.09%) ⬇️
...ead/pages/exploration_player/TutorCardDirective.js 2.27% <0%> (-0.06%) ⬇️
...pages/state_editor/StateSolutionEditorDirective.js 1.08% <0%> (-0.03%) ⬇️
... and 20 more

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 eb6c0ff...c8829c1. Read the comment docs.

Copy link
Contributor

@hoangviet1993 hoangviet1993 left a 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):
Copy link
Contributor

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',
Copy link
Contributor

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.

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 @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(
Copy link
Contributor

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(
Copy link
Contributor

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")
Copy link
Contributor

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()
Copy link
Contributor

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)

Copy link
Contributor Author

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

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks alot...

Copy link
Contributor Author

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.

Copy link
Contributor

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').

Copy link
Contributor Author

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
@JoyLubega
Copy link
Contributor Author

@nithusha21, @hoangviet1993
please review my changes

Copy link
Contributor

@hoangviet1993 hoangviet1993 left a 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):
Copy link
Contributor

Choose a reason for hiding this comment

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

Function docstring?

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

class StorySummaryModelTest(test_utils.GenericTestBase):
"""Tests for Oppia story summary models."""

def test_story_summary_model(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto (Re: Function docstring)

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

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')
Copy link
Contributor

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.

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

Copy link
Contributor

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')
Copy link
Contributor

Choose a reason for hiding this comment

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

Insert newline here maybe?

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto, regarding newline

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.

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(
Copy link
Contributor

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.

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

@oppiabot
Copy link

oppiabot bot commented Oct 1, 2018

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.
If you are still working on this PR, please make a follow-up commit within 7 days (and submit it for review, if applicable). Please also let us know if you are stuck so we can help you!

@oppiabot oppiabot bot added the stale label Oct 1, 2018
@oppiabot oppiabot bot removed the stale label Oct 2, 2018
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 @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')
Copy link
Contributor

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')
Copy link
Contributor

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."""
Copy link
Contributor

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?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nithusha21 Done>

@nithusha21
Copy link
Contributor

LGTM. Thanks @JoyLubega! Congrats on your PR!

@nithusha21 nithusha21 closed this Oct 5, 2018
@nithusha21 nithusha21 reopened this Oct 5, 2018
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.

Sorry about that. Accidentally closed. Approving!

Copy link
Contributor

@hoangviet1993 hoangviet1993 left a 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!

@seanlip
Copy link
Member

seanlip commented Oct 7, 2018

Merging. Congrats on your first PR, @JoyLubega!

@seanlip seanlip merged commit f887c01 into oppia:develop Oct 7, 2018
@JoyLubega
Copy link
Contributor Author

Thanks alot @nithusha21 @hoangviet1993 @seanlip

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.

5 participants