本文整理匯總了Python中google.appengine.api.datastore_errors.BadValueError方法的典型用法代碼示例。如果您正苦於以下問題:Python datastore_errors.BadValueError方法的具體用法?Python datastore_errors.BadValueError怎麽用?Python datastore_errors.BadValueError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.appengine.api.datastore_errors
的用法示例。
在下文中一共展示了datastore_errors.BadValueError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def create(self, request):
"""Creates a new tag and inserts the instance into datastore."""
self.check_xsrf_token(self.request_state)
try:
tag_model.Tag.create(
user_email=user.get_user_email(),
name=request.tag.name,
hidden=request.tag.hidden,
color=request.tag.color,
protect=request.tag.protect,
description=request.tag.description)
except datastore_errors.BadValueError as err:
raise endpoints.BadRequestException(
'Tag creation failed due to: %s' % err)
return message_types.VoidMessage()
示例2: update
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def update(self, request):
"""Updates an existing tag."""
self.check_xsrf_token(self.request_state)
key = api_utils.get_ndb_key(urlsafe_key=request.tag.urlsafe_key)
tag = key.get()
if tag.protect:
raise endpoints.BadRequestException(
'Cannot update tag %s because it is protected.' % tag.name)
try:
tag.update(
user_email=user.get_user_email(),
name=request.tag.name,
hidden=request.tag.hidden,
protect=request.tag.protect,
color=request.tag.color,
description=request.tag.description)
except datastore_errors.BadValueError as err:
raise endpoints.BadRequestException(
'Tag update failed due to: %s' % str(err))
return message_types.VoidMessage()
示例3: enroll
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def enroll(self, request):
"""Enrolls a shelf in the program."""
user_email = user.get_user_email()
self.check_xsrf_token(self.request_state)
try:
shelf_model.Shelf.enroll(
user_email=user_email,
friendly_name=request.friendly_name,
location=request.location,
latitude=request.latitude,
longitude=request.longitude,
altitude=request.altitude,
capacity=request.capacity,
audit_notification_enabled=request.audit_notification_enabled,
responsible_for_audit=request.responsible_for_audit,
audit_interval_override=request.audit_interval_override,
)
except (shelf_model.EnrollmentError, datastore_errors.BadValueError) as err:
raise endpoints.BadRequestException(str(err))
return message_types.VoidMessage()
示例4: create
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def create(cls, name, title=None, body=None):
"""Creates a model and entity."""
if not name:
raise datastore_errors.BadValueError(
'The Template name must not be empty.')
entity = cls(title=title,
body=body)
template = cls.get_by_id(name)
if template is not None:
raise datastore_errors.BadValueError(
'Create template: A Template entity with name %r already exists.' %
name)
entity.key = ndb.Key(cls, name)
entity.put()
logging.info('Creating a new template with name %r.', name)
cls.cached_templates = []
return entity
示例5: update
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def update(self, user_email, **kwargs):
"""Updates an existing tag.
Args:
user_email: str, email of the user creating the tag.
**kwargs: kwargs for the update API.
Raises:
datastore_errors.BadValueError: If the tag name is an empty string.
"""
if not kwargs['name']:
raise datastore_errors.BadValueError('The tag name must not be empty.')
if kwargs['name'] != self.name:
logging.info(
'Renaming the tag with name %r to %r.', self.name, kwargs['name'])
self.populate(**kwargs)
self.put()
logging.info(
'Updating a tag with urlsafe key %r and name %r.',
self.key.urlsafe(), self.name)
self.stream_to_bq(
user_email, 'Updated a tag with name %r.' % self.name)
示例6: get_datastore_cursor
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def get_datastore_cursor(urlsafe_cursor):
"""Builds a datastore.Cursor from a urlsafe cursor.
Args:
urlsafe_cursor: str, The urlsafe representation of a datastore.Cursor.
Returns:
datastore.Cursor instance.
Raises:
endpoints.BadRequestException: if the creation of the datastore.Cursor
fails.
"""
try:
return datastore_query.Cursor(urlsafe=urlsafe_cursor)
except datastore_errors.BadValueError:
raise endpoints.BadRequestException(_MALFORMED_PAGE_TOKEN_MSG)
示例7: validate
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def validate(self, value):
"""Validate value.
Args:
value: model value.
Returns:
Whether the specified value is valid data type value.
Raises:
BadValueError: when value is not of self.data_type type.
"""
if value is not None and not isinstance(value, self.data_type):
raise datastore_errors.BadValueError(
"Property %s must be convertible to a %s instance (%s)" %
(self.name, self.data_type, value))
return super(JsonProperty, self).validate(value)
示例8: validate
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def validate(self, value):
"""Validate value.
Args:
value: model value.
Returns:
Whether the specified value is valid data type value.
Raises:
BadValueError: when value is not of self.data_type type.
"""
if value is not None and not isinstance(value, self.data_type):
raise datastore_errors.BadValueError(
"Property %s must be convertible to a %s instance (%s)" %
(self.name, self.data_type, value))
return super(JsonProperty, self).validate(value)
示例9: _pre_put_hook
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def _pre_put_hook(self):
super(BqState, self)._pre_put_hook()
if bool(self.recent) != bool(self.oldest):
raise datastore_errors.BadValueError(
'Internal error; recent and oldest must both be set')
if self.oldest:
if self.oldest >= self.recent:
raise datastore_errors.BadValueError('Internal error; oldest >= recent')
if self.oldest.second or self.oldest.microsecond:
raise datastore_errors.BadValueError(
'Internal error; oldest has seconds')
if self.recent.second or self.recent.microsecond:
raise datastore_errors.BadValueError(
'Internal error; recent has seconds')
### Private APIs.
示例10: test_BqState
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def test_BqState(self):
now = datetime.datetime(2020, 1, 2, 3, 4)
bq_state.BqState(id='foo').put()
bq_state.BqState(
id='foo', recent=now,
oldest=now - datetime.timedelta(seconds=60)).put()
with self.assertRaises(datastore_errors.BadValueError):
bq_state.BqState(id='foo', oldest=now).put()
with self.assertRaises(datastore_errors.BadValueError):
bq_state.BqState(id='foo', recent=now).put()
with self.assertRaises(datastore_errors.BadValueError):
bq_state.BqState(id='foo', recent=now, oldest=now).put()
with self.assertRaises(datastore_errors.BadValueError):
bq_state.BqState(id='foo', recent=now, oldest=now).put()
with self.assertRaises(datastore_errors.BadValueError):
bq_state.BqState(
id='foo',
recent=now - datetime.timedelta(seconds=60.1),
oldest=now - datetime.timedelta(seconds=60)).put()
示例11: test_new_run_result_duration_no_exit_code
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def test_new_run_result_duration_no_exit_code(self):
request = _gen_request()
to_run = task_to_run.new_task_to_run(request, 0)
actual = task_result.new_run_result(request, to_run, u'localhost', u'abc', {
u'id': [u'localhost'],
u'foo': [u'bar', u'biz']
})
actual.completed_ts = self.now
actual.modified_ts = self.now
actual.started_ts = self.now
actual.duration = 1.
actual.state = task_result.State.COMPLETED
# Trigger _pre_put_hook().
with self.assertRaises(datastore_errors.BadValueError):
actual.put()
actual.state = task_result.State.TIMED_OUT
actual.put()
expected = self._gen_result(
completed_ts=self.now,
duration=1.,
modified_ts=self.now,
failure=True,
started_ts=self.now,
state=task_result.State.TIMED_OUT)
self.assertEqual(expected, actual.to_dict())
示例12: test_BotTaskDimensions
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def test_BotTaskDimensions(self):
cls = task_queues.BotTaskDimensions
now = datetime.datetime(2010, 1, 2, 3, 4, 5)
with self.assertRaises(datastore_errors.BadValueError):
cls(dimensions_flat=['a:b']).put()
with self.assertRaises(datastore_errors.BadValueError):
cls(valid_until_ts=now).put()
with self.assertRaises(datastore_errors.BadValueError):
cls(valid_until_ts=now, dimensions_flat=['a:b', 'a:b']).put()
with self.assertRaises(datastore_errors.BadValueError):
cls(valid_until_ts=now, dimensions_flat=['c:d', 'a:b']).put()
a = cls(valid_until_ts=now, dimensions_flat=['a:b'])
a.put()
self.assertEqual(True, a.is_valid({'a': ['b']}))
self.assertEqual(True, a.is_valid({'a': ['b', 'c']}))
self.assertEqual(False, a.is_valid({'x': ['c']}))
示例13: test_TaskDimensions
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def test_TaskDimensions(self):
cls = task_queues.TaskDimensions
setcls = task_queues.TaskDimensionsSet
now = datetime.datetime(2010, 1, 2, 3, 4, 5)
with self.assertRaises(datastore_errors.BadValueError):
cls().put()
with self.assertRaises(datastore_errors.BadValueError):
cls(sets=[setcls(valid_until_ts=now)]).put()
with self.assertRaises(datastore_errors.BadValueError):
cls(sets=[setcls(dimensions_flat=['a:b'])]).put()
with self.assertRaises(datastore_errors.BadValueError):
cls(sets=[
setcls(valid_until_ts=now, dimensions_flat=['a:b', 'a:b'])]).put()
with self.assertRaises(datastore_errors.BadValueError):
cls(sets=[
setcls(valid_until_ts=now, dimensions_flat=['c:d', 'a:b'])]).put()
with self.assertRaises(datastore_errors.BadValueError):
cls(sets=[
setcls(valid_until_ts=now, dimensions_flat=['a:b', 'c:d']),
setcls(valid_until_ts=now, dimensions_flat=['a:b', 'c:d']),
]).put()
cls(sets=[setcls(valid_until_ts=now, dimensions_flat=['a:b'])]).put()
示例14: test_request_bad_named_cache_and_cipd_input
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def test_request_bad_named_cache_and_cipd_input(self):
# A CIPD package and named caches cannot be mapped to the same path.
req = _gen_request(
properties=_gen_properties(
caches=[
task_request.CacheEntry(name='git_chromium', path='git_cache'),
],
cipd_input=_gen_cipd_input(
packages=[
task_request.CipdPackage(
package_name='foo', path='git_cache', version='latest'),
])))
with self.assertRaises(datastore_errors.BadValueError):
req.put()
req = _gen_request(
properties=_gen_properties(
caches=[
task_request.CacheEntry(name='git_chromium', path='git_cache1'),
],
cipd_input=_gen_cipd_input(packages=[
task_request.CipdPackage(
package_name='foo', path='git_cache2', version='latest'),
]))).put()
示例15: test_request_bad_execution_timeout
# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import BadValueError [as 別名]
def test_request_bad_execution_timeout(self):
# When used locally, it is set to 1, which means it's impossible to test
# below _MIN_TIMEOUT_SECS but above 0.
self.mock(task_request, '_MIN_TIMEOUT_SECS', 30)
p = _gen_request(properties=_gen_properties(execution_timeout_secs=0))
with self.assertRaises(datastore_errors.BadValueError):
# Only termination task may have 0.
p.put()
with self.assertRaises(datastore_errors.BadValueError):
_gen_request(
properties=_gen_properties(
execution_timeout_secs=task_request._MIN_TIMEOUT_SECS-1))
_gen_request(
properties=_gen_properties(
execution_timeout_secs=task_request._MIN_TIMEOUT_SECS))
with self.assertRaises(datastore_errors.BadValueError):
_gen_request(
properties=_gen_properties(
execution_timeout_secs=task_request.MAX_TIMEOUT_SECS+1))
_gen_request(
properties=_gen_properties(
execution_timeout_secs=task_request.MAX_TIMEOUT_SECS)).put()