Ejemplo 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
Ejemplo 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
Ejemplo 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)
Ejemplo 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
Ejemplo 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
Ejemplo 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"
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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"
Ejemplo 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)
Ejemplo 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")
Ejemplo 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")
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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"
Ejemplo 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)
Ejemplo 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
Ejemplo 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
Ejemplo 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"
     )
Ejemplo 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
Ejemplo 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
Ejemplo 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")
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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"
Ejemplo 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")
Ejemplo 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!"
Ejemplo 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!"
Ejemplo 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')
Ejemplo 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!"
Ejemplo 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')
Ejemplo 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"