本文整理汇总了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)