Python google.appengine.ext.ndb.BooleanProperty() Examples
The following are 19
code examples of google.appengine.ext.ndb.BooleanProperty().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
google.appengine.ext.ndb
, or try the search function
.
Example #1
Source File: task_result_test.py From luci-py with Apache License 2.0 | 6 votes |
def test_state_to_string(self): # Same code as State.to_string() except that it works for # TaskResultSummary too. class Foo(ndb.Model): deduped_from = None state = task_result.StateProperty() failure = ndb.BooleanProperty(default=False) internal_failure = ndb.BooleanProperty(default=False) for i in task_result.State.STATES: self.assertTrue(task_result.State.to_string(i)) for i in task_result.State.STATES: self.assertTrue(task_result.state_to_string(Foo(state=i))) f = Foo(state=task_result.State.COMPLETED) f.deduped_from = '123' self.assertEqual('Deduped', task_result.state_to_string(f))
Example #2
Source File: ndb.py From jbox with MIT License | 5 votes |
def convert_BooleanProperty(self, model, prop, kwargs): """Returns a form field for a ``ndb.BooleanProperty``.""" return f.BooleanField(**kwargs)
Example #3
Source File: handler_utils.py From upvote with Apache License 2.0 | 5 votes |
def _CoerceQueryParam(field, query_param): """Attempts to coerce `query_param` to match the ndb type of `field`. Args: field: The ndb field being queried. query_param: The query term to be coerced. Returns: The query param coerced if a coercion was possible. Raises: QueryTypeError: If there is an error with the type conversion. """ if isinstance(field, ndb.IntegerProperty): try: return int(query_param) except ValueError: raise QueryTypeError( 'Query param "%s" could not be converted to integer' % query_param) elif isinstance(field, ndb.BooleanProperty): if query_param.lower() == 'true': return True elif query_param.lower() == 'false': return False else: raise QueryTypeError( 'Query param "%s" could not be converted to boolean' % query_param) elif isinstance(field, ndb.KeyProperty): key = datastore_utils.GetKeyFromUrlsafe(query_param) if not key: raise QueryTypeError( 'Query param "%s" could not be converted to ndb.Key' % query_param) return key else: return query_param
Example #4
Source File: manager.py From tekton with MIT License | 5 votes |
def _to_default_reques_value(descriptor, name, index): if isinstance(descriptor, (StringProperty, TextProperty)): return "'%s_string'" % name if isinstance(descriptor, DateProperty): return "'1/%s/2014'" % (index + 1) if isinstance(descriptor, DateTimeProperty): return "'1/1/2014 01:%s:0'" % (index + 1) if isinstance(descriptor, (SimpleCurrency, SimpleDecimal)): return "'1.%s'" % (index + 1 if index >= 9 else '0%s' % (index + 1)) if isinstance(descriptor, IntegerProperty): return "'%s'" % (index + 1) if isinstance(descriptor, FloatProperty): return "'1.%s'" % (index + 1) if isinstance(descriptor, BooleanProperty): return "'True'"
Example #5
Source File: manager.py From tekton with MIT License | 5 votes |
def _to_default_model_value(descriptor, name, index): if isinstance(descriptor, (StringProperty, TextProperty)): return "'%s_string'" % name if isinstance(descriptor, DateProperty): return "date(2014, 1, %s)" % (index + 1) if isinstance(descriptor, DateTimeProperty): return "datetime(2014, 1, 1, 1, %s, 0)" % (index + 1) if isinstance(descriptor, (SimpleCurrency, SimpleDecimal)): return "Decimal('1.%s')" % (index + 1 if index >= 9 else '0%s' % (index + 1)) if isinstance(descriptor, IntegerProperty): return "%s" % (index + 1) if isinstance(descriptor, FloatProperty): return "1.%s" % (index + 1) if isinstance(descriptor, BooleanProperty): return "True"
Example #6
Source File: manager.py From tekton with MIT License | 5 votes |
def parse_property(p): name, type_alias = p.split(':') types = {'string': 'ndb.StringProperty(required=True)', 'date': 'ndb.DateProperty(required=True)', 'datetime': 'ndb.DateTimeProperty(required=True)', 'int': 'ndb.IntegerProperty(required=True)', 'float': 'ndb.FloatProperty(required=True)', 'decimal': 'property.SimpleDecimal(required=True)', 'currency': 'property.SimpleCurrency(required=True)', 'bool': 'ndb.BooleanProperty(required=True)'} return ' %s = %s' % (name, types[type_alias])
Example #7
Source File: ndb.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
def convert_BooleanProperty(self, model, prop, kwargs): """Returns a form field for a ``ndb.BooleanProperty``.""" return f.BooleanField(**kwargs)
Example #8
Source File: test_converter.py From graphene-gae with BSD 3-Clause "New" or "Revised" License | 5 votes |
def testBoolProperty_shouldConvertToString(self): self.__assert_conversion(ndb.BooleanProperty, graphene.Boolean)
Example #9
Source File: ndb.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def convert_BooleanProperty(self, model, prop, kwargs): """Returns a form field for a ``ndb.BooleanProperty``.""" return f.BooleanField(**kwargs)
Example #10
Source File: bigquery_test.py From loaner with Apache License 2.0 | 5 votes |
def test_generate_entity_schema(self): class NestedTestModel(ndb.Model): nested_string_attribute = ndb.StringProperty() class TestModel(ndb.Model): string_attribute = ndb.StringProperty() integer_attribute = ndb.IntegerProperty() boolean_attribute = ndb.BooleanProperty() nested_attribute = ndb.StructuredProperty(NestedTestModel) schema = bigquery._generate_entity_schema(TestModel()) expected_schema_names = _populate_schema_names(self.entity_schema) schema_names = _populate_schema_names(schema) self.assertCountEqual(expected_schema_names, schema_names)
Example #11
Source File: model.py From luci-py with Apache License 2.0 | 4 votes |
def get_historical_copy_class(cls): """Returns entity class for historical copies of original entity. Has all the same properties, but unindexed (not needed), unvalidated (original entity is already validated) and not cached. The name of the new entity class is "<original name>History" (to make sure it doesn't show up in indexes for original entity class). """ existing = getattr(cls, '_auth_db_historical_copy_cls', None) if existing: return existing props = {} for name, prop in cls._properties.items(): # Whitelist supported property classes. Better to fail loudly when # encountering something new, rather than silently produce (possibly) # incorrect result. Note that all AuthDB classes are instantiated in # unit tests, so there should be no unexpected asserts in production. assert prop.__class__ in ( datastore_utils.ProtobufProperty, IdentityGlobProperty, IdentityProperty, ndb.BlobProperty, ndb.BooleanProperty, ndb.DateTimeProperty, ndb.IntegerProperty, ndb.LocalStructuredProperty, ndb.StringProperty, ndb.TextProperty, ), prop.__class__ kwargs = { 'name': prop._name, 'indexed': False, 'required': False, 'repeated': prop._repeated, } if prop.__class__ == datastore_utils.ProtobufProperty: kwargs.update({ 'message_class': prop._message_class, 'compressed': prop._compressed, }) elif prop.__class__ == ndb.LocalStructuredProperty: kwargs['modelclass'] = prop._modelclass props[name] = prop.__class__(**kwargs) new_cls = type( '%sHistory' % cls.__name__, (_AuthDBHistoricalEntity,), props) cls._auth_db_historical_copy_cls = new_cls return new_cls
Example #12
Source File: serializable_test.py From luci-py with Apache License 2.0 | 4 votes |
def test_simple_properties(self): """Simple properties are unmodified in to_serializable_dict().""" class Entity(ndb.Model, serializable.SerializableModelMixin): blob_prop = ndb.BlobProperty() bool_prop = ndb.BooleanProperty() float_prop = ndb.FloatProperty() int_prop = ndb.IntegerProperty() json_prop = ndb.JsonProperty() pickle_prop = ndb.PickleProperty() str_prop = ndb.StringProperty() text_prop = ndb.TextProperty() # Test data in simple dict form. as_serializable_dict = { 'blob_prop': 'blob', 'bool_prop': True, 'float_prop': 3.14, 'int_prop': 42, 'json_prop': ['a list', 'why', 'not?'], 'pickle_prop': {'some': 'dict'}, 'str_prop': 'blah-blah', 'text_prop': 'longer blah-blah', } # Same data but in entity form. Constructing entity directly from # |as_serializable_dict| works only if it contains only simple properties # (that look the same in serializable dict and entity form). as_entity = Entity(**as_serializable_dict) # Ensure all simple properties (from _SIMPLE_PROPERTIES) are covered. self.assertEqual( set(serializable._SIMPLE_PROPERTIES), set(prop.__class__ for prop in Entity._properties.values())) # Check entity -> serializable dict conversion. self.assertEqual( as_serializable_dict, as_entity.to_serializable_dict()) # Check serializable dict -> Entity conversion. self.assertEqual( as_entity, Entity.from_serializable_dict(as_serializable_dict))
Example #13
Source File: serializable_test.py From luci-py with Apache License 2.0 | 4 votes |
def test_simple_properties(self): """Simple properties are unmodified in to_serializable_dict().""" class Entity(ndb.Model, serializable.SerializableModelMixin): blob_prop = ndb.BlobProperty() bool_prop = ndb.BooleanProperty() float_prop = ndb.FloatProperty() int_prop = ndb.IntegerProperty() json_prop = ndb.JsonProperty() pickle_prop = ndb.PickleProperty() str_prop = ndb.StringProperty() text_prop = ndb.TextProperty() # Test data in simple dict form. as_serializable_dict = { 'blob_prop': 'blob', 'bool_prop': True, 'float_prop': 3.14, 'int_prop': 42, 'json_prop': ['a list', 'why', 'not?'], 'pickle_prop': {'some': 'dict'}, 'str_prop': 'blah-blah', 'text_prop': 'longer blah-blah', } # Same data but in entity form. Constructing entity directly from # |as_serializable_dict| works only if it contains only simple properties # (that look the same in serializable dict and entity form). as_entity = Entity(**as_serializable_dict) # Ensure all simple properties (from _SIMPLE_PROPERTIES) are covered. self.assertEqual( set(serializable._SIMPLE_PROPERTIES), set(prop.__class__ for prop in Entity._properties.values())) # Check entity -> serializable dict conversion. self.assertEqual( as_serializable_dict, as_entity.to_serializable_dict()) # Check serializable dict -> Entity conversion. self.assertEqual( as_entity, Entity.from_serializable_dict(as_serializable_dict))
Example #14
Source File: model.py From luci-py with Apache License 2.0 | 4 votes |
def get_historical_copy_class(cls): """Returns entity class for historical copies of original entity. Has all the same properties, but unindexed (not needed), unvalidated (original entity is already validated) and not cached. The name of the new entity class is "<original name>History" (to make sure it doesn't show up in indexes for original entity class). """ existing = getattr(cls, '_auth_db_historical_copy_cls', None) if existing: return existing props = {} for name, prop in cls._properties.items(): # Whitelist supported property classes. Better to fail loudly when # encountering something new, rather than silently produce (possibly) # incorrect result. Note that all AuthDB classes are instantiated in # unit tests, so there should be no unexpected asserts in production. assert prop.__class__ in ( datastore_utils.ProtobufProperty, IdentityGlobProperty, IdentityProperty, ndb.BlobProperty, ndb.BooleanProperty, ndb.DateTimeProperty, ndb.IntegerProperty, ndb.LocalStructuredProperty, ndb.StringProperty, ndb.TextProperty, ), prop.__class__ kwargs = { 'name': prop._name, 'indexed': False, 'required': False, 'repeated': prop._repeated, } if prop.__class__ == datastore_utils.ProtobufProperty: kwargs.update({ 'message_class': prop._message_class, 'compressed': prop._compressed, }) elif prop.__class__ == ndb.LocalStructuredProperty: kwargs['modelclass'] = prop._modelclass props[name] = prop.__class__(**kwargs) new_cls = type( '%sHistory' % cls.__name__, (_AuthDBHistoricalEntity,), props) cls._auth_db_historical_copy_cls = new_cls return new_cls
Example #15
Source File: model.py From luci-py with Apache License 2.0 | 4 votes |
def get_historical_copy_class(cls): """Returns entity class for historical copies of original entity. Has all the same properties, but unindexed (not needed), unvalidated (original entity is already validated) and not cached. The name of the new entity class is "<original name>History" (to make sure it doesn't show up in indexes for original entity class). """ existing = getattr(cls, '_auth_db_historical_copy_cls', None) if existing: return existing props = {} for name, prop in cls._properties.items(): # Whitelist supported property classes. Better to fail loudly when # encountering something new, rather than silently produce (possibly) # incorrect result. Note that all AuthDB classes are instantiated in # unit tests, so there should be no unexpected asserts in production. assert prop.__class__ in ( datastore_utils.ProtobufProperty, IdentityGlobProperty, IdentityProperty, ndb.BlobProperty, ndb.BooleanProperty, ndb.DateTimeProperty, ndb.IntegerProperty, ndb.LocalStructuredProperty, ndb.StringProperty, ndb.TextProperty, ), prop.__class__ kwargs = { 'name': prop._name, 'indexed': False, 'required': False, 'repeated': prop._repeated, } if prop.__class__ == datastore_utils.ProtobufProperty: kwargs.update({ 'message_class': prop._message_class, 'compressed': prop._compressed, }) elif prop.__class__ == ndb.LocalStructuredProperty: kwargs['modelclass'] = prop._modelclass props[name] = prop.__class__(**kwargs) new_cls = type( '%sHistory' % cls.__name__, (_AuthDBHistoricalEntity,), props) cls._auth_db_historical_copy_cls = new_cls return new_cls
Example #16
Source File: serializable_test.py From luci-py with Apache License 2.0 | 4 votes |
def test_simple_properties(self): """Simple properties are unmodified in to_serializable_dict().""" class Entity(ndb.Model, serializable.SerializableModelMixin): blob_prop = ndb.BlobProperty() bool_prop = ndb.BooleanProperty() float_prop = ndb.FloatProperty() int_prop = ndb.IntegerProperty() json_prop = ndb.JsonProperty() pickle_prop = ndb.PickleProperty() str_prop = ndb.StringProperty() text_prop = ndb.TextProperty() # Test data in simple dict form. as_serializable_dict = { 'blob_prop': 'blob', 'bool_prop': True, 'float_prop': 3.14, 'int_prop': 42, 'json_prop': ['a list', 'why', 'not?'], 'pickle_prop': {'some': 'dict'}, 'str_prop': 'blah-blah', 'text_prop': 'longer blah-blah', } # Same data but in entity form. Constructing entity directly from # |as_serializable_dict| works only if it contains only simple properties # (that look the same in serializable dict and entity form). as_entity = Entity(**as_serializable_dict) # Ensure all simple properties (from _SIMPLE_PROPERTIES) are covered. self.assertEqual( set(serializable._SIMPLE_PROPERTIES), set(prop.__class__ for prop in Entity._properties.values())) # Check entity -> serializable dict conversion. self.assertEqual( as_serializable_dict, as_entity.to_serializable_dict()) # Check serializable dict -> Entity conversion. self.assertEqual( as_entity, Entity.from_serializable_dict(as_serializable_dict))
Example #17
Source File: model.py From luci-py with Apache License 2.0 | 4 votes |
def get_historical_copy_class(cls): """Returns entity class for historical copies of original entity. Has all the same properties, but unindexed (not needed), unvalidated (original entity is already validated) and not cached. The name of the new entity class is "<original name>History" (to make sure it doesn't show up in indexes for original entity class). """ existing = getattr(cls, '_auth_db_historical_copy_cls', None) if existing: return existing props = {} for name, prop in cls._properties.items(): # Whitelist supported property classes. Better to fail loudly when # encountering something new, rather than silently produce (possibly) # incorrect result. Note that all AuthDB classes are instantiated in # unit tests, so there should be no unexpected asserts in production. assert prop.__class__ in ( datastore_utils.ProtobufProperty, IdentityGlobProperty, IdentityProperty, ndb.BlobProperty, ndb.BooleanProperty, ndb.DateTimeProperty, ndb.IntegerProperty, ndb.LocalStructuredProperty, ndb.StringProperty, ndb.TextProperty, ), prop.__class__ kwargs = { 'name': prop._name, 'indexed': False, 'required': False, 'repeated': prop._repeated, } if prop.__class__ == datastore_utils.ProtobufProperty: kwargs.update({ 'message_class': prop._message_class, 'compressed': prop._compressed, }) elif prop.__class__ == ndb.LocalStructuredProperty: kwargs['modelclass'] = prop._modelclass props[name] = prop.__class__(**kwargs) new_cls = type( '%sHistory' % cls.__name__, (_AuthDBHistoricalEntity,), props) cls._auth_db_historical_copy_cls = new_cls return new_cls
Example #18
Source File: serializable_test.py From luci-py with Apache License 2.0 | 4 votes |
def test_simple_properties(self): """Simple properties are unmodified in to_serializable_dict().""" class Entity(ndb.Model, serializable.SerializableModelMixin): blob_prop = ndb.BlobProperty() bool_prop = ndb.BooleanProperty() float_prop = ndb.FloatProperty() int_prop = ndb.IntegerProperty() json_prop = ndb.JsonProperty() pickle_prop = ndb.PickleProperty() str_prop = ndb.StringProperty() text_prop = ndb.TextProperty() # Test data in simple dict form. as_serializable_dict = { 'blob_prop': 'blob', 'bool_prop': True, 'float_prop': 3.14, 'int_prop': 42, 'json_prop': ['a list', 'why', 'not?'], 'pickle_prop': {'some': 'dict'}, 'str_prop': 'blah-blah', 'text_prop': 'longer blah-blah', } # Same data but in entity form. Constructing entity directly from # |as_serializable_dict| works only if it contains only simple properties # (that look the same in serializable dict and entity form). as_entity = Entity(**as_serializable_dict) # Ensure all simple properties (from _SIMPLE_PROPERTIES) are covered. self.assertEqual( set(serializable._SIMPLE_PROPERTIES), set(prop.__class__ for prop in Entity._properties.values())) # Check entity -> serializable dict conversion. self.assertEqual( as_serializable_dict, as_entity.to_serializable_dict()) # Check serializable dict -> Entity conversion. self.assertEqual( as_entity, Entity.from_serializable_dict(as_serializable_dict))
Example #19
Source File: model.py From luci-py with Apache License 2.0 | 4 votes |
def get_historical_copy_class(cls): """Returns entity class for historical copies of original entity. Has all the same properties, but unindexed (not needed), unvalidated (original entity is already validated) and not cached. The name of the new entity class is "<original name>History" (to make sure it doesn't show up in indexes for original entity class). """ existing = getattr(cls, '_auth_db_historical_copy_cls', None) if existing: return existing props = {} for name, prop in cls._properties.items(): # Whitelist supported property classes. Better to fail loudly when # encountering something new, rather than silently produce (possibly) # incorrect result. Note that all AuthDB classes are instantiated in # unit tests, so there should be no unexpected asserts in production. assert prop.__class__ in ( datastore_utils.ProtobufProperty, IdentityGlobProperty, IdentityProperty, ndb.BlobProperty, ndb.BooleanProperty, ndb.DateTimeProperty, ndb.IntegerProperty, ndb.LocalStructuredProperty, ndb.StringProperty, ndb.TextProperty, ), prop.__class__ kwargs = { 'name': prop._name, 'indexed': False, 'required': False, 'repeated': prop._repeated, } if prop.__class__ == datastore_utils.ProtobufProperty: kwargs.update({ 'message_class': prop._message_class, 'compressed': prop._compressed, }) elif prop.__class__ == ndb.LocalStructuredProperty: kwargs['modelclass'] = prop._modelclass props[name] = prop.__class__(**kwargs) new_cls = type( '%sHistory' % cls.__name__, (_AuthDBHistoricalEntity,), props) cls._auth_db_historical_copy_cls = new_cls return new_cls