本文整理汇总了Python中aspen.utils.utcnow函数的典型用法代码示例。如果您正苦于以下问题:Python utcnow函数的具体用法?Python utcnow怎么用?Python utcnow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了utcnow函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_non_post_is_405
def test_non_post_is_405(self):
self.make_participant('alice', claimed_time=utcnow(), is_admin=True)
self.make_participant('bob', claimed_time=utcnow())
actual = self.client.GxT( '/bob/history/record-an-exchange'
, auth_as='alice'
).code
assert actual == 405
开发者ID:Alive-AttemptTheLifeGangHouse,项目名称:www.gittip.com,代码行数:7,代码来源:test_record_an_exchange.py
示例2: test_withdrawals_work
def test_withdrawals_work(self):
self.make_participant("alice", claimed_time=utcnow(), is_admin=True)
self.make_participant("bob", claimed_time=utcnow(), balance=20)
self.record_an_exchange("-7", "0", "noted", False)
expected = Decimal("13.00")
SQL = "SELECT balance FROM participants WHERE username='bob'"
actual = self.db.one(SQL)
assert actual == expected
开发者ID:joeyespo,项目名称:www.gittip.com,代码行数:8,代码来源:test_record_an_exchange.py
示例3: test_route_should_belong_to_user_else_400
def test_route_should_belong_to_user_else_400(self):
alice = self.make_participant('alice', claimed_time=utcnow(), is_admin=True)
self.make_participant('bob', claimed_time=utcnow())
route = ExchangeRoute.insert(alice, 'paypal', '[email protected]')
response = self.record_an_exchange({'amount': '10', 'fee': '0', 'route_id': route.id}, False)
assert response.code == 400
assert response.body == "Route doesn't exist"
开发者ID:HolaChica,项目名称:gratipay.com,代码行数:8,代码来源:test_record_an_exchange.py
示例4: test_withdrawals_work
def test_withdrawals_work(self):
self.make_participant('alice', claimed_time=utcnow(), is_admin=True)
self.make_participant('bob', claimed_time=utcnow(), balance=20)
self.record_an_exchange('-7', '0', 'noted', False)
expected = [{"balance": Decimal('13.00')}]
SQL = "SELECT balance FROM participants WHERE id='bob'"
actual = list(gittip.db.fetchall(SQL))
assert actual == expected, actual
开发者ID:arkidas,项目名称:www.gittip.com,代码行数:8,代码来源:test_record_an_exchange.py
示例5: test_withdrawals_work
def test_withdrawals_work(self):
self.make_participant('alice', claimed_time=utcnow(), is_admin=True)
self.make_participant('bob', claimed_time=utcnow(), balance=20)
self.record_an_exchange('-7', '0', 'noted', make_participants=False)
expected = Decimal('13.00')
SQL = "SELECT balance FROM participants WHERE username='bob'"
actual = self.db.one(SQL)
assert actual == expected
开发者ID:SirCmpwn,项目名称:gratipay.com,代码行数:8,代码来源:test_record_an_exchange.py
示例6: setup_tips
def setup_tips(*recs):
"""Setup some participants and tips. recs is a list of:
("tipper", "tippee", '2.00', False)
^
|-- good cc?
good_cc can be True, False, or None
"""
tips = []
_participants = {}
for rec in recs:
defaults = good_cc, payin_suspended, claimed = (True, False, True)
if len(rec) == 3:
tipper, tippee, amount = rec
elif len(rec) == 4:
tipper, tippee, amount, good_cc = rec
payin_suspended, claimed = (False, True)
elif len(rec) == 5:
tipper, tippee, amount, good_cc, payin_suspended = rec
claimed = True
elif len(rec) == 6:
tipper, tippee, amount, good_cc, payin_suspended, claimed = rec
assert good_cc in (True, False, None), good_cc
assert payin_suspended in (True, False), payin_suspended
assert claimed in (True, False), claimed
_participants[tipper] = (good_cc, payin_suspended, claimed)
if tippee not in _participants:
_participants[tippee] = defaults
now = utcnow()
tips.append({ "ctime": now
, "mtime": now
, "tipper": tipper
, "tippee": tippee
, "amount": Decimal(amount)
})
then = utcnow() - datetime.timedelta(seconds=3600)
participants = []
for participant_id, (good_cc, payin_suspended, claimed) in _participants.items():
rec = {"id": participant_id}
if good_cc is not None:
rec["last_bill_result"] = "" if good_cc else "Failure!"
rec["balanced_account_uri"] = "/v1/blah/blah/" + participant_id
rec["payin_suspended"] = payin_suspended
if claimed:
rec["claimed_time"] = then
participants.append(rec)
return ["participants"] + participants + ["tips"] + tips
开发者ID:gvenkataraman,项目名称:www.gittip.com,代码行数:57,代码来源:testing.py
示例7: test_tip
def test_tip(self, log, transfer):
self.db.run("""
UPDATE participants
SET balance=1
, balanced_customer_href=%s
, is_suspicious=False
WHERE username='alice'
""", (self.BALANCED_CUSTOMER_HREF,))
amount = D('1.00')
invalid_amount = D('0.00')
tip = { 'amount': amount
, 'tippee': self.alice.username
, 'claimed_time': utcnow()
}
ts_start = utcnow()
result = self.payday.tip(self.alice, tip, ts_start)
assert result == 1
result = transfer.called_with(self.alice.username, tip['tippee'],
tip['amount'])
assert result
assert log.called_with('SUCCESS: $1 from mjallday to alice.')
# XXX: Should these tests be broken down to a separate class with the
# common setup factored in to a setUp method.
# XXX: We should have constants to compare the values to
# invalid amount
tip['amount'] = invalid_amount
result = self.payday.tip(self.alice, tip, ts_start)
assert result == 0
tip['amount'] = amount
# XXX: We should have constants to compare the values to
# not claimed
tip['claimed_time'] = None
result = self.payday.tip(self.alice, tip, ts_start)
assert result == 0
# XXX: We should have constants to compare the values to
# claimed after payday
tip['claimed_time'] = utcnow()
result = self.payday.tip(self.alice, tip, ts_start)
assert result == 0
ts_start = utcnow()
# XXX: We should have constants to compare the values to
# transfer failed
transfer.return_value = False
result = self.payday.tip(self.alice, tip, ts_start)
assert result == -1
开发者ID:barmoshe,项目名称:www.gittip.com,代码行数:56,代码来源:test_billing_payday.py
示例8: test_tip
def test_tip(self, log, transfer):
self.db.run("""
UPDATE participants
SET balance=1
, balanced_account_uri=%s
, is_suspicious=False
WHERE username='alice'
""", (self.BALANCED_ACCOUNT_URI,))
amount = Decimal('1.00')
invalid_amount = Decimal('0.00')
tip = { 'amount': amount
, 'tippee': self.alice.username
, 'claimed_time': utcnow()
}
ts_start = utcnow()
result = self.payday.tip(self.alice, tip, ts_start)
assert_equals(result, 1)
result = transfer.called_with(self.alice.username, tip['tippee'],
tip['amount'])
self.assertTrue(result)
self.assertTrue(log.called_with('SUCCESS: $1 from mjallday to alice.'))
# XXX: Should these tests be broken down to a separate class with the
# common setup factored in to a setUp method.
# XXX: We should have constants to compare the values to
# invalid amount
tip['amount'] = invalid_amount
result = self.payday.tip(self.alice, tip, ts_start)
assert_equals(result, 0)
tip['amount'] = amount
# XXX: We should have constants to compare the values to
# not claimed
tip['claimed_time'] = None
result = self.payday.tip(self.alice, tip, ts_start)
assert_equals(result, 0)
# XXX: We should have constants to compare the values to
# claimed after payday
tip['claimed_time'] = utcnow()
result = self.payday.tip(self.alice, tip, ts_start)
assert_equals(result, 0)
ts_start = utcnow()
# XXX: We should have constants to compare the values to
# transfer failed
transfer.return_value = False
result = self.payday.tip(self.alice, tip, ts_start)
assert_equals(result, -1)
开发者ID:stedy,项目名称:www.gittip.com,代码行数:56,代码来源:test_billing_payday.py
示例9: test_api_returns_amount_and_totals
def test_api_returns_amount_and_totals(self):
"Test that we get correct amounts and totals back on POSTs to subscription.json"
# First, create some test data
# We need accounts
now = utcnow()
self.make_team("A", is_approved=True)
self.make_team("B", is_approved=True)
self.make_participant("alice", claimed_time=now, last_bill_result='')
# Then, add a $1.50 and $3.00 subscription
response1 = self.client.POST( "/A/subscription.json"
, {'amount': "1.50"}
, auth_as='alice'
)
response2 = self.client.POST( "/B/subscription.json"
, {'amount': "3.00"}
, auth_as='alice'
)
# Confirm we get back the right amounts.
first_data = json.loads(response1.body)
second_data = json.loads(response2.body)
assert first_data['amount'] == "1.50"
assert first_data['total_giving'] == "1.50"
assert second_data['amount'] == "3.00"
assert second_data['total_giving'] == "4.50"
开发者ID:gaurishankarprasad,项目名称:gratipay.com,代码行数:28,代码来源:test_subscription_json.py
示例10: sign_in
def sign_in(self, cookies):
"""Start a new session for the user.
"""
token = uuid.uuid4().hex
expires = utcnow() + SESSION_TIMEOUT
self.participant.update_session(token, expires)
set_cookie(cookies, SESSION, token, expires)
开发者ID:HolaChica,项目名称:gratipay.com,代码行数:7,代码来源:user.py
示例11: make_participant
def make_participant(self, username, **kw):
# At this point wireup.db() has been called, but not ...
wireup.username_restrictions(self.client.website)
participant = Participant.with_random_username()
participant.change_username(username)
if 'elsewhere' in kw or 'claimed_time' in kw:
username = participant.username
platform = kw.pop('elsewhere', 'github')
self.seq += 1
self.db.run("""
INSERT INTO elsewhere
(platform, user_id, user_name, participant)
VALUES (%s,%s,%s,%s)
""", (platform, self.seq, username, username))
# Update participant
if kw:
if kw.get('claimed_time') == 'now':
kw['claimed_time'] = utcnow()
cols, vals = zip(*kw.items())
cols = ', '.join(cols)
placeholders = ', '.join(['%s']*len(vals))
participant = self.db.one("""
UPDATE participants
SET ({0}) = ({1})
WHERE username=%s
RETURNING participants.*::participants
""".format(cols, placeholders), vals+(participant.username,))
return participant
开发者ID:atunit,项目名称:www.gittip.com,代码行数:32,代码来源:__init__.py
示例12: setUp
def setUp(self):
super(Harness, self).setUp()
now = utcnow()
for idx, username in enumerate(["alice", "bob", "carl"], start=1):
self.make_participant(username, claimed_time=now)
twitter_account = TwitterAccount(idx, {"screen_name": username})
Participant(username).take_over(twitter_account)
开发者ID:sigmavirus24,项目名称:www.gittip.com,代码行数:7,代码来源:test_participant.py
示例13: test_post_user_is_not_member_or_team_returns_403
def test_post_user_is_not_member_or_team_returns_403(self):
client, csrf_token = self.make_client_and_csrf()
self.make_team_and_participant()
self.make_participant("bob", claimed_time=utcnow(), number='plural')
response = client.post('/team/members/alice.json'
, {
'take': '0.01'
, 'csrf_token': csrf_token
}
, user='team'
)
actual = response.code
assert actual == 200
response = client.post('/team/members/bob.json'
, {
'take': '0.01'
, 'csrf_token': csrf_token
}
, user='team'
)
actual = response.code
assert actual == 200
response = client.post('/team/members/alice.json'
, { 'csrf_token': csrf_token }
, user='bob'
)
actual = response.code
assert actual == 403
开发者ID:abnor,项目名称:www.gittip.com,代码行数:35,代码来源:test_membername_json.py
示例14: test_joining_and_leaving_community
def test_joining_and_leaving_community(self):
self.make_participant("alice", claimed_time=utcnow())
response = self.client.GET('/for/communities.json', auth_as='alice')
assert len(json.loads(response.body)['communities']) == 0
response = self.client.POST( '/for/communities.json'
, {'name': 'Test', 'is_member': 'true'}
, auth_as='alice'
)
communities = json.loads(response.body)['communities']
assert len(communities) == 1
assert communities[0]['name'] == 'Test'
assert communities[0]['nmembers'] == 1
response = self.client.POST( '/for/communities.json'
, {'name': 'Test', 'is_member': 'false'}
, auth_as='alice'
)
response = self.client.GET('/for/communities.json', auth_as='alice')
assert len(json.loads(response.body)['communities']) == 0
# Check that the empty community was deleted
community = Community.from_slug('test')
assert not community
开发者ID:HolaChica,项目名称:gratipay.com,代码行数:28,代码来源:test_communities_json.py
示例15: test_post_non_team_member_adds_member_returns_403
def test_post_non_team_member_adds_member_returns_403(self):
client, csrf_token = self.make_client_and_csrf()
self.make_team_and_participant()
self.make_participant("bob", claimed_time=utcnow())
response = client.post('/team/members/alice.json'
, {
'take': '0.01'
, 'csrf_token': csrf_token
}
, user='team'
)
actual = response.code
assert actual == 200, actual
response = client.post('/team/members/bob.json'
, {
'take': '0.01'
, 'csrf_token': csrf_token
}
, user='alice'
)
actual = response.code
assert actual == 403, actual
开发者ID:angleman,项目名称:www.gittip.com,代码行数:27,代码来源:test_membername_json.py
示例16: test_post_can_leave_community
def test_post_can_leave_community(self):
client, csrf_token = self.make_client_and_csrf()
community = 'Test'
self.make_participant("alice", claimed_time=utcnow())
response = client.post('/for/communities.json'
, { 'name': community
, 'is_member': 'true'
, 'csrf_token': csrf_token
}
, user='alice'
)
response = client.post('/for/communities.json'
, { 'name': community
, 'is_member': 'false'
, 'csrf_token': csrf_token
}
, user='alice'
)
response = client.get('/for/communities.json', 'alice')
actual = len(json.loads(response.body)['communities'])
assert actual == 0, actual
开发者ID:angleman,项目名称:www.gittip.com,代码行数:26,代码来源:test_communities_json.py
示例17: also_prune_variant
def also_prune_variant(self, also_prune, tippees=1):
now = utcnow()
self.make_participant("test_tippee1", claimed_time=now)
self.make_participant("test_tippee2", claimed_time=now)
self.make_participant("test_tipper", claimed_time=now)
data = [
{'username': 'test_tippee1', 'platform': 'gittip', 'amount': '1.00'},
{'username': 'test_tippee2', 'platform': 'gittip', 'amount': '2.00'}
]
response = self.client.POST( '/test_tipper/tips.json'
, body=json.dumps(data)
, content_type='application/json'
, auth_as='test_tipper'
)
assert response.code == 200
assert len(json.loads(response.body)) == 2
response = self.client.POST( '/test_tipper/tips.json?also_prune=' + also_prune
, body=json.dumps([{ 'username': 'test_tippee2'
, 'platform': 'gittip'
, 'amount': '1.00'
}])
, content_type='application/json'
, auth_as='test_tipper'
)
assert response.code == 200
response = self.client.GET('/test_tipper/tips.json', auth_as='test_tipper')
assert response.code == 200
assert len(json.loads(response.body)) == tippees
开发者ID:Alive-AttemptTheLifeGangHouse,项目名称:www.gittip.com,代码行数:35,代码来源:test_tips_json.py
示例18: setUp
def setUp(self):
super(Harness, self).setUp()
now = utcnow()
for idx, username in enumerate(['alice', 'bob', 'carl'], start=1):
self.make_participant(username, claimed_time=now)
twitter_account = TwitterAccount(idx, {'screen_name': username})
Participant.from_username(username).take_over(twitter_account)
开发者ID:angleman,项目名称:www.gittip.com,代码行数:7,代码来源:test_participant.py
示例19: test_get_amount_and_total_back_from_api
def test_get_amount_and_total_back_from_api(self):
"Test that we get correct amounts and totals back on POSTs to tip.json"
# First, create some test data
# We need accounts
now = utcnow()
self.make_participant("test_tippee1", claimed_time=now)
self.make_participant("test_tippee2", claimed_time=now)
self.make_participant("test_tipper")
# Then, add a $1.50 and $3.00 tip
response1 = self.client.POST( "/test_tippee1/tip.json"
, {'amount': "1.00"}
, auth_as='test_tipper'
)
response2 = self.client.POST( "/test_tippee2/tip.json"
, {'amount': "3.00"}
, auth_as='test_tipper'
)
# Confirm we get back the right amounts.
first_data = json.loads(response1.body)
second_data = json.loads(response2.body)
assert first_data['amount'] == "1.00"
assert first_data['total_giving'] == "1.00"
assert second_data['amount'] == "3.00"
assert second_data['total_giving'] == "4.00"
开发者ID:atunit,项目名称:www.gittip.com,代码行数:28,代码来源:test_tip_json.py
示例20: test_start_zero_out_and_get_participants
def test_start_zero_out_and_get_participants(self, log):
self.make_participant(
"bob", balance=10, claimed_time=None, pending=1, balanced_customer_href=self.BALANCED_CUSTOMER_HREF
)
self.make_participant(
"carl", balance=10, claimed_time=utcnow(), pending=1, balanced_customer_href=self.BALANCED_CUSTOMER_HREF
)
self.db.run(
"""
UPDATE participants
SET balance=0
, claimed_time=null
, pending=null
, balanced_customer_href=%s
WHERE username='alice'
""",
(self.BALANCED_CUSTOMER_HREF,),
)
ts_start = self.payday.start()
self.payday.zero_out_pending(ts_start)
participants = self.payday.get_participants(ts_start)
expected_logging_call_args = [
("Starting a new payday."),
("Payday started at {}.".format(ts_start)),
("Zeroed out the pending column."),
("Fetched participants."),
]
expected_logging_call_args.reverse()
for args, _ in log.call_args_list:
assert args[0] == expected_logging_call_args.pop()
log.reset_mock()
# run a second time, we should see it pick up the existing payday
second_ts_start = self.payday.start()
self.payday.zero_out_pending(second_ts_start)
second_participants = self.payday.get_participants(second_ts_start)
assert ts_start == second_ts_start
participants = list(participants)
second_participants = list(second_participants)
# carl is the only valid participant as he has a claimed time
assert len(participants) == 1
assert participants == second_participants
expected_logging_call_args = [
("Picking up with an existing payday."),
("Payday started at {}.".format(second_ts_start)),
("Zeroed out the pending column."),
("Fetched participants."),
]
expected_logging_call_args.reverse()
for args, _ in log.call_args_list:
assert args[0] == expected_logging_call_args.pop()
开发者ID:joshgillies,项目名称:www.gittip.com,代码行数:60,代码来源:test_billing_payday.py
注:本文中的aspen.utils.utcnow函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论