本文整理汇总了Python中models.api_auth_access.ApiAuthAccess.put方法的典型用法代码示例。如果您正苦于以下问题:Python ApiAuthAccess.put方法的具体用法?Python ApiAuthAccess.put怎么用?Python ApiAuthAccess.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.api_auth_access.ApiAuthAccess
的用法示例。
在下文中一共展示了ApiAuthAccess.put方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.api_auth_access import ApiAuthAccess [as 别名]
# 或者: from models.api_auth_access.ApiAuthAccess import put [as 别名]
def post(self, auth_id):
self._require_admin()
auth = ApiAuthAccess.get_by_id(auth_id)
auth_types_enum = []
if self.request.get('allow_edit_teams'):
auth_types_enum.append(AuthType.EVENT_TEAMS)
if self.request.get('allow_edit_matches'):
auth_types_enum.append(AuthType.EVENT_MATCHES)
if self.request.get('allow_edit_rankings'):
auth_types_enum.append(AuthType.EVENT_RANKINGS)
if self.request.get('allow_edit_alliances'):
auth_types_enum.append(AuthType.EVENT_ALLIANCES)
if self.request.get('allow_edit_awards'):
auth_types_enum.append(AuthType.EVENT_AWARDS)
if self.request.get('allow_edit_match_video'):
auth_types_enum.append(AuthType.MATCH_VIDEO)
if not auth:
auth = ApiAuthAccess(
id=auth_id,
description=self.request.get('description'),
secret=''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(64)),
event_list=[ndb.Key(Event, event_key.strip()) for event_key in self.request.get('event_list_str').split(',')],
auth_types_enum=auth_types_enum,
)
else:
auth.description = self.request.get('description')
auth.event_list = event_list=[ndb.Key(Event, event_key.strip()) for event_key in self.request.get('event_list_str').split(',')]
auth.auth_types_enum = auth_types_enum
auth.put()
self.redirect("/admin/api_auth/manage")
示例2: post
# 需要导入模块: from models.api_auth_access import ApiAuthAccess [as 别名]
# 或者: from models.api_auth_access.ApiAuthAccess import put [as 别名]
def post(self, auth_id):
self._require_admin()
auth = ApiAuthAccess.get_by_id(auth_id)
auth_types_enum = []
if self.request.get('allow_edit_teams'):
auth_types_enum.append(AuthType.EVENT_TEAMS)
if self.request.get('allow_edit_matches'):
auth_types_enum.append(AuthType.EVENT_MATCHES)
if self.request.get('allow_edit_rankings'):
auth_types_enum.append(AuthType.EVENT_RANKINGS)
if self.request.get('allow_edit_alliances'):
auth_types_enum.append(AuthType.EVENT_ALLIANCES)
if self.request.get('allow_edit_awards'):
auth_types_enum.append(AuthType.EVENT_AWARDS)
if self.request.get('allow_edit_match_video'):
auth_types_enum.append(AuthType.MATCH_VIDEO)
if self.request.get('owner', None):
owner = Account.query(Account.email == self.request.get('owner')).fetch()
owner_key = owner[0].key if owner else None
else:
owner_key = None
if self.request.get('expiration', None):
expiration = datetime.strptime(self.request.get('expiration'), '%Y-%m-%d')
else:
expiration = None
if not auth:
auth = ApiAuthAccess(
id=auth_id,
description=self.request.get('description'),
owner=owner_key,
expiration=expiration,
secret=''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(64)),
event_list=[ndb.Key(Event, event_key.strip()) for event_key in self.request.get('event_list_str').split(',')],
auth_types_enum=auth_types_enum,
)
else:
auth.description = self.request.get('description')
auth.event_list = event_list=[ndb.Key(Event, event_key.strip()) for event_key in self.request.get('event_list_str').split(',')]
auth.auth_types_enum = auth_types_enum
auth.owner = owner_key
auth.expiration = expiration
auth.put()
self.redirect("/admin/api_auth/manage")
示例3: _process_accepted
# 需要导入模块: from models.api_auth_access import ApiAuthAccess [as 别名]
# 或者: from models.api_auth_access.ApiAuthAccess import put [as 别名]
def _process_accepted(self, suggestion_id, message):
suggestion = Suggestion.get_by_id(suggestion_id)
event_key = suggestion.contents['event_key']
user = suggestion.author.get()
event = Event.get_by_id(event_key)
auth_id = ''.join(
random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in
range(16))
auth_types = self.request.get_all("auth_types", [])
expiration_offset = int(self.request.get("expiration_days"))
if expiration_offset != -1:
expiration_event_end = event.end_date + timedelta(days=expiration_offset + 1)
expiration_now = datetime.now() + timedelta(days=expiration_offset)
expiration = max(expiration_event_end, expiration_now)
else:
expiration = None
auth = ApiAuthAccess(
id=auth_id,
description="{} @ {}".format(user.display_name, suggestion.contents['event_key']),
secret=''.join(
random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _
in range(64)),
event_list=[ndb.Key(Event, event_key)],
auth_types_enum=[int(type) for type in auth_types],
owner=suggestion.author,
expiration=expiration
)
auth.put()
suggestion.review_state = Suggestion.REVIEW_ACCEPTED
suggestion.reviewer = self.user_bundle.account.key
suggestion.reviewed_at = datetime.now()
suggestion.put()
return auth_id, user, event_key, """Hi {},
We graciously accept your request for auth tokens so you can add data to the following event: {} {}
You can find the keys on your account overview page: https://www.thebluealliance.com/account
{}
If you have any questions, please don't heasitate to reach out to us at [email protected]
Thanks,
TBA Admins
""".format(user.display_name, event.year, event.name, message)
示例4: testExistingAuthKeys
# 需要导入模块: from models.api_auth_access import ApiAuthAccess [as 别名]
# 或者: from models.api_auth_access.ApiAuthAccess import put [as 别名]
def testExistingAuthKeys(self):
self.loginUser()
self.givePermission()
existing_auth = ApiAuthAccess(id='tEsT_id_0',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2016necmp')],
auth_types_enum=[AuthType.EVENT_TEAMS])
existing_auth.put()
suggestion_id = self.createSuggestion()
form = self.getSuggestionForm(suggestion_id)
response = form.submit('verdict', value='accept').follow()
self.assertEqual(response.status_int, 200)
auths = ApiAuthAccess.query().fetch()
self.assertTrue(len(auths), 2)
示例5: post
# 需要导入模块: from models.api_auth_access import ApiAuthAccess [as 别名]
# 或者: from models.api_auth_access.ApiAuthAccess import put [as 别名]
def post(self, auth_id):
self._require_admin()
auth = ApiAuthAccess.get_by_id(auth_id)
if not auth:
auth = ApiAuthAccess(
id=auth_id,
description=self.request.get('description'),
secret=''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(64)),
event_list=[ndb.Key(Event, event_key.strip()) for event_key in self.request.get('event_list_str').split(',')],
)
else:
auth.description = self.request.get('description')
auth.event_list = event_list=[ndb.Key(Event, event_key.strip()) for event_key in self.request.get('event_list_str').split(',')]
auth.put()
self.redirect("/admin/api_auth/manage")
示例6: TestApiTrustedController
# 需要导入模块: from models.api_auth_access import ApiAuthAccess [as 别名]
# 或者: from models.api_auth_access.ApiAuthAccess import put [as 别名]
class TestApiTrustedController(unittest2.TestCase):
def setUp(self):
self.testapp = webtest.TestApp(api_main.app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
self.testbed.init_taskqueue_stub(root_path=".")
self.teams_auth = ApiAuthAccess(id='tEsT_id_0',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_TEAMS])
self.matches_auth = ApiAuthAccess(id='tEsT_id_1',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_MATCHES])
self.rankings_auth = ApiAuthAccess(id='tEsT_id_2',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_RANKINGS])
self.alliances_auth = ApiAuthAccess(id='tEsT_id_3',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_ALLIANCES])
self.awards_auth = ApiAuthAccess(id='tEsT_id_4',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_AWARDS])
self.video_auth = ApiAuthAccess(id='tEsT_id_5',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.MATCH_VIDEO])
self.event = Event(
id='2014casj',
event_type_enum=EventType.REGIONAL,
event_short='casj',
year=2014,
)
self.event.put()
def tearDown(self):
self.testbed.deactivate()
def test_auth(self):
request_path = '/api/trusted/v1/event/2014casj/matches/update'
# Fail
response = self.testapp.post(request_path, expect_errors=True)
self.assertEqual(response.status_code, 400)
self.assertTrue('Error' in response.json)
# Fail
request_body = json.dumps([])
sig = md5.new('{}{}{}'.format('321tEsTsEcReT', request_path, request_body)).hexdigest()
response = self.testapp.post(request_path, request_body, headers={'X-TBA-Auth-Id': 'tEsT_id_1', 'X-TBA-Auth-Sig': sig}, expect_errors=True)
self.assertEqual(response.status_code, 400)
self.assertTrue('Error' in response.json)
self.rankings_auth.put()
self.matches_auth.put()
# Pass
sig = md5.new('{}{}{}'.format('321tEsTsEcReT', request_path, request_body)).hexdigest()
response = self.testapp.post(request_path, request_body, headers={'X-TBA-Auth-Id': 'tEsT_id_1', 'X-TBA-Auth-Sig': sig}, expect_errors=True)
self.assertEqual(response.status_code, 200)
# Fail; bad X-TBA-Auth-Id
sig = md5.new('{}{}{}'.format('321tEsTsEcReT', request_path, request_body)).hexdigest()
response = self.testapp.post(request_path, request_body, headers={'X-TBA-Auth-Id': 'badTestAuthId', 'X-TBA-Auth-Sig': sig}, expect_errors=True)
self.assertEqual(response.status_code, 400)
self.assertTrue('Error' in response.json)
# Fail; bad sig
response = self.testapp.post(request_path, request_body, headers={'X-TBA-Auth-Id': 'tEsT_id_1', 'X-TBA-Auth-Sig': '123abc'}, expect_errors=True)
self.assertEqual(response.status_code, 400)
self.assertTrue('Error' in response.json)
# Fail; bad sig due to wrong body
body2 = json.dumps([{}])
sig = md5.new('{}{}{}'.format('321tEsTsEcReT', request_path, request_body)).hexdigest()
response = self.testapp.post(request_path, body2, headers={'X-TBA-Auth-Id': 'tEsT_id_1', 'X-TBA-Auth-Sig': sig}, expect_errors=True)
self.assertEqual(response.status_code, 400)
self.assertTrue('Error' in response.json)
#.........这里部分代码省略.........
示例7: TestApiTrustedController
# 需要导入模块: from models.api_auth_access import ApiAuthAccess [as 别名]
# 或者: from models.api_auth_access.ApiAuthAccess import put [as 别名]
class TestApiTrustedController(unittest2.TestCase):
def setUp(self):
self.testapp = webtest.TestApp(api_main.app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
self.testbed.init_user_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
self.testbed.init_taskqueue_stub(root_path=".")
self.teams_auth = ApiAuthAccess(id='tEsT_id_0',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_TEAMS])
self.matches_auth = ApiAuthAccess(id='tEsT_id_1',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_MATCHES])
self.rankings_auth = ApiAuthAccess(id='tEsT_id_2',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_RANKINGS])
self.alliances_auth = ApiAuthAccess(id='tEsT_id_3',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_ALLIANCES])
self.awards_auth = ApiAuthAccess(id='tEsT_id_4',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_AWARDS])
self.video_auth = ApiAuthAccess(id='tEsT_id_5',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.MATCH_VIDEO])
self.expired_auth = ApiAuthAccess(id='tEsT_id_6',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_MATCHES],
expiration=datetime.datetime(year=1970, month=1, day=1))
self.owned_auth = ApiAuthAccess(id='tEsT_id_7',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_MATCHES],
owner=ndb.Key(Account, "42"))
self.owned_auth_expired = ApiAuthAccess(id='tEsT_id_8',
secret='321tEsTsEcReT',
description='test',
event_list=[ndb.Key(Event, '2014casj')],
auth_types_enum=[AuthType.EVENT_MATCHES],
owner=ndb.Key(Account, "42"),
expiration=datetime.datetime(year=1970, month=1, day=1))
self.event = Event(
id='2014casj',
event_type_enum=EventType.REGIONAL,
event_short='casj',
year=2014,
)
self.event.put()
def tearDown(self):
self.testbed.deactivate()
def loginUser(self, is_admin=False):
self.testbed.setup_env(
user_email="[email protected]",
user_id="42",
user_is_admin='1' if is_admin else '0',
overwrite=True)
def test_auth(self):
request_path = '/api/trusted/v1/event/2014casj/matches/update'
request_path_caps_key = '/api/trusted/v1/event/2014CASJ/matches/update'
# Fail
response = self.testapp.post(request_path, expect_errors=True)
self.assertEqual(response.status_code, 400)
self.assertTrue('Error' in response.json)
#.........这里部分代码省略.........