def create_structured_sms_keyword(self, keyword, app_id, form_unique_id, reply_sms, delimiter=None, named_args=None, named_args_separator=None, override_open_sessions=True, initiator_filter=None): k = Keyword( domain=self.domain, keyword=keyword, description=keyword, delimiter=delimiter, override_open_sessions=override_open_sessions, initiator_doc_type_filter=initiator_filter or [], ) k.save() k.keywordaction_set.create( recipient=KeywordAction.RECIPIENT_SENDER, action=KeywordAction.ACTION_SMS, message_content=reply_sms, ) k.keywordaction_set.create( recipient=KeywordAction.RECIPIENT_SENDER, action=KeywordAction.ACTION_STRUCTURED_SMS, app_id=app_id, form_unique_id=form_unique_id, use_named_args=(named_args is not None), named_args=(named_args or {}), named_args_separator=named_args_separator, )
def test_unlink_keywords_in_domain_returns_zero_if_no_linked_keywords(self): keyword = Keyword(domain=self.domain) keyword.save() unlinked_keywords = unlink_keywords_in_domain(self.domain) self.assertEqual(0, len(unlinked_keywords))
def test_unlink_keyword_returns_none_if_not_linked(self): keyword = Keyword() keyword.save() unlinked_keyword = unlink_keyword(keyword) self.assertIsNone(unlinked_keyword)
def create_structured_sms_keyword(self, keyword, form_unique_id, reply_sms, delimiter=None, named_args=None, named_args_separator=None, override_open_sessions=True, initiator_filter=None): k = Keyword( domain=self.domain, keyword=keyword, description=keyword, delimiter=delimiter, override_open_sessions=override_open_sessions, initiator_doc_type_filter=initiator_filter or [], ) k.save() k.keywordaction_set.create( recipient=KeywordAction.RECIPIENT_SENDER, action=KeywordAction.ACTION_SMS, message_content=reply_sms, ) k.keywordaction_set.create( recipient=KeywordAction.RECIPIENT_SENDER, action=KeywordAction.ACTION_STRUCTURED_SMS, form_unique_id=form_unique_id, use_named_args=(named_args is not None), named_args=(named_args or {}), named_args_separator=named_args_separator, )
def test_unlink_keyword_returns_unlinked_keyword(self): keyword = Keyword(upstream_id='abc123') keyword.save() unlinked_keyword = unlink_keyword(keyword) self.assertIsNone(unlinked_keyword.upstream_id) self.assertEqual(keyword.id, unlinked_keyword.id)
class TestLinkedKeywords(BaseLinkedAppsTest): def setUp(self): super(TestLinkedKeywords, self).setUp() module = self.master1.add_module(Module.new_module("M1", None)) master_form = module.new_form( "f1", None, self.get_xml("very_simple_form").decode("utf-8")) self.keyword = Keyword( domain=self.domain_link.master_domain, keyword="ping", description="The description", override_open_sessions=True, ) self.keyword.save() self.keyword.keywordaction_set.create( recipient=KeywordAction.RECIPIENT_SENDER, action=METHOD_SMS, message_content="pong", app_id=self.master1.get_id, form_unique_id=master_form.unique_id, ) def tearDown(self): self.keyword.delete() super(TestLinkedKeywords, self).tearDown() def test_create_keyword_link(self): new_keyword_id = create_linked_keyword(self.domain_link, self.keyword.id) new_keyword = Keyword.objects.get(id=new_keyword_id) self.assertEqual(new_keyword.keyword, self.keyword.keyword) new_keyword_action = new_keyword.keywordaction_set.first() self.assertEqual( new_keyword_action.message_content, self.keyword.keywordaction_set.first().message_content, ) self.assertEqual(new_keyword_action.app_id, self.linked_app.get_id) def test_update_keyword_link(self): new_keyword_id = create_linked_keyword(self.domain_link, self.keyword.id) self.keyword.keyword = "foo" self.keyword.save() keyword_action = self.keyword.keywordaction_set.first() keyword_action.message_content = "bar" keyword_action.save() update_keyword(self.domain_link, new_keyword_id) linked_keyword = Keyword.objects.get(id=new_keyword_id) self.assertEqual(linked_keyword.keyword, "foo") self.assertEqual( linked_keyword.keywordaction_set.first().message_content, "bar")
def test_unlink_keywords_in_domain_successfully_unlinks_keyword(self): keyword = Keyword(domain=self.domain, upstream_id='abc123') keyword.save() unlinked_keywords = unlink_keywords_in_domain(self.domain) self.assertEqual(1, len(unlinked_keywords)) self.assertIsNone(unlinked_keywords[0].upstream_id) self.assertEqual(keyword.id, unlinked_keywords[0].id)
def _create_new_keyword(self, keyword_name): keyword = Keyword( domain=self.domain_link.master_domain, keyword=keyword_name, description="The description", override_open_sessions=True, ) keyword.save() return keyword
def _create_keyword(domain, name="ping", upstream_id=None, should_save=True): keyword = Keyword(domain=domain, keyword=name, description="The description", override_open_sessions=True, upstream_id=upstream_id) if should_save: keyword.save() return keyword
def test_unlink_keywords_in_domain_only_processes_linked_keywords(self): original_keyword = Keyword(domain=self.domain) linked_keyword = Keyword(domain=self.domain, upstream_id='abc123') original_keyword.save() linked_keyword.save() unlinked_keywords = unlink_keywords_in_domain(self.domain) self.assertEqual(1, len(unlinked_keywords)) self.assertIsNone(unlinked_keywords[0].upstream_id) keyword_ids = [keyword.id for keyword in unlinked_keywords] self.assertFalse(original_keyword.id in keyword_ids) self.assertTrue(linked_keyword.id in keyword_ids)
def test_unlink_keywords_in_domain_unlinks_multiple_keywords(self): keyword1 = Keyword(domain=self.domain, upstream_id='abc123') keyword2 = Keyword(domain=self.domain, upstream_id='abc123') keyword1.save() keyword2.save() unlinked_keywords = unlink_keywords_in_domain(self.domain) self.assertEqual(2, len(unlinked_keywords)) self.assertIsNone(unlinked_keywords[0].upstream_id) self.assertIsNone(unlinked_keywords[1].upstream_id) keyword_ids = [keyword.id for keyword in unlinked_keywords] self.assertTrue(keyword1.id in keyword_ids) self.assertTrue(keyword2.id in keyword_ids)
def create_survey_keyword(self, keyword, form_unique_id, delimiter=None, override_open_sessions=True, initiator_filter=None): k = Keyword( domain=self.domain, keyword=keyword, description=keyword, delimiter=delimiter, override_open_sessions=override_open_sessions, initiator_doc_type_filter=initiator_filter or [], ) k.save() k.keywordaction_set.create( recipient=KeywordAction.RECIPIENT_SENDER, action=KeywordAction.ACTION_SMS_SURVEY, form_unique_id=form_unique_id, )
def create_survey_keyword(self, keyword, app_id, form_unique_id, delimiter=None, override_open_sessions=True, initiator_filter=None): k = Keyword( domain=self.domain, keyword=keyword, description=keyword, delimiter=delimiter, override_open_sessions=override_open_sessions, initiator_doc_type_filter=initiator_filter or [], ) k.save() k.keywordaction_set.create( recipient=KeywordAction.RECIPIENT_SENDER, action=KeywordAction.ACTION_SMS_SURVEY, app_id=app_id, form_unique_id=form_unique_id, )
def create_sms_keyword(self, keyword, reply_sms, override_open_sessions=True, initiator_filter=None, recipient=KeywordAction.RECIPIENT_SENDER, recipient_id=None): k = Keyword( domain=self.domain, keyword=keyword, description=keyword, override_open_sessions=override_open_sessions, initiator_doc_type_filter=initiator_filter or [], ) k.save() k.keywordaction_set.create( recipient=recipient, recipient_id=recipient_id, action=KeywordAction.ACTION_SMS, message_content=reply_sms, )
def create_sms_keyword(self, keyword, reply_sms, override_open_sessions=True, initiator_filter=None, recipient=KeywordAction.RECIPIENT_SENDER, recipient_id=None): k = Keyword( domain=self.domain, keyword=keyword, description=keyword, override_open_sessions=override_open_sessions, initiator_doc_type_filter=initiator_filter or [], ) k.save() k.keywordaction_set.create( recipient=recipient, recipient_id=recipient_id, action=KeywordAction.ACTION_SMS, message_content=reply_sms, )
def _create_keyword(domain, name="ping", upstream_id=None, should_save=True, is_grouped=False): keyword = Keyword(domain=domain, keyword=name, description="The description", override_open_sessions=True, upstream_id=upstream_id) if should_save: keyword.save() if is_grouped: keyword.keywordaction_set.create( recipient=KeywordAction.RECIPIENT_USER_GROUP, recipient_id='abc123', action=KeywordAction.ACTION_SMS, message_content='Test', ) return keyword