def test_new_conversation_triggers(self, mock_post): mock_post.return_value = MockResponse(200, json.dumps({'success': True})) flow = self.create_flow() trigger = Trigger.create(self.org, self.admin, Trigger.TYPE_NEW_CONVERSATION, flow, self.channel) mock_post.assert_called_once_with('https://graph.facebook.com/v2.6/12345/thread_settings', json={ 'setting_type': 'call_to_actions', 'thread_state': 'new_thread', 'call_to_actions': [{"payload": "get_started"}] }, headers={'Content-Type': 'application/json'}, params={'access_token': '09876543'}) mock_post.reset_mock() trigger.archive(self.admin) mock_post.assert_called_once_with('https://graph.facebook.com/v2.6/12345/thread_settings', json={ 'setting_type': 'call_to_actions', 'thread_state': 'new_thread', 'call_to_actions': [] }, headers={'Content-Type': 'application/json'}, params={'access_token': '09876543'}) mock_post.reset_mock() trigger.restore(self.admin) mock_post.assert_called_once_with('https://graph.facebook.com/v2.6/12345/thread_settings', json={ 'setting_type': 'call_to_actions', 'thread_state': 'new_thread', 'call_to_actions': [{"payload": "get_started"}] }, headers={'Content-Type': 'application/json'}, params={'access_token': '09876543'}) mock_post.reset_mock()
def test_new_conversation_triggers(self): flow = self.create_flow() with patch("requests.post") as mock_post: mock_post.return_value = MockResponse( 200, json.dumps({"success": True})) trigger = Trigger.create(self.org, self.admin, Trigger.TYPE_NEW_CONVERSATION, flow, channel=self.channel) mock_post.assert_called_once_with( "https://graph.facebook.com/v3.3/12345/thread_settings", json={ "setting_type": "call_to_actions", "thread_state": "new_thread", "call_to_actions": [{ "payload": "get_started" }], }, headers={"Content-Type": "application/json"}, params={"access_token": "09876543"}, ) mock_post.reset_mock() trigger.archive(self.admin) mock_post.assert_called_once_with( "https://graph.facebook.com/v3.3/12345/thread_settings", json={ "setting_type": "call_to_actions", "thread_state": "new_thread", "call_to_actions": [] }, headers={"Content-Type": "application/json"}, params={"access_token": "09876543"}, ) mock_post.reset_mock() trigger.restore(self.admin) mock_post.assert_called_once_with( "https://graph.facebook.com/v3.3/12345/thread_settings", json={ "setting_type": "call_to_actions", "thread_state": "new_thread", "call_to_actions": [{ "payload": "get_started" }], }, headers={"Content-Type": "application/json"}, params={"access_token": "09876543"}, ) mock_post.reset_mock()
def test_new_conversation_triggers(self): flow = self.create_flow() with patch("requests.post") as mock_post: mock_post.return_value = MockResponse( 200, json.dumps({"success": True})) trigger = Trigger.create(self.org, self.admin, Trigger.TYPE_NEW_CONVERSATION, flow, channel=self.channel) mock_post.assert_called_once_with( "https://graph.facebook.com/v12.0/me/messenger_profile", json={"get_started": { "payload": "get_started" }}, headers={"Content-Type": "application/json"}, params={"access_token": "09876543"}, ) mock_post.reset_mock() with patch("requests.delete") as mock_post: mock_post.return_value = MockResponse( 200, json.dumps({"success": True})) trigger.archive(self.admin) mock_post.assert_called_once_with( "https://graph.facebook.com/v12.0/me/messenger_profile", json={"fields": ["get_started"]}, headers={"Content-Type": "application/json"}, params={"access_token": "09876543"}, ) mock_post.reset_mock() with patch("requests.post") as mock_post: mock_post.return_value = MockResponse( 200, json.dumps({"success": True})) trigger.restore(self.admin) mock_post.assert_called_once_with( "https://graph.facebook.com/v12.0/me/messenger_profile", json={"get_started": { "payload": "get_started" }}, headers={"Content-Type": "application/json"}, params={"access_token": "09876543"}, ) mock_post.reset_mock()
def test_new_conversation_triggers(self, mock_post): mock_post.return_value = MockResponse(200, json.dumps({"success": True})) flow = self.create_flow() trigger = Trigger.create(self.org, self.admin, Trigger.TYPE_NEW_CONVERSATION, flow, self.channel) mock_post.assert_called_once_with( "https://graph.facebook.com/v2.12/12345/thread_settings", json={ "setting_type": "call_to_actions", "thread_state": "new_thread", "call_to_actions": [{"payload": "get_started"}], }, headers={"Content-Type": "application/json"}, params={"access_token": "09876543"}, ) mock_post.reset_mock() trigger.archive(self.admin) mock_post.assert_called_once_with( "https://graph.facebook.com/v2.12/12345/thread_settings", json={"setting_type": "call_to_actions", "thread_state": "new_thread", "call_to_actions": []}, headers={"Content-Type": "application/json"}, params={"access_token": "09876543"}, ) mock_post.reset_mock() trigger.restore(self.admin) mock_post.assert_called_once_with( "https://graph.facebook.com/v2.12/12345/thread_settings", json={ "setting_type": "call_to_actions", "thread_state": "new_thread", "call_to_actions": [{"payload": "get_started"}], }, headers={"Content-Type": "application/json"}, params={"access_token": "09876543"}, ) mock_post.reset_mock()
def setUpBeforeMigration(self, apps): contact1 = self.create_contact("Bob", twitter="bob") favorites = self.get_flow("favorites") # create schedule attached to a trigger self.trigger = Trigger.create(self.org, self.admin, Trigger.TYPE_SCHEDULE, flow=favorites, schedule=create_schedule( self.admin, "D")) # create schedule attached to a broadcast self.broadcast = Broadcast.create(self.org, self.admin, "hi there", contacts=[contact1], schedule=create_schedule( self.admin, "W")) # create orphan schedule create_schedule(self.admin, "M")