Skip to content

Commit

Permalink
Separates exploration model getters from exp_services (oppia#7093)
Browse files Browse the repository at this point in the history
* Created exp_fetchers.py file.

* Fixed import issue.

* Fix mock method issues.

* Fixed test issue.
  • Loading branch information
DubeySandeep authored and brianrodri committed Jul 14, 2019
1 parent b9a98b3 commit 574b643
Show file tree
Hide file tree
Showing 50 changed files with 1,155 additions and 1,095 deletions.
5 changes: 3 additions & 2 deletions core/controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from core.domain import config_domain
from core.domain import config_services
from core.domain import exp_domain
from core.domain import exp_fetchers
from core.domain import exp_services
from core.domain import recommendations_services
from core.domain import rights_manager
Expand Down Expand Up @@ -276,7 +277,7 @@ def _generate_dummy_explorations(
for i in range(num_dummy_exps_to_generate):
title = random.choice(possible_titles)
category = random.choice(constants.SEARCH_DROPDOWN_CATEGORIES)
new_exploration_id = exp_services.get_new_exploration_id()
new_exploration_id = exp_fetchers.get_new_exploration_id()
exploration = exp_domain.Exploration.create_default_exploration(
new_exploration_id, title=title, category=category,
objective='Dummy Objective')
Expand Down Expand Up @@ -392,7 +393,7 @@ def get(self):
exp_id = self.request.get('exp_id')
try:
exp_version = int(self.request.get('exp_version'))
exploration = exp_services.get_exploration_by_id(
exploration = exp_fetchers.get_exploration_by_id(
exp_id, version=exp_version)
except Exception:
raise self.InvalidInputException(
Expand Down
3 changes: 2 additions & 1 deletion core/controllers/classifier_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from core.domain import classifier_services
from core.domain import config_domain
from core.domain import email_manager
from core.domain import exp_fetchers
from core.domain import exp_services
from core.platform import models
from core.tests import test_utils
Expand Down Expand Up @@ -54,7 +55,7 @@ def setUp(self):
exp_services.save_new_exploration_from_yaml_and_assets(
feconf.SYSTEM_COMMITTER_ID, self.yaml_content, self.exp_id,
assets_list)
self.exploration = exp_services.get_exploration_by_id(self.exp_id)
self.exploration = exp_fetchers.get_exploration_by_id(self.exp_id)

self.classifier_data_with_floats_stringified = {
'_alpha': '0.1',
Expand Down
6 changes: 3 additions & 3 deletions core/controllers/collection_editor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from core.domain import collection_domain
from core.domain import collection_services
from core.domain import exp_services
from core.domain import exp_fetchers
from core.domain import rights_manager
from core.domain import user_services
from core.tests import test_utils
Expand Down Expand Up @@ -275,7 +275,7 @@ def test_can_not_publish_collection_with_invalid_payload_version(self):
# exploration.
self.login(self.OWNER_EMAIL)
collection_id = collection_services.get_new_collection_id()
exploration_id = exp_services.get_new_exploration_id()
exploration_id = exp_fetchers.get_new_exploration_id()
self.save_new_valid_exploration(exploration_id, self.owner_id)
self.save_new_valid_collection(
collection_id, self.owner_id, exploration_id=exploration_id)
Expand Down Expand Up @@ -310,7 +310,7 @@ def test_can_not_unpublish_collection_with_invalid_payload_version(self):
# Login as owner and publish a collection with a public exploration.
self.login(self.OWNER_EMAIL)
collection_id = collection_services.get_new_collection_id()
exploration_id = exp_services.get_new_exploration_id()
exploration_id = exp_fetchers.get_new_exploration_id()
self.save_new_valid_exploration(exploration_id, self.owner_id)
self.save_new_valid_collection(
collection_id, self.owner_id, exploration_id=exploration_id)
Expand Down
7 changes: 4 additions & 3 deletions core/controllers/creator_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from core.domain import config_domain
from core.domain import dependency_registry
from core.domain import exp_domain
from core.domain import exp_fetchers
from core.domain import exp_services
from core.domain import feedback_services
from core.domain import interaction_registry
Expand Down Expand Up @@ -172,7 +173,7 @@ def _round_average_ratings(rating):
# originally subscribed to may have been deleted since.
subscribed_exploration_summaries = [
summary for summary in
exp_services.get_exploration_summaries_matching_ids(
exp_fetchers.get_exploration_summaries_matching_ids(
subscription_services.get_exploration_ids_subscribed_to(
self.user_id))
if summary is not None]
Expand Down Expand Up @@ -379,7 +380,7 @@ def post(self):
"""Handles POST requests."""
title = self.payload.get('title', feconf.DEFAULT_EXPLORATION_TITLE)

new_exploration_id = exp_services.get_new_exploration_id()
new_exploration_id = exp_fetchers.get_new_exploration_id()
exploration = exp_domain.Exploration.create_default_exploration(
new_exploration_id, title=title)
exp_services.save_new_exploration(self.user_id, exploration)
Expand Down Expand Up @@ -413,7 +414,7 @@ def post(self):
"""Handles POST requests."""
yaml_content = self.request.get('yaml_file')

new_exploration_id = exp_services.get_new_exploration_id()
new_exploration_id = exp_fetchers.get_new_exploration_id()
if constants.ALLOW_YAML_FILE_UPLOAD:
exp_services.save_new_exploration_from_yaml_and_assets(
self.user_id, yaml_content, new_exploration_id, [],
Expand Down
3 changes: 2 additions & 1 deletion core/controllers/creator_dashboard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from core.controllers import creator_dashboard
from core.domain import collection_services
from core.domain import event_services
from core.domain import exp_fetchers
from core.domain import exp_services
from core.domain import feedback_domain
from core.domain import feedback_services
Expand Down Expand Up @@ -921,7 +922,7 @@ def test_can_upload_exploration(self):
csrf_token=csrf_token)[creator_dashboard.EXPLORATION_ID_KEY]
explorations_list = self.get_json(
feconf.CREATOR_DASHBOARD_DATA_URL)['explorations_list']
exploration = exp_services.get_exploration_by_id(exp_a_id)
exploration = exp_fetchers.get_exploration_by_id(exp_a_id)
self.assertEqual(explorations_list[0]['id'], exp_a_id)
self.assertEqual(exploration.to_yaml(), self.SAMPLE_YAML_CONTENT)
self.logout()
Expand Down
19 changes: 10 additions & 9 deletions core/controllers/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from core.domain import dependency_registry
from core.domain import email_manager
from core.domain import exp_domain
from core.domain import exp_fetchers
from core.domain import exp_services
from core.domain import fs_domain
from core.domain import fs_services
Expand Down Expand Up @@ -176,7 +177,7 @@ def get(self, exploration_id):
@acl_decorators.can_edit_exploration
def put(self, exploration_id):
"""Updates properties of the given exploration."""
exploration = exp_services.get_exploration_by_id(exploration_id)
exploration = exp_fetchers.get_exploration_by_id(exploration_id)
version = self.payload.get('version')
_require_valid_version(version, exploration.version)

Expand Down Expand Up @@ -221,7 +222,7 @@ class ExplorationRightsHandler(EditorHandler):
@acl_decorators.can_modify_exploration_roles
def put(self, exploration_id):
"""Updates the editing rights for the given exploration."""
exploration = exp_services.get_exploration_by_id(exploration_id)
exploration = exp_fetchers.get_exploration_by_id(exploration_id)
version = self.payload.get('version')
_require_valid_version(version, exploration.version)

Expand All @@ -244,7 +245,7 @@ def put(self, exploration_id):
exploration.title)

elif make_community_owned:
exploration = exp_services.get_exploration_by_id(exploration_id)
exploration = exp_fetchers.get_exploration_by_id(exploration_id)
try:
exploration.validate(strict=True)
except utils.ValidationError as e:
Expand Down Expand Up @@ -279,7 +280,7 @@ def _publish_exploration(self, exploration_id):
Raises:
InvalidInputException: Given exploration is invalid.
"""
exploration = exp_services.get_exploration_by_id(exploration_id)
exploration = exp_fetchers.get_exploration_by_id(exploration_id)
try:
exploration.validate(strict=True)
except utils.ValidationError as e:
Expand Down Expand Up @@ -310,7 +311,7 @@ def put(self, exploration_id):
"""Unpublishes the given exploration, and sends an email to all its
owners.
"""
exploration = exp_services.get_exploration_by_id(exploration_id)
exploration = exp_fetchers.get_exploration_by_id(exploration_id)
email_body = self.payload.get('email_body')
version = self.payload.get('version')
_require_valid_version(version, exploration.version)
Expand Down Expand Up @@ -390,7 +391,7 @@ class ExplorationFileDownloader(EditorHandler):
@acl_decorators.can_download_exploration
def get(self, exploration_id):
"""Handles GET requests."""
exploration = exp_services.get_exploration_by_id(exploration_id)
exploration = exp_fetchers.get_exploration_by_id(exploration_id)

version_str = self.request.get('v', default_value=exploration.version)
output_format = self.request.get('output_format', default_value='zip')
Expand Down Expand Up @@ -503,7 +504,7 @@ class ExplorationStatisticsHandler(EditorHandler):
@acl_decorators.can_view_exploration_stats
def get(self, exploration_id):
"""Handles GET requests."""
current_exploration = exp_services.get_exploration_by_id(
current_exploration = exp_fetchers.get_exploration_by_id(
exploration_id)

self.render_json(stats_services.get_exploration_stats(
Expand All @@ -518,7 +519,7 @@ class StateRulesStatsHandler(EditorHandler):
@acl_decorators.can_view_exploration_stats
def get(self, exploration_id, escaped_state_name):
"""Handles GET requests."""
current_exploration = exp_services.get_exploration_by_id(
current_exploration = exp_fetchers.get_exploration_by_id(
exploration_id)

state_name = utils.unescape_encoded_uri_component(escaped_state_name)
Expand Down Expand Up @@ -742,7 +743,7 @@ class StateAnswerStatisticsHandler(EditorHandler):
@acl_decorators.can_view_exploration_stats
def get(self, exploration_id):
"""Handles GET requests."""
current_exploration = exp_services.get_exploration_by_id(exploration_id)
current_exploration = exp_fetchers.get_exploration_by_id(exploration_id)

top_state_answers = stats_services.get_top_state_answer_stats_multi(
exploration_id, current_exploration.states)
Expand Down
Loading

0 comments on commit 574b643

Please sign in to comment.