def test_create_enum_method(self): """Test create_enum method.""" enum = utils.create_enum('first', 'second', 'third') self.assertEqual(enum.first, 'first') self.assertEqual(enum.second, 'second') self.assertEqual(enum.third, 'third') with self.assertRaises(AttributeError): enum.fourth # pylint: disable=pointless-statement
def test_create_enum_method(self): """Test create_enum method.""" o = utils.create_enum('first', 'second', 'third') self.assertEqual(o.first, 'first') self.assertEqual(o.second, 'second') self.assertEqual(o.third, 'third') with self.assertRaises(AttributeError): o.fourth
def test_create_enum_method(self): """Test create_enum method.""" enum = utils.create_enum('first', 'second', 'third') self.assertEqual(enum.first, 'first') self.assertEqual(enum.second, 'second') self.assertEqual(enum.third, 'third') with self.assertRaisesRegexp( AttributeError, 'type object \'Enum\' has no attribute \'fourth\''): enum.fourth # pylint: disable=pointless-statement
"""Interface for storage model switching.""" from __future__ import absolute_import # pylint: disable=import-only-modules from __future__ import unicode_literals # pylint: disable=import-only-modules import inspect import feconf import python_utils import utils # Valid model names. NAMES = utils.create_enum( 'activity', 'audit', 'base_model', 'classifier', 'collection', 'config', 'email', 'exploration', 'feedback', 'job', 'opportunity', 'question', 'recommendations', 'skill', 'statistics', 'story', 'suggestion', 'topic', 'user') GAE_PLATFORM = 'gae' class Platform(python_utils.OBJECT): """A base class for platform-specific imports related to GAE.""" @classmethod def import_models(cls): """An abstract method that should be implemented on inherited classes. Raises:
from google.appengine.datastore import datastore_query from google.appengine.ext import ndb transaction_services = models.Registry.import_transaction_services() # The delimiter used to separate the version number from the model instance # id. To get the instance id from a snapshot id, use Python's rfind() # method to find the location of this delimiter. _VERSION_DELIMITER = '-' # Types of deletion policies. The pragma comment is needed because Enums are # evaluated as classes in Python and they should use PascalCase, but using # UPPER_CASE seems more appropriate here. DELETION_POLICY = utils.create_enum( # pylint: disable=invalid-name 'KEEP', 'DELETE', 'ANONYMIZE', 'LOCALLY_PSEUDONYMIZE', 'KEEP_IF_PUBLIC', 'NOT_APPLICABLE') # Constant used when retrieving big number of models. FETCH_BATCH_SIZE = 1000 # Constants used for generating ids. MAX_RETRIES = 10 RAND_RANGE = (1 << 30) - 1 ID_LENGTH = 12 class BaseModel(ndb.Model): """Base model for all persistent object storage classes.""" # When this entity was first created. This can be overwritten and
"""Interface for storage model switching.""" from __future__ import absolute_import # pylint: disable=import-only-modules from __future__ import unicode_literals # pylint: disable=import-only-modules import inspect from constants import constants import feconf import python_utils import utils # Valid model names. NAMES = utils.create_enum('activity', 'audit', 'auth', 'base_model', 'classifier', 'collection', 'config', 'email', 'exploration', 'feedback', 'improvements', 'job', 'opportunity', 'question', 'recommendations', 'skill', 'statistics', 'story', 'subtopic', 'suggestion', 'topic', 'user') # Types of deletion policies. The pragma comment is needed because Enums are # evaluated as classes in Python and they should use PascalCase, but using # UPPER_CASE seems more appropriate here. MODULES_WITH_PSEUDONYMIZABLE_CLASSES = utils.create_enum( # pylint: disable=invalid-name NAMES.collection, NAMES.config, NAMES.exploration, NAMES.feedback, NAMES.question, NAMES.skill, NAMES.story, NAMES.subtopic, NAMES.suggestion, NAMES.topic) GAE_PLATFORM = 'gae' class Platform(python_utils.OBJECT):
"""Domain objects for platform parameters.""" from __future__ import absolute_import # pylint: disable=import-only-modules from __future__ import unicode_literals # pylint: disable=import-only-modules import json import re from constants import constants from core.domain import change_domain import feconf import python_utils import utils SERVER_MODES = utils.create_enum('dev', 'test', 'prod') # pylint: disable=invalid-name FEATURE_STAGES = SERVER_MODES # pylint: disable=invalid-name DATA_TYPES = utils.create_enum('bool', 'string', 'number') # pylint: disable=invalid-name ALLOWED_USER_LOCALES = [ lang_dict['id'] for lang_dict in constants.SUPPORTED_SITE_LANGUAGES] ALLOWED_SERVER_MODES = [ SERVER_MODES.dev, SERVER_MODES.test, SERVER_MODES.prod] ALLOWED_FEATURE_STAGES = [ FEATURE_STAGES.dev, FEATURE_STAGES.test, FEATURE_STAGES.prod] ALLOWED_CLIENT_TYPES = ['Web', 'Android'] ALLOWED_BROWSER_TYPES = ['Chrome', 'Edge', 'Safari', 'Firefox', 'Unknown'] # The ordering of elements in ALLOWED_APP_VERSION_FLAVOR implies the ordering # of corresponding flavors, which is used in app_version_flavor filter for order # comparison, with following ordering: 'test' < 'alpha' < 'beta' < 'release'.
from core.platform import models import feconf from jobs import job_utils from jobs.decorators import audit_decorators from jobs.types import audit_errors import utils import apache_beam as beam (base_models, ) = models.Registry.import_models([models.NAMES.base_model]) BASE_MODEL_ID_PATTERN = r'^[A-Za-z0-9-_]{1,%s}$' % base_models.ID_LENGTH MAX_CLOCK_SKEW_SECS = datetime.timedelta(seconds=1) VALIDATION_MODES = utils.create_enum('neutral', 'strict', 'non_strict') # pylint: disable=invalid-name class ValidateDeletedModel(beam.DoFn): """DoFn to check whether models marked for deletion are stale. Doesn't use the AuditsExisting decorator because it audits deleted models, not existing ones. """ def process(self, input_model): """Yields audit errors that are discovered in the input model. Args: input_model: datastore_services.Model. Entity to validate. Yields:
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS-IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Interface for storage model switching.""" import feconf import utils # Valid model names. NAMES = utils.create_enum('activity', 'base_model', 'classifier', 'collection', 'config', 'email', 'exploration', 'feedback', 'file', 'job', 'recommendations', 'statistics', 'user') class _Platform(object): @classmethod def import_models(cls): raise NotImplementedError class _Gae(_Platform): @classmethod def import_models(cls, model_names): returned_models = [] for name in model_names:
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Definition of platform parameters.""" from __future__ import absolute_import # pylint: disable=import-only-modules from __future__ import unicode_literals # pylint: disable=import-only-modules from core.domain import platform_parameter_domain from core.domain import platform_parameter_registry as registry import utils Registry = registry.Registry FEATURE_STAGES = platform_parameter_domain.FEATURE_STAGES # pylint: disable=invalid-name DATA_TYPES = platform_parameter_domain.DATA_TYPES # pylint: disable=invalid-name PARAM_NAMES = utils.create_enum( # pylint: disable=invalid-name 'dummy_feature', 'dummy_parameter') # Platform parameters should all be defined below. Registry.create_feature_flag( PARAM_NAMES.dummy_feature, 'This is a dummy feature flag.', FEATURE_STAGES.dev, ) Registry.create_platform_parameter(PARAM_NAMES.dummy_parameter, 'This is a dummy platform parameter.', DATA_TYPES.string)
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS-IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Interface for storage model switching.""" __author__ = 'Sean Lip' import feconf import utils # Valid model names. NAMES = utils.create_enum( 'base_model', 'config', 'exploration', 'file', 'job', 'statistics', 'user', 'feedback') class _Platform(object): @classmethod def import_models(cls): raise NotImplementedError class _Gae(_Platform): @classmethod def import_models(cls, model_names): returned_models = [] for name in model_names:
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS-IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Interface for storage model switching.""" __author__ = 'Sean Lip' import feconf import utils # Valid model names. NAMES = utils.create_enum('base_model', 'config', 'exploration', 'file', 'job', 'statistics', 'user', 'feedback') class _Platform(object): @classmethod def import_models(cls): raise NotImplementedError class _Gae(_Platform): @classmethod def import_models(cls, model_names): returned_models = [] for name in model_names: if name == NAMES.base_model:
from google.appengine.datastore import datastore_query from google.appengine.ext import ndb transaction_services = models.Registry.import_transaction_services() # The delimiter used to separate the version number from the model instance # id. To get the instance id from a snapshot id, use Python's rfind() # method to find the location of this delimiter. _VERSION_DELIMITER = '-' # Types of deletion policies. The pragma comment is needed because Enums are # evaluated as classes in Python and they should use PascalCase, but using # UPPER_CASE seems more appropriate here. DELETION_POLICY = utils.create_enum( # pylint: disable=invalid-name 'KEEP', 'DELETE', 'ANONYMIZE', 'LOCALLY_PSEUDONYMIZE', 'KEEP_IF_PUBLIC', 'NOT_APPLICABLE') EXPORT_POLICY = utils.create_enum( # pylint: disable=invalid-name 'CONTAINS_USER_DATA', 'NOT_APPLICABLE', ) # Types of user id migration policies. The pragma comment is needed because # Enums are evaluated as classes in Python and they should use PascalCase, # but using UPPER_CASE seems more appropriate here. # COPY - User ID is used as model ID thus the model needs to be recreated. # COPY_AND_UPDATE_ONE_FIELD - User ID is used as some part of the model ID and # also in user_id field thus the model needs to be # recreated and the field changed. # ONE_FIELD - One field in the model contains user ID thus the value in that
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS-IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Interface for storage model switching.""" import feconf import utils # Valid model names. NAMES = utils.create_enum( 'activity', 'base_model', 'collection', 'config', 'email', 'exploration', 'feedback', 'file', 'job', 'recommendations', 'statistics', 'user') class _Platform(object): @classmethod def import_models(cls): raise NotImplementedError class _Gae(_Platform): @classmethod def import_models(cls, model_names): returned_models = [] for name in model_names:
__author__ = 'Sean Lip' import collections import utils from apps.base_model.models import BaseModel from apps.exploration.models import Exploration from google.appengine.ext import ndb IMPROVE_TYPE_DEFAULT = 'default' IMPROVE_TYPE_INCOMPLETE = 'incomplete' STATS_ENUMS = utils.create_enum( 'exploration_visited', 'rule_hit', 'exploration_completed', 'feedback_submitted', 'state_hit') def create_rule_name(rule): name = rule.name for key in rule.inputs.keys(): left_paren = name.index('(') name = name[0:left_paren] + name[left_paren:].replace( key, str(rule.inputs[key])) return name def get_event_key(event_name, key): if event_name == STATS_ENUMS.exploration_visited: return 'e.%s' % key
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS-IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Interface for storage model switching.""" __author__ = 'Sean Lip' import feconf import utils # Valid model names. NAMES = utils.create_enum( 'base_model', 'config', 'exploration', 'image', 'statistics') class _Platform(object): @classmethod def import_models(cls): raise NotImplementedError class _Django(_Platform): @classmethod def import_models(cls, model_names): returned_models = [] for name in model_names: