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 tests/methods that refer to private functions in Python #7450

Open
16 of 25 tasks
kevinlee12 opened this issue Aug 24, 2019 · 145 comments · Fixed by #7841 or #7860
Open
16 of 25 tasks

Fix tests/methods that refer to private functions in Python #7450

kevinlee12 opened this issue Aug 24, 2019 · 145 comments · Fixed by #7841 or #7860
Labels
enhancement Label to indicate an issue is a feature/improvement Impact: Low -- ONLY DO IF GOOD FIRST ISSUE Postponing for now, since it doesn't affect users much. Work: Low Solution is known and broken into good-first-issue-sized chunks.

Comments

@kevinlee12
Copy link
Contributor

kevinlee12 commented Aug 24, 2019

There are currently a few tests that reference private functions in Python. Tests should test through public interface. If the test tests a private method, find a way to test the method through the existing public interface instead (you'll need to find the corresponding public API function that uses the internal private one, and use that function instead in tests). Please note that modifications to other classes outside of the file in question may be necessary.

Note that you can identify such references by searching for the string # pylint: disable=protected-access. (If you don't see the string in the file(s) you're assigned to, please let the author of this issue know so that the list can be edited accordingly.)

Important: In general, do not just change methods from private to public. You'll need to find the already existing publicly-accessible function which invokes the private method and use that one instead.

The following the cases where we test private functions:

  • gae_models.VersionedModel @Azrecycle4
    • delete
    • revert
    • get_version
    • get_multi_versions
    • get_snapshots_metadata
  • suggestion_services_test.SuggestionServicesUnitTests @gopivaibhav
    • test_accept_suggestion_commit_message_after_updating_a_suggestion
    • test_update_translation_suggestion_to_change_translation_html
  • suggestion_services_test.SuggestionIntegrationTests @hardikkat24
    • setUp
  • email_manager_test.EmailRightsTest @vijaykpatel
    • test_sender_id_validation
  • email_manager.BulkEmailsTests @brianlinUM
    • test_that_correct_email_is_sent
    • test_that_exception_is_raised_for_unauthorised_sender
  • library_test.LibraryPageTests @brianlinUM
    • test_library_handler_for_created_explorations
  • build_test (All) @Mohitbalwani26
  • suggestion_test.SuggestionUnitTests @AnuragVats007
    • setUp
  • exp_services_test.ZipFileExportUnitTests (all) @ayushjaink8

Completed:

  • draft_upgrade_services_test.DraftUpgradeUnitTests @kaylahardie
    • test_try_upgrade_success
  • draft_upgrade_services_test.DraftUpgradeUtilUnitTests @kaylahardie
    • test_convert_states_v29_dict_to_v30_dict
    • test_convert_states_v28_dict_to_v29_dict
    • test_convert_states_v27_dict_to_v28_dict
  • gae_models_test.GenerateHashTests - @lorryaze
    • test_same_inputs_always_gives_same_hashes
    • test_different_inputs_give_different_hashes
  • models_test.BaseCalculationUnitTests @donosco98 (Fix part of #7450: Modify private methods in BaseCalculationUnitTests #7841)
    • test_equality_of_hashable_answers
  • user_services_test.LastLoginIntegrationTests @vpishuk
    • test_legacy_user
  • user_services_test.LastExplorationEditedIntegrationTests @vpishuk
    • test_legacy_user
    • test_last_exp_edit_time_gets_updated
  • user_services_test.LastExplorationCreatedIntegrationTests @vpishuk
    • test_legacy_user
    • test_last_exp_edit_time_gets_updated
  • config_domain_test.ConfigPropertyRegistryTests (@nishantwrp)
    • test_config_property_schemas_are_valid
  • email_manager.DuplicateEmailTests @Hudda
    • test_send_email_does_not_resend_if_same_hash_exists
    • test_sending_email_with_different_recipient_but_same_hash
    • test_sending_email_with_different_subject_but_same_hash
    • test_sending_email_with_different_body_but_same_hash
    • test_duplicate_emails_are_sent_after_some_time_has_elapsed
  • user_jobs_one_off_test.UserFirstContributionMsecOneOffJobTests - @Arnesh07
    • test_contribution_msec_does_not_update_on_unpublished_explorations
  • user_jobs_one_off_test.UserLastExplorationActivityOneOffJobTests @Hudda
    • test_that_last_created_time_is_updated
  • html_validation_service_test.ContentMigrationTests - @cathuang20
    • test_validate_soup_for_rte
    • test_validate_customization_args_in_tag
    • test_that_last_edited_time_is_updated
    • test_that_last_edited_and_created_time_both_updated
    • test_that_last_edited_and_created_time_are_not_updated
  • rte_component_registry_test.RteComponentUnitTests - @alexlee311
    • test_rte_components_are_valid
  • extensions.interactions.base_test.InteractionUnitTests - @aazuspan
    • test_default_interactions_are_valid
  • collection_services_test @sudiptapradhan1181
    • _count_at_least_editable_collection_summaries
  • exp_services.test - @aazuspan
    • _count_at_least_editable_exploration_summaries
@kevinlee12 kevinlee12 changed the title Fix tests that refer to private functions in Python Fix tests/methods that refer to private functions in Python Aug 24, 2019
@DubeySandeep DubeySandeep pinned this issue Aug 24, 2019
@ykabusalah
Copy link

Can I try to do this?

@kevinlee12
Copy link
Contributor Author

Sure, which part would you like to do? (each major bullet point is open)

@lilithxxx
Copy link
Contributor

@kevinlee12 perhaps swap the bullet points with check-boxes?

@kevinlee12
Copy link
Contributor Author

good call, done!

@xoxwaw
Copy link

xoxwaw commented Sep 25, 2019

Hi can I take jobs_test.JobManagerUnitTests ?

@kevinlee12
Copy link
Contributor Author

sure, go for it!

@xoxwaw
Copy link

xoxwaw commented Sep 27, 2019

@ankita240796 could you please add @kevinlee12 as my reviewer? Thank you

@kevinlee12
Copy link
Contributor Author

I'll go ahead and do a review :)

@KristiKovacs
Copy link

Hello! I'd like to try: email_manager.BulkEmailsTests

@DubeySandeep
Copy link
Member

Hi @KristiKovacs, I've assigned you to email_manager.BulkEmailsTests. You can start working on it! :)

@rahmot
Copy link

rahmot commented Oct 4, 2019

Hello @DubeySandeep, I'd like to try "suggestion_services_test.SuggestionServicesUnitTests".

@DubeySandeep
Copy link
Member

@rahmot, I've assigned you to suggestion_services_test.SuggestionServicesUnitTests.

@rahmot
Copy link

rahmot commented Oct 4, 2019

@DubeySandeep, please can you put me through on how to get started with suggestion_services_test.SuggestionServicesUnitTests. Thank you!

@DubeySandeep
Copy link
Member

DubeySandeep commented Oct 4, 2019

@rahmot I would have approached this issue in the following way:

After going through the details of the issue, I understand that "Few test methods in test files are using private methods for testing, so I have to change the test methods such that it only uses the public methods."

Let's solve one test method for your case:

  1. I looked into suggestion_services_test and found test_accept_suggestion_handled_suggestion_failure method on line 350.
  2. I see line 368 is calling a private method _update_suggestion.
  3. I read the test code and found that we are trying to change the status of the suggestion and update the suggestion using the private method from the suggestion_service.
  4. Going further I read a few lines of suggestion_service and found mark_review_completed which does the same thing and I think that can be useful.

With all this information I will go ahead and change the test method and create a PR!

(Note: maybe this idea won't work, then you have to take a deeper look and find another way to solve the problem.)

I hope this helps.

@rahmot
Copy link

rahmot commented Oct 4, 2019

@DubeySandeep, thanks for the illumination. I sincerely appreciate.

@Hudda
Copy link
Contributor

Hudda commented Oct 5, 2019

Hello @DubeySandeep can I take email_manager.DuplicateEmailTests ?

@DubeySandeep
Copy link
Member

DubeySandeep commented Oct 5, 2019

Hi @Hudda, I think you haven't filled the survey form yet, would you mind doing that first? Once you complete the instructions provided here, do let us know we will go ahead and assign you to the issue you have selcted. :)

@Hudda
Copy link
Contributor

Hudda commented Oct 5, 2019

@DubeySandeep I have adhered to your instructions and filled the form.

@DubeySandeep
Copy link
Member

@Hudda, I've assigned you email_manager.DuplicateEmailTests, you can go ahead and start working on it! :)

@vojtechjelinek
Copy link
Contributor

@AnuragVats007 Done.

@gopivaibhav
Copy link
Contributor

Hey @vojtechjelinek Can you please assign me suggestion_services_test.SuggestionServicesUnitTests ?
Thank you

@vojtechjelinek
Copy link
Contributor

@gopivaibhav Done.

@Mohitbalwani26
Copy link
Contributor

Hey @vojtechjelinek, I was looking into file scripts/build_test.py as it is mentioned in the issue. It contains tests for functions like _minify, _minify_and_create_sourcemap, etc. which are defined in scripts/build.py, shouldn't these be made public in build.py in the first place like other functions get_dependencies_filepaths? If you could help me understand why they are private, it would be helpful.

@vojtechjelinek
Copy link
Contributor

@Mohitbalwani26 They are private because they are not used outside of the build.py file.

@Mohitbalwani26
Copy link
Contributor

@Mohitbalwani26 They are private because they are not used outside of the build.py file.

@vojtechjelinek I was thinking to test these functions indirectly.
For example -

build._minify(INVALID_INPUT_FILEPATH, INVALID_OUTPUT_FILEPATH) # pylint: disable=protected-access

this _minify() can also be tested if we replace _minify() with minify_func() defined in build.py as it internally calls _minify according to some conditions and we can explicitly make sure that it meets the criteria to go through.

similar is case with _ensure_files_exist()

build._ensure_files_exist(non_existent_filepaths) # pylint: disable=protected-access

this test can be merged with test of safe_delete_file() as it internally checks the existence of file by calling _ensure_files_exist().

Does this approach look good to you?

@vojtechjelinek
Copy link
Contributor

@Mohitbalwani26 Sounds good!

@ayushjaink8
Copy link
Contributor

@vojtechjelinek Can you please assign me this file: exp_services_test.ZipFileExportUnitTests (all)

@vojtechjelinek
Copy link
Contributor

@ayushjaink8 Sure.

@Mohitbalwani26
Copy link
Contributor

@vojtechjelinek can you assign me build_test.py? Also i have raised a PR for the same.

@vojtechjelinek
Copy link
Contributor

@Mohitbalwani26 Done.

@jordyparker
Copy link
Contributor

@vojtechjelinek is there any other file i can work on ? if yes, pls assign me to it

krishita30j pushed a commit that referenced this issue Mar 15, 2022
…15020)

* fix testing of private method: _minify and _ensure_files_exist

* changes as suggested in CR

* change filename variable value

* change filename variable

* fix lint issue
vojtechjelinek pushed a commit that referenced this issue Mar 16, 2022
…Tests (#15001)

Co-authored-by: Gopi Vaibhav <gopivaibhav@pop-os.localdomain>
@JeeveshGarg
Copy link
Contributor

@vojtechjelinek Please update the issue description, unassign contributors from tasks they are no longer working on, and remove completed tasks. Add additional task if any arise.

Cross check whether the GSoC project clashes with this issue. If so, let @JeeveshGarg know. in order to prevent problems for new contributors. If not, simply respond to this.

Thanks.

@vojtechjelinek
Copy link
Contributor

@JeeveshGarg Hey, can someone from the dev experience or automated QA overtake this? I no longer focus on this area.

@JeeveshGarg
Copy link
Contributor

JeeveshGarg commented Jul 16, 2022

@oppia/automated-qa-reviewers @U8NWXD @krishnarao22 ?

@U8NWXD
Copy link
Member

U8NWXD commented Jul 24, 2022

@JeeveshGarg I still need to do an audit to update this issue based on the current state of the code base. It'll have to wait until other dev workflow issues like the flakes are under control. I'd recommend removing this as a starter issue for now

@U8NWXD U8NWXD moved this to In Progress in Developer Workflow Team Aug 1, 2022
@kevintab95 kevintab95 added the enhancement Label to indicate an issue is a feature/improvement label Aug 30, 2022
@U8NWXD U8NWXD added Impact: Low -- ONLY DO IF GOOD FIRST ISSUE Postponing for now, since it doesn't affect users much. Work: Low Solution is known and broken into good-first-issue-sized chunks. and removed backend labels Oct 4, 2022
@seanlip seanlip moved this from In Progress to Todo in Developer Workflow Team Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Label to indicate an issue is a feature/improvement Impact: Low -- ONLY DO IF GOOD FIRST ISSUE Postponing for now, since it doesn't affect users much. Work: Low Solution is known and broken into good-first-issue-sized chunks.
Projects
Status: Todo