本文整理汇总了Python中eums.services.contact_service.ContactService类的典型用法代码示例。如果您正苦于以下问题:Python ContactService类的具体用法?Python ContactService怎么用?Python ContactService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContactService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_contact
def update_contact(runnable):
tree_position = getattr(runnable, 'tree_position', Flow.Label.IMPLEMENTING_PARTNER)
ContactService.update_after_delivery_creation(runnable.contact_person_id,
tree_position,
runnable.programme.name,
runnable.location,
runnable.consignee.name)
示例2: test_should_add_rapid_pro_contact
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)
示例3: test_should_not_update_contact_when_contact_not_modified
def test_should_not_update_contact_when_contact_not_modified(self, update, get):
get.return_value = CONTACT
update.return_value = 200
ContactService.update_after_delivery_creation(CONTACT['_id'], type='End-user',
outcome='YI105 - PCR 1 KEEP CHILDREN AND MOTHERS',
ip='WAKISO DHA', district='Wakiso')
ContactService.get.assert_called_once_with(CONTACT['_id'])
ContactService.update.assert_not_called(CONTACT)
示例4: test_should_add_rapid_pro_contact_called
def test_should_add_rapid_pro_contact_called(self, rapid_pro_contact):
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=CONTACT)))
ContactService.add_or_update_rapid_pro_contact(CONTACT)
self.assertTrue(requests.post.called)
示例5: get
def get(self, request, pk=None):
if pk:
return Response(status=HTTP_200_OK, data=ContactService.get(pk))
created_by_user_id = request.GET.get('createdbyuserid')
if created_by_user_id:
return Response(status=HTTP_200_OK, data=ContactService.get_by_user_id(created_by_user_id))
search_field = request.GET.get('searchfield')
if search_field:
return Response(status=HTTP_200_OK, data=ContactService.search(search_field))
return Response(status=HTTP_200_OK, data=ContactService.get_all())
示例6: test_should_update_rapid_pro_contact_when_phone_not_modified
def test_should_update_rapid_pro_contact_when_phone_not_modified(self, rapid_pro_contact):
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=self.generate_add_or_update_rapid_pro_contact_response(CONTACT))))
new_contact = copy.deepcopy(CONTACT)
new_contact.update({
'prePhone': CONTACT['phone'],
'phone': CONTACT['phone']
})
requests.post = MagicMock(return_value=MagicMock(status_code=200, json=MagicMock(
return_value=new_contact)))
ContactService.add_or_update_rapid_pro_contact(new_contact)
self.assertTrue(requests.post.called)
示例7: generate_build_rapid_pro_contact
def generate_build_rapid_pro_contact(self, contact):
return {
'name': 'Jack Bob',
'groups': [{'name': 'EUMS', 'uuid': '362bcb66-6f2e-4899-b78b-187309bdf636'}],
'urns': ['tel:%s' % contact.get('phone')],
'fields': ContactService.build_rapid_pro_contact_fields(contact)
}
示例8: test_should_delete_contact
def test_should_delete_contact(self):
requests.delete = MagicMock(return_value=MagicMock(status_code=204))
response = ContactService.delete(CONTACT.get('_id'))
requests.delete.assert_called_once_with(url='%s%s' % (settings.CONTACTS_SERVICE_URL, CONTACT['_id']))
self.assertEqual(response, 204)
示例9: test_should_update_contact
def test_should_update_contact(self):
requests.put = MagicMock(return_value=MagicMock(status_code=200, json=MagicMock(return_value=CONTACT)))
response = ContactService.update(CONTACT)
requests.put.assert_called_once_with('%s' % settings.CONTACTS_SERVICE_URL, json.dumps(CONTACT),
headers=HEADER_CONTACT)
self.assertEqual(response, 200)
示例10: test_should_update_rapid_pro_contact_when_phone_modified
def test_should_update_rapid_pro_contact_when_phone_modified(self):
requests.get = MagicMock(return_value=MagicMock(status_code=200, json=MagicMock(
return_value=self.generate_get_rapid_pro_contact_response(CONTACT))))
new_contact = copy.deepcopy(CONTACT)
new_phone = '+8618694029575'
new_contact.update({
'prePhone': CONTACT['phone'],
'phone': new_phone
})
requests.post = MagicMock(return_value=MagicMock(status_code=200, json=MagicMock(
return_value=self.generate_add_or_update_rapid_pro_contact_response(CONTACT))))
logger.info(new_contact)
ContactService.add_or_update_rapid_pro_contact(new_contact)
self.assertTrue(requests.post.called)
示例11: test_should_add_contact
def test_should_add_contact(self):
requests.post = MagicMock(return_value=MagicMock(status_code=201, json=MagicMock(return_value=CONTACT)))
response = ContactService.add(CONTACT)
requests.post.assert_called_once_with('%s' % settings.CONTACTS_SERVICE_URL, json.dumps(CONTACT),
headers=HEADER_CONTACT)
self.assertEqual(response.status_code, 201)
self.assertEqual(response.json(), CONTACT)
示例12: test_should_delete_rapid_pro_contact
def test_should_delete_rapid_pro_contact(self):
phone = '+8618192235667'
url_delete_rapid_pro_contact = '%s?%s' % (settings.RAPIDPRO_URLS.get('CONTACTS'), urlencode({
'urns': 'tel:%s' % phone
}))
requests.delete = MagicMock(return_value=MagicMock(status_code=HTTP_204_NO_CONTENT))
response = ContactService.delete_rapid_pro_contact(phone)
requests.delete.assert_called_once_with(url_delete_rapid_pro_contact, headers=HEADER,
verify=settings.RAPIDPRO_SSL_VERIFY)
self.assertEqual(response.status_code, HTTP_204_NO_CONTENT)
示例13: test_should_get_rapid_pro_contact_group
def test_should_get_rapid_pro_contact_group(self):
group_name = 'EUMS'
requests.get = MagicMock(return_value=MagicMock(status_code=200, json=MagicMock(return_value=
self.generate_rapid_pro_contact_group())))
url_get_rapid_pro_contact_group = '%s?%s' % (settings.RAPIDPRO_URLS.get('GROUPS'), urlencode({
'name': '%s' % group_name
}))
response = ContactService.get_rapid_pro_contact_group(group_name)
requests.get.assert_called_once_with(url_get_rapid_pro_contact_group,
headers=HEADER, verify=settings.RAPIDPRO_SSL_VERIFY)
self.assertEqual(response.get('name'), 'EUMS')
self.assertEqual(response.get('uuid'), '362bcb66-6f2e-4899-b78b-187309bdf636')
示例14: generate_get_rapid_pro_contact_response
def generate_get_rapid_pro_contact_response(self, contact):
return {
"results": [
{
"uuid": "52fa33e7-da32-4703-8feb-aa5114dc1a8b",
"name": "Jack Bob",
"urns": [
"tel:%s" % contact.get('phone')
],
"fields": ContactService.build_rapid_pro_contact_fields(contact)
}
]
}
示例15: generate_add_or_update_rapid_pro_contact_response
def generate_add_or_update_rapid_pro_contact_response(self, contact):
return {
"uuid": "e5de51c0-844b-4feb-8023-33b180bdf965",
"name": "Jack Bob",
"language": None,
"group_uuids": ["fbc775f2-03e3-428e-93a2-608d7a7b46dc"],
"urns": ["tel:%s" % contact.get('phone')],
"fields": ContactService.build_rapid_pro_contact_fields(contact),
"blocked": False,
"failed": False,
"modified_on": "2016-03-07T09:09:46.429Z",
"phone": contact.get('phone'),
"groups": ['EUMS']
}