def test_is_blocking_reply(self, recipients): msg = InboundSms({ 'From': str(recipients['wesley'].number), 'Body': 'test' }) reply = msg.construct_reply() assert len(reply) == 0
def test_do_not_reply(self, recipients): msg = InboundSms({ 'From': str(recipients['beza'].number), 'Body': 'test' }) reply = msg.construct_reply() assert len(reply) == 0
def test_name(self, recipients): msg = InboundSms({ 'From': str(recipients['calvin'].number), 'Body': 'name John Calvin' }) reply = msg.construct_reply() assert "John" in str(reply)
def test_only_one_name(self, recipients): msg = InboundSms({ 'From': str(recipients['calvin'].number), 'Body': 'name JohnCalvin' }) reply = msg.construct_reply() assert "Something went wrong" in reply
def test_contact_added_to_group_keyword( self, recipients, groups, keywords ): populated_group = groups['test_group'] empty_group = groups['empty_group'] assert empty_group.recipient_set.count() == 0 assert populated_group.recipient_set.count() == 2 test_keyword = keywords['test'] test_keyword.linked_groups.add(empty_group, populated_group) test_keyword.save() msg = InboundSms( { 'From': str(recipients['beza'].number), 'Body': 'test' } ) reply = msg.construct_reply() grp1 = RecipientGroup.objects.get(name='Empty Group') assert grp1.recipient_set.all().count() == 1 grp2 = RecipientGroup.objects.get(name='Test Group') assert grp2.recipient_set.all().count() == 3 # let's repeat to test case where contact already in group: reply = msg.construct_reply() grp = RecipientGroup.objects.get(name='Empty Group') assert grp.recipient_set.count() == 1
def test_existing_keyword(self, recipients, keywords): msg = InboundSms({ 'From': str(recipients['calvin'].number), 'Body': 'test msg' }) reply = msg.construct_reply() assert reply == "Test custom response with John"
def test_only_one_name(self, recipients): msg = InboundSms({ "From": str(recipients["calvin"].number), "Body": "name JohnCalvin" }) reply = msg.construct_reply() assert "Something went wrong" in reply
def test_is_blocking_reply(self, recipients): msg = InboundSms({ "From": str(recipients["wesley"].number), "Body": "test" }) reply = msg.construct_reply() assert len(reply) == 0
def test_do_not_reply(self, recipients): msg = InboundSms({ "From": str(recipients["beza"].number), "Body": "test" }) reply = msg.construct_reply() assert len(reply) == 0
def test_existing_keyword(self, recipients, keywords): msg = InboundSms({ "From": str(recipients["calvin"].number), "Body": "test msg" }) reply = msg.construct_reply() assert reply == "Test custom response with John"
def test_name(self, recipients): msg = InboundSms({ "From": str(recipients["calvin"].number), "Body": "name John Calvin" }) reply = msg.construct_reply() assert "John" in str(reply)
def test_no_existing_keyword(self, recipients): msg = InboundSms({ "From": str(recipients["calvin"].number), "Body": "nope" }) reply = msg.construct_reply() assert reply == fetch_default_reply("keyword_no_match").replace( "%name%", "John")
def test_no_existing_keyword(self, recipients): msg = InboundSms({ 'From': str(recipients['calvin'].number), 'Body': 'nope' }) reply = msg.construct_reply() assert reply == fetch_default_reply('keyword_no_match').replace( "%name%", "John")
def test_is_blocking_reply(self, recipients): msg = InboundSms( { 'From': str(recipients['wesley'].number), 'Body': 'test' } ) reply = msg.construct_reply() assert len(reply) == 0
def test_name_never_contact(self, recipients): recipients["beza"].never_contact = True recipients["beza"].save() msg = InboundSms({ "From": str(recipients["beza"].number), "Body": "name" }) reply = msg.construct_reply() assert len(reply) == 0
def test_switch_off_no_keyword_reply(self, recipients): from site_config.models import DefaultResponses dr = DefaultResponses.get_solo() dr.keyword_no_match = '' dr.clean() dr.save() msg = InboundSms({'From': str(recipients['calvin'].number), 'Body': 'test'}) reply = msg.construct_reply() assert len(reply) == 0
def test_do_not_reply(self, recipients): msg = InboundSms( { 'From': str(recipients['beza'].number), 'Body': 'test' } ) reply = msg.construct_reply() assert len(reply) == 0
def test_only_one_name(self, recipients): msg = InboundSms( { 'From': str(recipients['calvin'].number), 'Body': 'name JohnCalvin' } ) reply = msg.construct_reply() assert "Something went wrong" in reply
def test_existing_keyword(self, recipients, keywords): msg = InboundSms( { 'From': str(recipients['calvin'].number), 'Body': 'test msg' } ) reply = msg.construct_reply() assert reply == "Test custom response with John"
def test_name(self, recipients): msg = InboundSms( { 'From': str(recipients['calvin'].number), 'Body': 'name John Calvin' } ) reply = msg.construct_reply() assert "John" in str(reply)
def test_stop_start(self, recipients): msg = InboundSms({'From': str(recipients['calvin'].number), 'Body': 'stop '}) reply = msg.construct_reply() assert len(reply) == 0 assert Recipient.objects.get(pk=recipients['calvin'].pk).is_blocking msg = InboundSms({'From': str(recipients['calvin'].number), 'Body': 'start '}) reply = msg.construct_reply() assert Recipient.objects.get(pk=recipients['calvin'].pk).is_blocking is False assert 'signing up' in reply
def test_no_existing_keyword(self, recipients): msg = InboundSms( { 'From': str(recipients['calvin'].number), 'Body': 'nope' } ) reply = msg.construct_reply() assert reply == fetch_default_reply('keyword_no_match').replace( "%name%", "John" )
def test_switch_off_no_keyword_reply(self, recipients): from site_config.models import DefaultResponses dr = DefaultResponses.get_solo() dr.keyword_no_match = "" dr.clean() dr.save() msg = InboundSms({ "From": str(recipients["calvin"].number), "Body": "test" }) reply = msg.construct_reply() assert len(reply) == 0
def sms(request): """ Handle all incoming messages from Twilio. This is the start of the message processing pipeline. """ r = twiml.Response() msg = InboundSms(request.POST) msg.start_bg_tasks() config = SiteConfiguration.get_solo() if not config.disable_all_replies: r.message(msg.reply) return r
def sms(request): """ Handle all incoming messages from Twilio. This is the start of the message processing pipeline. """ logger.info("Received new sms") r = MessagingResponse() msg = InboundSms(request.POST) msg.start_bg_tasks() config = SiteConfiguration.get_solo() if msg.reply and not config.disable_all_replies: logger.info("Add reply (%s) to response", msg.reply) r.message(msg.reply) logger.info("Return response to Twilio") return HttpResponse(str(r), content_type="application/xml")
def sms(request): """ Handle all incoming messages from Twilio. This is the start of the message processing pipeline. """ logger.info('Received new sms') r = twiml.Response() msg = InboundSms(request.POST) msg.start_bg_tasks() config = SiteConfiguration.get_solo() if msg.reply and not config.disable_all_replies: logger.info('Add reply (%s) to response', msg.reply) r.message(msg.reply) logger.info('Return response to Twilio') return r
def test_contact_added_to_group_keyword(self, recipients, groups, keywords): populated_group = groups['test_group'] empty_group = groups['empty_group'] assert empty_group.recipient_set.count() == 0 assert populated_group.recipient_set.count() == 2 test_keyword = keywords['test'] test_keyword.linked_groups.add(empty_group, populated_group) test_keyword.save() msg = InboundSms({'From': str(recipients['beza'].number), 'Body': 'test'}) reply = msg.construct_reply() grp1 = RecipientGroup.objects.get(name='Empty Group') assert grp1.recipient_set.all().count() == 1 grp2 = RecipientGroup.objects.get(name='Test Group') assert grp2.recipient_set.all().count() == 3 # let's repeat to test case where contact already in group: reply = msg.construct_reply() grp = RecipientGroup.objects.get(name='Empty Group') assert grp.recipient_set.count() == 1
def test_contact_added_to_group_keyword(self, recipients, groups, keywords): populated_group = groups["test_group"] empty_group = groups["empty_group"] assert empty_group.recipient_set.count() == 0 assert populated_group.recipient_set.count() == 2 test_keyword = keywords["test"] test_keyword.linked_groups.add(empty_group, populated_group) test_keyword.save() msg = InboundSms({ "From": str(recipients["beza"].number), "Body": "test" }) reply = msg.construct_reply() grp1 = RecipientGroup.objects.get(name="Empty Group") assert grp1.recipient_set.all().count() == 1 grp2 = RecipientGroup.objects.get(name="Test Group") assert grp2.recipient_set.all().count() == 3 # let's repeat to test case where contact already in group: reply = msg.construct_reply() grp = RecipientGroup.objects.get(name="Empty Group") assert grp.recipient_set.count() == 1
def test_stop_start(self, recipients): msg = InboundSms({ "From": str(recipients["calvin"].number), "Body": "stop " }) reply = msg.construct_reply() assert len(reply) == 0 assert Recipient.objects.get(pk=recipients["calvin"].pk).is_blocking msg = InboundSms({ "From": str(recipients["calvin"].number), "Body": "start " }) reply = msg.construct_reply() assert Recipient.objects.get( pk=recipients["calvin"].pk).is_blocking is False assert "signing up" in reply
def test_existing_keyword_new_contact(self, keywords): msg = InboundSms({'From': '+447927401749', 'Body': 'test msg'}) reply = msg.construct_reply() assert reply == "Test custom response with Unknown"
def test_existing_keyword_new_contact(self, keywords): msg = InboundSms({"From": "+447927401749", "Body": "2test msg"}) reply = msg.construct_reply() assert reply == fetch_default_reply( "default_no_keyword_auto_reply").replace("%name%", "Unknown")
def test_existing_keyword_new_contact(self, keywords): msg = InboundSms({"From": "+447927401749", "Body": "test msg"}) reply = msg.construct_reply() assert reply == "Thanks new person!"
def test_existing_keyword_new_contact(self, keywords): msg = InboundSms({'From': '+447927401749', 'Body': 'test msg'}) reply = msg.construct_reply() assert reply == "Thanks new person!"
def test_existing_keyword_new_contact(self, keywords): msg = InboundSms({'From': '+447927401749', 'Body': '2test msg'}) reply = msg.construct_reply() assert reply == fetch_default_reply( 'default_no_keyword_auto_reply').replace('%name%', 'Unknown')
def test_existing_keyword_new_contact(self, keywords): msg = InboundSms({'From': '+447927401749', 'Body': '2test msg'}) reply = msg.construct_reply() assert reply == fetch_default_reply('default_no_keyword_auto_reply').replace('%name%', 'Unknown')