Skip to content

Commit

Permalink
Lint fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlip committed Nov 5, 2014
1 parent 7a822e4 commit 717b735
Show file tree
Hide file tree
Showing 28 changed files with 136 additions and 124 deletions.
3 changes: 2 additions & 1 deletion core/controllers/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ def get(self, exploration_id):
"""Handles GET requests."""

try:
snapshots = exp_services.get_exploration_snapshots_metadata(exploration_id)
snapshots = exp_services.get_exploration_snapshots_metadata(
exploration_id)
except:
raise self.PageNotFoundException

Expand Down
1 change: 0 additions & 1 deletion core/controllers/editor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ class ExplorationDownloadIntegrationTest(BaseEditorControllerTest):
feconf.DEFAULT_INIT_STATE_NAME
)).replace('<', '\\u003c').replace('>', '\\u003e')


def test_exploration_download_handler_for_default_exploration(self):

# Register and log in as an editor.
Expand Down
6 changes: 4 additions & 2 deletions core/controllers/galleries.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def get(self):
}

# Get non-private and viewable private exploration summaries
exp_summaries_dict = exp_services.get_non_private_exploration_summaries()
exp_summaries_dict = (
exp_services.get_non_private_exploration_summaries())
if self.user_id:
exp_summaries_dict.update(
exp_services.get_private_at_least_viewable_exploration_summaries(
Expand Down Expand Up @@ -134,7 +135,8 @@ def get(self):
private_explorations_list.append(e_dict)
elif e_dict['status'] == rights_manager.EXPLORATION_STATUS_PUBLIC:
beta_explorations_list.append(e_dict)
elif e_dict['status'] == rights_manager.EXPLORATION_STATUS_PUBLICIZED:
elif (e_dict['status'] ==
rights_manager.EXPLORATION_STATUS_PUBLICIZED):
released_explorations_list.append(e_dict)

private_explorations_list = sorted(
Expand Down
3 changes: 0 additions & 3 deletions core/controllers/galleries_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

__author__ = 'Sean Lip'

from core import jobs_registry
from core.controllers import galleries
from core.domain import config_services
from core.domain import exp_jobs
Expand Down Expand Up @@ -116,7 +115,6 @@ def test_gallery_handler_demo_exploration(self):
'status': rights_manager.EXPLORATION_STATUS_PUBLICIZED,
}, response_dict['released'][0])


def test_gallery_handler_for_created_explorations(self):
"""Test the gallery data handler for manually created explirations."""

Expand Down Expand Up @@ -210,7 +208,6 @@ def test_gallery_handler_for_created_explorations(self):
'status': rights_manager.EXPLORATION_STATUS_PUBLICIZED,
}, response_dict['released'][0])


def test_new_exploration_ids(self):
"""Test generation of exploration ids."""
self.register_editor(self.EDITOR_EMAIL)
Expand Down
1 change: 0 additions & 1 deletion core/controllers/pages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
__author__ = 'Sean Lip'

from core.tests import test_utils
import feconf


class NoninteractivePagesTest(test_utils.GenericTestBase):
Expand Down
1 change: 0 additions & 1 deletion core/controllers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from core.controllers import base
from core.domain import config_domain
from core.domain import exp_services
from core.domain import user_services
import feconf
import utils
Expand Down
3 changes: 2 additions & 1 deletion core/controllers/reader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def test_unpublished_explorations_are_invisible_to_other_editors(self):

other_exploration = exp_domain.Exploration.create_default_exploration(
'eid2', 'A title', 'A category')
exp_services.save_new_exploration(other_editor_email, other_exploration)
exp_services.save_new_exploration(
other_editor_email, other_exploration)

self.login(other_editor_email)
response = self.testapp.get(
Expand Down
1 change: 0 additions & 1 deletion core/domain/config_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@


from core.domain import config_domain
from core.domain import obj_services
from core.platform import models
(config_models,) = models.Registry.import_models([models.NAMES.config])
memcache_services = models.Registry.import_memcache_services()
Expand Down
11 changes: 7 additions & 4 deletions core/domain/event_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ def _handle_event(

class ExplorationContentChangeEventHandler(BaseEventHandler):
"""Event handler for receiving exploration change events. This event is
triggered whenever changes to an exploration's contents or metadata (title, blurb etc.)
are persisted. This includes when a a new exploration is created."""
triggered whenever changes to an exploration's contents or metadata (title,
blurb etc.) are persisted. This includes when a a new exploration is
created.
"""

EVENT_TYPE = feconf.EVENT_TYPE_EXPLORATION_CHANGE

Expand All @@ -154,8 +156,9 @@ def _handle_event(cls, *args, **kwargs):

class ExplorationStatusChangeEventHandler(BaseEventHandler):
"""Event handler for receiving exploration status change events.
These events are triggered whenever an exploration is published, publicized,
unpublished or unpublicized."""
These events are triggered whenever an exploration is published,
publicized, unpublished or unpublicized.
"""

EVENT_TYPE = feconf.EVENT_TYPE_EXPLORATION_STATUS_CHANGE

Expand Down
28 changes: 16 additions & 12 deletions core/domain/exp_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ def __init__(self, widget_id, customization_args, handlers, sticky=False):
self.widget_id = widget_id
# Customization args for the interactive widget view. Parts of these
# args may be Jinja templates that refer to state parameters.
# This is a dict: the keys are names of customization_args and the values
# are dicts with a single key, 'value', whose corresponding value is the
# value of the customization arg.
# This is a dict: the keys are names of customization_args and the
# values are dicts with a single key, 'value', whose corresponding
# value is the value of the customization arg.
self.customization_args = customization_args
# Answer handlers and rule specs.
self.handlers = [AnswerHandlerInstance(h.name, h.rule_specs)
Expand Down Expand Up @@ -511,7 +511,8 @@ def validate(self):

@classmethod
def create_default_widget(cls, default_dest_state_name):
default_obj_type = WidgetInstance._get_obj_type(feconf.DEFAULT_WIDGET_ID)
default_obj_type = WidgetInstance._get_obj_type(
feconf.DEFAULT_WIDGET_ID)
return cls(
feconf.DEFAULT_WIDGET_ID,
{},
Expand Down Expand Up @@ -666,7 +667,8 @@ def from_dict(cls, state_dict):
)

@classmethod
def create_default_state(cls, default_dest_state_name, is_initial_state=False):
def create_default_state(
cls, default_dest_state_name, is_initial_state=False):
text_str = (
feconf.DEFAULT_INIT_STATE_CONTENT_STR if is_initial_state else '')
return cls(
Expand Down Expand Up @@ -710,9 +712,10 @@ def __init__(self, exploration_id, title, category, objective,
self.last_updated = last_updated

def is_equal_to(self, other):
simple_props = ['id', 'title', 'category', 'objective', 'language_code',
'skill_tags', 'blurb', 'author_notes', 'default_skin',
'init_state_name', 'version']
simple_props = [
'id', 'title', 'category', 'objective', 'language_code',
'skill_tags', 'blurb', 'author_notes', 'default_skin',
'init_state_name', 'version']

for prop in simple_props:
if getattr(self, prop) != getattr(other, prop):
Expand All @@ -731,7 +734,8 @@ def is_equal_to(self, other):
return False

for i in xrange(len(self.param_changes)):
if self.param_changes[i].to_dict() != other.param_changes[i].to_dict():
if (self.param_changes[i].to_dict() !=
other.param_changes[i].to_dict()):
return False

return True
Expand All @@ -748,9 +752,9 @@ def create_default_exploration(
}

return cls(
exploration_id, title, category, objective, language_code, [], '', '',
'conversation_v1', feconf.DEFAULT_INIT_STATE_NAME, states_dict, {}, [],
0)
exploration_id, title, category, objective, language_code, [], '',
'', 'conversation_v1', feconf.DEFAULT_INIT_STATE_NAME, states_dict,
{}, [], 0)

@classmethod
def _require_valid_name(cls, name, name_type):
Expand Down
13 changes: 4 additions & 9 deletions core/domain/exp_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,11 @@

__author__ = 'Frederik Creemers'

import ast

from core import jobs
from core.domain import exp_domain
from core.platform import models
(base_models, exp_models,) = models.Registry.import_models([
models.NAMES.base_model, models.NAMES.exploration])
transaction_services = models.Registry.import_transaction_services()
import feconf
import utils

from google.appengine.ext import ndb


class ExpSummariesCreationOneOffJob(jobs.BaseMapReduceJobManager):
Expand Down Expand Up @@ -68,7 +61,9 @@ def entity_classes_to_map_over(cls):

@staticmethod
def map(item):
# We're inline importing here to break import loops like this: (-> means imports)
# exp_services -> event_services -> jobs_registry -> exp_jobs -> exp_services.
# We're inline importing here to break import loops like this: (->
# means imports):
# exp_services -> event_services -> jobs_registry ->
# exp_jobs -> exp_services.
from core.domain import exp_services
exp_services.index_explorations_given_ids([item.id])
2 changes: 1 addition & 1 deletion core/domain/exp_jobs_for_production_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Jobs operating on explorations that can be used for production tests.
"""Jobs operating on explorations that can be used for production tests.
To use these jobs, first need to register them in jobs_registry (at
the moment they are not displayed there to avoid accidental use)."""

Expand Down
33 changes: 14 additions & 19 deletions core/domain/exp_jobs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,15 @@

"""Tests for ExpSummary continuous computations."""

import collections
import datetime

from core import jobs
from core import jobs_registry
from core.domain import config_services
from core.domain import event_services
from core.domain import exp_domain
from core.domain import exp_jobs
from core.domain import exp_services
from core.domain import rights_manager
from core.platform import models
from core.tests import test_utils
import feconf
(job_models, exp_models,) = models.Registry.import_models([
models.NAMES.job, models.NAMES.exploration])
search_services = models.Registry.import_search_services()
import utils



class ExpSummariesCreationOneOffJobTest(test_utils.GenericTestBase):
Expand All @@ -47,7 +37,9 @@ class ExpSummariesCreationOneOffJobTest(test_utils.GenericTestBase):
ONE_OFF_JOB_MANAGERS_FOR_TESTS = [exp_jobs.ExpSummariesCreationOneOffJob]

def test_all_exps_publicized(self):
"""Test exploration summary batch job if all explorations are publicized."""
"""Test exploration summary batch job if all explorations are
publicized.
"""

# specify explorations that will be used in test
exp_specs = [
Expand Down Expand Up @@ -164,21 +156,22 @@ def _run_batch_job_once_and_verify_output(
# publish or publicize exploration
if spec['status'] == rights_manager.EXPLORATION_STATUS_PUBLIC:
rights_manager.publish_exploration(self.owner_id, exp_id)
elif spec['status'] == rights_manager.EXPLORATION_STATUS_PUBLICIZED:
elif (spec['status'] ==
rights_manager.EXPLORATION_STATUS_PUBLICIZED):
rights_manager.publish_exploration(self.owner_id, exp_id)
rights_manager.publicize_exploration(self.owner_id, exp_id)

# do not include user_id here, so all explorations are not
# editable for now (will be updated depending on user_id
# in galleries)
is_editable = False
exp_rights_model = exp_models.ExplorationRightsModel.get(exp_id)
exp_rights_model = exp_models.ExplorationRightsModel.get(
exp_id)

exploration = exp_services.get_exploration_by_id(exp_id)
exploration_model_last_updated = exploration.last_updated
exploration_model_created_on = exploration.created_on

# manually create the expectated summary specifying title,
# manually create the expectated summary specifying title,
# category, etc
expected_job_output[exp_id] = exp_domain.ExplorationSummary(
exp_id,
Expand Down Expand Up @@ -229,15 +222,16 @@ def _run_batch_job_once_and_verify_output(
self.assertEqual(actual_job_output.keys(),
expected_job_output.keys())
simple_props = ['id', 'title', 'category', 'objective',
'language_code','skill_tags', 'status',
'language_code', 'skill_tags', 'status',
'community_owned', 'owner_ids',
'editor_ids', 'viewer_ids', 'version',
'exploration_model_created_on',
'exploration_model_last_updated']
for exp_id in actual_job_output:
for prop in simple_props:
self.assertEqual(getattr(actual_job_output[exp_id], prop),
getattr(expected_job_output[exp_id], prop))
self.assertEqual(
getattr(actual_job_output[exp_id], prop),
getattr(expected_job_output[exp_id], prop))


class OneOffReindexExplorationsJobTest(test_utils.GenericTestBase):
Expand Down Expand Up @@ -271,7 +265,8 @@ def add_docs_mock(docs, index):
from core.domain import exp_services
self.assertEqual(index, exp_services.SEARCH_INDEX_EXPLORATIONS)

add_docs_swap = self.swap(search_services, 'add_documents_to_index', add_docs_mock)
add_docs_swap = self.swap(
search_services, 'add_documents_to_index', add_docs_mock)

with add_docs_swap:
self.process_and_flush_pending_tasks()
Expand Down
Loading

0 comments on commit 717b735

Please sign in to comment.