Esempio n. 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
Esempio n. 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
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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"
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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"
Esempio n. 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)
Esempio n. 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")
Esempio n. 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")
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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"
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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"
     )
Esempio n. 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
Esempio n. 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
Esempio n. 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")
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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"
Esempio n. 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")
Esempio n. 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!"
Esempio n. 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!"
Esempio n. 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')
Esempio n. 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!"
Esempio n. 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')
Esempio n. 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"