本文整理汇总了Python中eums.services.contact_service.ContactService.build_rapid_pro_contact方法的典型用法代码示例。如果您正苦于以下问题:Python ContactService.build_rapid_pro_contact方法的具体用法?Python ContactService.build_rapid_pro_contact怎么用?Python ContactService.build_rapid_pro_contact使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eums.services.contact_service.ContactService
的用法示例。
在下文中一共展示了ContactService.build_rapid_pro_contact方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_should_add_rapid_pro_contact
# 需要导入模块: from eums.services.contact_service import ContactService [as 别名]
# 或者: from eums.services.contact_service.ContactService import build_rapid_pro_contact [as 别名]
def test_should_add_rapid_pro_contact(self, rapid_pro_contact):
first_name = "Jack"
last_name = "Bob"
phone = '+8618192235667'
outcomes = ["YI105 - PCR 1 KEEP CHILDREN AND MOTHERS"]
districts = ["Kampala"]
ips = ["KAMPALA DHO, WAKISO DHO"]
types = ["END_USER", "IMPLEMENTING_PARTNER"]
contact = self.generate_eums_contact(districts, first_name, ips, last_name, outcomes, phone, types)
rapid_pro_contact.return_value = self.generate_build_rapid_pro_contact(contact)
requests.get = MagicMock(return_value=MagicMock(status_code=200, json=MagicMock(
return_value={'results': []}
)))
requests.post = MagicMock(return_value=MagicMock(status_code=200, json=MagicMock(
return_value=self.generate_add_or_update_rapid_pro_contact_response(contact))))
response = ContactService.add_or_update_rapid_pro_contact(contact)
self.assertEqual(response.status_code, HTTP_200_OK)
self.assertEqual(len(response.json().get('groups')), 1)
self.assertEqual(response.json().get('groups')[0], 'EUMS')
fields = response.json().get("fields")
self.assertEqual(fields.get('firstname'), first_name)
self.assertEqual(fields.get('lastname'), last_name)
self.assertEqual(fields.get('outcomes'), ','.join(outcomes))
self.assertEqual(fields.get('districts'), ','.join(districts))
self.assertEqual(fields.get('ips'), ','.join(ips))
self.assertEqual(fields.get('types'), ','.join(["End-user", "IP"]))
requests.post.assert_called_once_with(settings.RAPIDPRO_URLS.get('CONTACTS'),
data=json.dumps(ContactService.build_rapid_pro_contact(contact)),
headers=HEADER,
verify=settings.RAPIDPRO_SSL_VERIFY)