本文整理汇总了Python中utils.set_utcnow_for_test函数的典型用法代码示例。如果您正苦于以下问题:Python set_utcnow_for_test函数的具体用法?Python set_utcnow_for_test怎么用?Python set_utcnow_for_test使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_utcnow_for_test函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_data_expires_after_ttl
def test_data_expires_after_ttl(self):
cache = resources.RamCache()
cache.put('a', 'b', 10)
utils.set_utcnow_for_test(9.99)
assert cache.get('a') == 'b'
utils.set_utcnow_for_test(10.01)
assert cache.get('a') is None
开发者ID:google,项目名称:personfinder,代码行数:7,代码来源:test_resources.py
示例2: test_put_expiry_flags
def test_put_expiry_flags(self):
# Try put_expiry_flags when the record has not expired yet.
assert not self.p1.is_expired
self.p1.put_expiry_flags()
# Both entities should be unexpired.
p1 = db.get(self.p1.key())
assert p1.expiry_date
assert not p1.is_expired
assert p1.given_name == 'John'
n1_1 = db.get(self.n1_1.key())
assert not n1_1.is_expired
# Advance past the expiry date and try again.
set_utcnow_for_test(datetime(2010, 2, 3))
p1.put_expiry_flags()
# Both entities should be expired.
p1 = db.get(self.p1.key())
assert p1.is_expired
assert p1.given_name == 'John'
assert p1.source_date == datetime(2010, 2, 3)
assert p1.entry_date == datetime(2010, 2, 3)
assert p1.expiry_date == datetime(2010, 2, 1)
n1_1 = db.get(self.n1_1.key())
assert n1_1.is_expired
开发者ID:Aloknayan,项目名称:personfinder,代码行数:26,代码来源:test_model.py
示例3: test_rejects_expired_token
def test_rejects_expired_token(self):
"""Tests that an expired token is rejected."""
config.set(xsrf_token_key='abcdef')
tool = utils.XsrfTool()
token = tool.generate_token(12345, 'test_action')
utils.set_utcnow_for_test(XsrfToolTests.TEST_NOW +
datetime.timedelta(hours=4, minutes=1))
self.assertFalse(tool.verify_token(token, 12345, 'test_action'))
开发者ID:google,项目名称:personfinder,代码行数:8,代码来源:test_xsrftool.py
示例4: test_get_default_expiration_date
def test_get_default_expiration_date(self):
"""Tests that the expected default expiration date is correctly."""
self.login_as_manager()
utils.set_utcnow_for_test(datetime.datetime(2010, 1, 5))
res = self.client.get('/haiti/admin/acls/', secure=True)
self.assertEqual(
res.context['default_expiration_date'],
datetime.datetime(2011, 1, 5))
开发者ID:google,项目名称:personfinder,代码行数:8,代码来源:test_admin_acls.py
示例5: test_expiration_placeholder_with_bad_source_entry_date
def test_expiration_placeholder_with_bad_source_entry_date(self):
"""validate_expired_records_removed should return a list with the
person_record_ids of all expired records whose source_date and entry_date
are not the same value and are not created within a day after expiration"""
validator = self.set_up_validator(
PfifXml.XML_EXPIRE_99_NO_DATA_NONSYNCED_DATES)
utils.set_utcnow_for_test(ValidatorTests.EXPIRED_TIME)
self.assertEqual(len(validator.validate_expired_records_removed()), 2)
开发者ID:google,项目名称:personfinder,代码行数:8,代码来源:test_validator.py
示例6: test_expired_records_with_unremoved_top_level_note
def test_expired_records_with_unremoved_top_level_note(self):
"""validate_expired_records_removed should return a list with messages for
each expired record that still had a note referring to its
person_record_id"""
validator = (
self.set_up_validator(PfifXml.XML_EXPIRE_99_HAS_NOTE_DATA))
utils.set_utcnow_for_test(ValidatorTests.EXPIRED_TIME)
self.assertEqual(len(validator.validate_expired_records_removed()), 1)
开发者ID:google,项目名称:personfinder,代码行数:8,代码来源:test_validator.py
示例7: tearDown
def tearDown(self):
utils.set_utcnow_for_test(None)
resources.clear_caches()
Resource.get_by_key_name = self.resource_get_by_key_name_original
webapp.template.Template.__init__ = self.template_init_original
webapp.template.Template.render = self.template_render_original
db.delete(self.temp_entity_keys)
开发者ID:google,项目名称:personfinder,代码行数:9,代码来源:test_resources.py
示例8: test_past_due
def test_past_due(self):
"""Make sure Person records are detected as past due correctly."""
def assert_past_due_count(expected):
assert len(list(model.Person.past_due_records())) == expected
assert_past_due_count(0)
set_utcnow_for_test(datetime(2010, 2, 15))
assert_past_due_count(1)
set_utcnow_for_test(datetime(2010, 3, 15))
assert_past_due_count(2)
开发者ID:dddaisuke,项目名称:hack4jp,代码行数:9,代码来源:test_model.py
示例9: test_no_expiration_without_date
def test_no_expiration_without_date(self):
"""validate_expired_records_removed should return an empty list when the
there isn't an expiry_date"""
validator = self.set_up_validator(PfifXml.XML_NO_EXPIRY_DATE)
utils.set_utcnow_for_test(ValidatorTests.EXPIRED_TIME)
self.assertEqual(len(validator.validate_expired_records_removed()), 0)
validator = self.set_up_validator(PfifXml.XML_EMPTY_EXPIRY_DATE)
utils.set_utcnow_for_test(ValidatorTests.EXPIRED_TIME)
self.assertEqual(len(validator.validate_expired_records_removed()), 0)
开发者ID:google,项目名称:personfinder,代码行数:10,代码来源:test_validator.py
示例10: test_clean_up_in_test_mode_multi_tasks
def test_clean_up_in_test_mode_multi_tasks(self):
"""Test the clean up in test mode when it is broken into multiple
tasks."""
class Listener(object):
def before_deletion(self, person):
# This will be implemented later using mock.
assert False
tasks.CleanUpInTestMode.DELETION_AGE_SECONDS = 2 * 3600 # 2 hours
utcnow = datetime.datetime(2010, 1, 1, 7, 0, 0)
set_utcnow_for_test(utcnow)
self.mox = mox.Mox()
cleanup = \
test_handler.initialize_handler(tasks.CleanUpInTestMode,
tasks.CleanUpInTestMode.ACTION)
listener = Listener()
cleanup.set_listener(listener)
# Simulates add_task_for_repo() because it doesn't work in unit tests.
def add_task_for_repo(repo, task_name, action, **kwargs):
cleanup = test_handler.initialize_handler(
tasks.CleanUpInTestMode, action, repo=repo, params=kwargs)
cleanup.set_listener(listener)
cleanup.get()
self.mox.StubOutWithMock(cleanup, 'add_task_for_repo')
(cleanup.add_task_for_repo(
'haiti',
mox.IsA(str),
mox.IsA(str),
utcnow=str(calendar.timegm(utcnow.utctimetuple())),
cursor=mox.IsA(str),
queue_name=mox.IsA(str)).
WithSideEffects(add_task_for_repo).MultipleTimes())
def raise_deadline_exceeded_error(_):
raise runtime.DeadlineExceededError()
self.mox.StubOutWithMock(listener, 'before_deletion')
listener.before_deletion(self.key_p1)
listener.before_deletion(self.key_p2).WithSideEffects(
raise_deadline_exceeded_error)
listener.before_deletion(self.key_p2)
self.mox.ReplayAll()
config.set(test_mode=True, repo='haiti')
# This should run multiple tasks and finally deletes all records.
cleanup.get()
assert db.get(self.key_p1) is None
assert db.get(self.key_p2) is None
self.mox.UnsetStubs()
self.mox.VerifyAll()
开发者ID:matthew-z,项目名称:personfinder,代码行数:55,代码来源:test_tasks.py
示例11: test_unexpired_records
def test_unexpired_records(self):
"""validate_expired_records_removed should return an empty list when no
records are expired"""
validator = self.set_up_validator(
PfifXml.XML_EXPIRE_99_HAS_DATA_NONSYNCED_DATES)
not_expired_1998 = datetime.datetime(1998, 11, 1, 1, 1, 1, 1)
utils.set_utcnow_for_test(not_expired_1998)
self.assertEqual(len(validator.validate_expired_records_removed()), 0)
just_not_expired = datetime.datetime(1999, 2, 4, 4, 5, 5, 0)
utils.set_utcnow_for_test(just_not_expired)
self.assertEqual(len(validator.validate_expired_records_removed()), 0)
开发者ID:google,项目名称:personfinder,代码行数:11,代码来源:test_validator.py
示例12: setUp
def setUp(self):
set_utcnow_for_test(datetime(2010, 1, 1))
self.p1 = model.Person.create_original(
'haiti',
first_name='John',
last_name='Smith',
home_street='Washington St.',
home_city='Los Angeles',
home_state='California',
home_postal_code='11111',
home_neighborhood='Good Neighborhood',
author_name='Alice Smith',
author_phone='111-111-1111',
author_email='[email protected]',
source_url='https://www.source.com',
source_date=datetime(2010, 1, 1),
source_name='Source Name',
entry_date=datetime(2010, 1, 1),
expiry_date=datetime(2010, 2, 1),
other='')
self.p2 = model.Person.create_original(
'haiti',
first_name='Tzvika',
last_name='Hartman',
home_street='Herzl St.',
home_city='Tel Aviv',
home_state='Israel',
entry_date=datetime(2010, 1, 1),
expiry_date=datetime(2010, 3, 1),
other='')
self.key_p1 = db.put(self.p1)
self.key_p2 = db.put(self.p2)
self.n1_1 = model.Note.create_original(
'haiti',
person_record_id=self.p1.record_id,
linked_person_record_id=self.p2.record_id,
status=u'believed_missing',
found=False,
entry_date=get_utcnow(),
source_date=datetime(2000, 1, 1))
self.n1_2 = model.Note.create_original(
'haiti',
person_record_id=self.p1.record_id,
found=True,
entry_date=get_utcnow(),
source_date=datetime(2000, 2, 2))
self.key_n1_1 = db.put(self.n1_1)
self.key_n1_2 = db.put(self.n1_2)
# Update the Person entity according to the Note.
self.p1.update_from_note(self.n1_1)
self.p1.update_from_note(self.n1_2)
db.put(self.p1)
开发者ID:dddaisuke,项目名称:hack4jp,代码行数:54,代码来源:test_model.py
示例13: test_task
def test_task(self):
utils.set_utcnow_for_test(datetime.datetime(2010, 4, 2))
self.run_task('/haiti/tasks/cleanup_stray_notes',
data={}, method='POST')
notes_q = model.Note.all()
# Note #1 should be kept because it's associated with an existing Person
# record, and note #2 should be kept because it's within the grace
# period.
self.assertEqual(2, notes_q.count())
notes = notes_q[:2]
self.assertEqual(sorted([n.key() for n in notes]),
sorted([self.note1.key(), self.note2.key()]))
开发者ID:google,项目名称:personfinder,代码行数:12,代码来源:test_deletion.py
示例14: setUp
def setUp(self):
logging.basicConfig(level=logging.INFO, stream=sys.stderr)
self.mox = None
# Setup cheerfully stolen from test_model.
set_utcnow_for_test(datetime.datetime(2010, 1, 1))
self.photo = model.Photo.create('haiti', image_data='xyz')
self.photo.put()
self.photo_key = self.photo.key()
self.p1 = model.Person.create_original(
'haiti',
given_name='John',
family_name='Smith',
home_street='Washington St.',
home_city='Los Angeles',
home_state='California',
home_postal_code='11111',
home_neighborhood='Good Neighborhood',
author_name='Alice Smith',
author_phone='111-111-1111',
author_email='[email protected]',
photo_url='',
photo=self.photo,
source_url='https://www.source.com',
source_date=datetime.datetime(2010, 1, 1),
source_name='Source Name',
entry_date=datetime.datetime(2010, 1, 1),
expiry_date=datetime.datetime(2010, 2, 1),
other='')
self.p2 = model.Person.create_original(
'haiti',
given_name='Tzvika',
family_name='Hartman',
home_street='Herzl St.',
home_city='Tel Aviv',
home_state='Israel',
source_date=datetime.datetime(2010, 1, 1),
entry_date=datetime.datetime(2010, 1, 1),
expiry_date=datetime.datetime(2010, 3, 1),
other='')
self.key_p1 = db.put(self.p1)
self.key_p2 = db.put(self.p2)
self.n1_1 = model.Note.create_original(
'haiti',
person_record_id=self.p1.record_id,
linked_person_record_id=self.p2.record_id,
status=u'believed_missing',
author_made_contact=False,
entry_date=get_utcnow(),
source_date=datetime.datetime(2010, 1, 2))
self.note_id = self.n1_1.note_record_id
db.put(self.n1_1)
self.to_delete = [self.p1, self.p2, self.n1_1, self.photo]
开发者ID:santoshsahoo,项目名称:personfinder,代码行数:53,代码来源:test_tasks.py
示例15: get
def get(self):
utcnow_before_change = get_utcnow()
utcnow = self.params.utcnow
if self.is_test_mode():
try:
logging.info('Setting utcnow to %r' % utcnow)
set_utcnow_for_test(utcnow)
self.render('templates/set_utcnow.html', utcnow=get_utcnow(),
utcbefore=utcnow_before_change)
except Exception, e:
# bad param.
return self.error(400, 'bad timestamp %s, e=%s' % (utcnow, e))
开发者ID:dddaisuke,项目名称:hack4jp,代码行数:12,代码来源:set_utcnow.py
示例16: setUp
def setUp(self):
utils.set_utcnow_for_test(0)
resources.clear_caches()
resources.set_active_bundle_name('1')
self.temp_entity_keys = []
self.put_resource('1', 'base.html.template', 50,
'hi! {% block foo %}{% endblock foo %}')
self.put_resource('1', 'base.html.template:es', 40,
'\xc2\xa1hola! {% block foo %}{% endblock foo %}')
self.put_resource('1', 'page.html.template', 30,
'{% extends "base.html.template" %} '
'{% block foo %}default{% endblock foo %}')
self.put_resource('1', 'page.html.template:fr', 20,
'{% extends "base.html.template" %} '
'{% block foo %}fran\xc3\xa7ais{% endblock foo %}')
self.put_resource('1', 'static.html', 30, 'hello')
self.put_resource('1', 'static.html:fr', 20, 'bonjour')
self.put_resource('1', 'data', 10, '\xff\xfe\xfd\xfc')
self.fetched = []
self.compiled = []
self.rendered = []
self.resource_get_by_key_name_original = Resource.get_by_key_name
self.template_init_original = django.template.Template.__init__
self.template_render_original = django.template.Template.render
test_self = self
@staticmethod
def resource_get_by_key_name_for_test(
key_name, parent, *args, **kwargs):
test_self.fetched.append(key_name) # track datastore fetches
return test_self.resource_get_by_key_name_original(
key_name, parent, *args, **kwargs)
def template_init_for_test(
self, content, origin, name, *args, **kwargs):
test_self.compiled.append(name) # track template compilations
return test_self.template_init_original(
self, content, origin, name, *args, **kwargs)
def template_render_for_test(self, context, *args, **kwargs):
test_self.rendered.append(self.name) # track render calls
return test_self.template_render_original(
self, context, *args, **kwargs)
Resource.get_by_key_name = resource_get_by_key_name_for_test
django.template.Template.__init__ = template_init_for_test
django.template.Template.render = template_render_for_test
开发者ID:google,项目名称:personfinder,代码行数:51,代码来源:test_resources.py
示例17: test_set_utcnow_for_test
def test_set_utcnow_for_test(self):
max_delta = datetime.timedelta(0,0,100)
utcnow = datetime.datetime.utcnow()
utilsnow = utils.get_utcnow()
# max sure we're getting the current time.
assert (utilsnow - utcnow) < max_delta
# now set the utils time.
test_time = datetime.datetime(2011, 1, 1, 0, 0)
utils.set_utcnow_for_test(test_time)
assert utils.get_utcnow() == test_time
# now unset.
utils.set_utcnow_for_test(None)
assert utils.get_utcnow()
assert utils.get_utcnow() != test_time
开发者ID:Aloknayan,项目名称:personfinder,代码行数:14,代码来源:test_utils.py
示例18: setUp
def setUp(self):
utils.set_utcnow_for_test(0)
resources.clear_caches()
resources.set_active_bundle_name("1")
self.temp_entity_keys = []
self.put_resource("1", "base.html.template", 50, "hi! {% block foo %}{% endblock foo %}")
self.put_resource("1", "base.html.template:es", 40, "\xc2\xa1hola! {% block foo %}{% endblock foo %}")
self.put_resource(
"1",
"page.html.template",
30,
'{% extends "base.html.template" %} ' "{% block foo %}default{% endblock foo %}",
)
self.put_resource(
"1",
"page.html.template:fr",
20,
'{% extends "base.html.template" %} ' "{% block foo %}fran\xc3\xa7ais{% endblock foo %}",
)
self.put_resource("1", "static.html", 30, "hello")
self.put_resource("1", "static.html:fr", 20, "bonjour")
self.put_resource("1", "data", 10, "\xff\xfe\xfd\xfc")
self.fetched = []
self.compiled = []
self.rendered = []
self.resource_get_by_key_name_original = Resource.get_by_key_name
self.template_init_original = django.template.Template.__init__
self.template_render_original = django.template.Template.render
test_self = self
@staticmethod
def resource_get_by_key_name_for_test(key_name, parent):
test_self.fetched.append(key_name) # track datastore fetches
return test_self.resource_get_by_key_name_original(key_name, parent)
def template_init_for_test(self, content, origin, name):
test_self.compiled.append(name) # track template compilations
return test_self.template_init_original(self, content, origin, name)
def template_render_for_test(self, context):
test_self.rendered.append(self.name) # track render calls
return test_self.template_render_original(self, context)
Resource.get_by_key_name = resource_get_by_key_name_for_test
django.template.Template.__init__ = template_init_for_test
django.template.Template.render = template_render_for_test
开发者ID:resilientchennai,项目名称:personfinder,代码行数:50,代码来源:test_resources.py
示例19: test_wipe_contents
def test_wipe_contents(self):
# Advance past the expiry date.
set_utcnow_for_test(datetime(2010, 2, 3))
self.p1.put_expiry_flags()
# Try wiping the contents.
self.p1.wipe_contents()
p1 = db.get(self.p1.key())
assert p1.is_expired
assert p1.first_name == None
assert p1.source_date == datetime(2010, 2, 3)
assert p1.entry_date == datetime(2010, 2, 3)
assert p1.expiry_date == datetime(2010, 2, 1)
assert not db.get(self.n1_1.key())
开发者ID:dddaisuke,项目名称:hack4jp,代码行数:15,代码来源:test_model.py
示例20: set_utcnow_for_test
def set_utcnow_for_test(self, new_utcnow, flush=''):
"""Sets the utils.get_utcnow() clock locally and on the server, and
optionally also flushes caches on the server.
Args:
new_utcnow: A datetime, timestamp, or None to revert to real time.
flush: Names of caches to flush (see main.flush_caches).
"""
if new_utcnow is None:
param = 'real'
elif isinstance(new_utcnow, (int, float)):
param = str(new_utcnow)
else:
param = calendar.timegm(new_utcnow.utctimetuple())
path = '/?utcnow=%s&flush=%s' % (param, flush)
# Requesting '/' gives a fast redirect; to save time, don't follow it.
scrape.Session(verbose=0).go(self.path_to_url(path), redirects=0)
utils.set_utcnow_for_test(new_utcnow)
开发者ID:Stephanie1125,项目名称:personfinder,代码行数:18,代码来源:server_tests_base.py
注:本文中的utils.set_utcnow_for_test函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论