本文整理匯總了Python中qiita_db.study.StudyPerson.from_name_and_affiliation方法的典型用法代碼示例。如果您正苦於以下問題:Python StudyPerson.from_name_and_affiliation方法的具體用法?Python StudyPerson.from_name_and_affiliation怎麽用?Python StudyPerson.from_name_and_affiliation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qiita_db.study.StudyPerson
的用法示例。
在下文中一共展示了StudyPerson.from_name_and_affiliation方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_post_new_person
# 需要導入模塊: from qiita_db.study import StudyPerson [as 別名]
# 或者: from qiita_db.study.StudyPerson import from_name_and_affiliation [as 別名]
def test_post_new_person(self):
body = {'name': 'Boaty McBoatFace', 'affiliation': 'UCSD',
'email': '[email protected]', 'phone': '720-876-5309'}
response = self.post('/api/v1/person', data=body, headers=self.headers)
self.assertEqual(response.code, 201)
obs = json_decode(response.body)
exp = StudyPerson.from_name_and_affiliation(body['name'],
body['affiliation']).id
self.assertEqual(exp, obs['id'])
示例2: get
# 需要導入模塊: from qiita_db.study import StudyPerson [as 別名]
# 或者: from qiita_db.study.StudyPerson import from_name_and_affiliation [as 別名]
def get(self, *args, **kwargs):
name = self.get_argument('name', None)
affiliation = self.get_argument('affiliation', None)
if name is None and affiliation is None:
# Retrieve the list of all the StudyPerson
sp = [{'name': p.name, 'affiliation': p.affiliation}
for p in StudyPerson.iter()]
self.write(json_encode(sp))
self.finish()
elif name is not None and affiliation is not None:
try:
p = StudyPerson.from_name_and_affiliation(name, affiliation)
except QiitaDBLookupError:
self.fail('Person not found', 404)
return
self.write({'address': p.address, 'phone': p.phone,
'email': p.email, 'id': p.id})
self.finish()
else:
arg_name = 'name' if name is None else 'affiliation'
raise MissingArgumentError(arg_name)