示例#1
0
 def test_is_blocking_reply(self, recipients):
     msg = InboundSms({
         'From': str(recipients['wesley'].number),
         'Body': 'test'
     })
     reply = msg.construct_reply()
     assert len(reply) == 0
示例#2
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
示例#3
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)
示例#4
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
示例#5
0
    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
示例#6
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"
示例#7
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
示例#8
0
 def test_is_blocking_reply(self, recipients):
     msg = InboundSms({
         "From": str(recipients["wesley"].number),
         "Body": "test"
     })
     reply = msg.construct_reply()
     assert len(reply) == 0
示例#9
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
示例#10
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"
示例#11
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)
示例#12
0
 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")
示例#13
0
 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")
示例#14
0
 def test_is_blocking_reply(self, recipients):
     msg = InboundSms(
         {
             'From': str(recipients['wesley'].number),
             'Body': 'test'
         }
     )
     reply = msg.construct_reply()
     assert len(reply) == 0
示例#15
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
示例#16
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
示例#17
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
示例#18
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
示例#19
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"
示例#20
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)
示例#21
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
示例#22
0
    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
示例#23
0
 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"
     )
示例#24
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
示例#25
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
示例#26
0
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")
示例#27
0
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
示例#28
0
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
示例#29
0
    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
示例#30
0
    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
示例#31
0
    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
示例#32
0
    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
示例#33
0
 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"
示例#34
0
 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")
示例#35
0
 def test_existing_keyword_new_contact(self, keywords):
     msg = InboundSms({"From": "+447927401749", "Body": "test msg"})
     reply = msg.construct_reply()
     assert reply == "Thanks new person!"
示例#36
0
 def test_existing_keyword_new_contact(self, keywords):
     msg = InboundSms({'From': '+447927401749', 'Body': 'test msg'})
     reply = msg.construct_reply()
     assert reply == "Thanks new person!"
示例#37
0
 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')
示例#38
0
 def test_existing_keyword_new_contact(self, keywords):
     msg = InboundSms({'From': '+447927401749', 'Body': 'test msg'})
     reply = msg.construct_reply()
     assert reply == "Thanks new person!"
示例#39
0
 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')
示例#40
0
 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"