Exemple #1
0
    def test_messages_by_from_and_to_date_and_location_when_initial_queryset_is_empty(
            self):
        location_name = 'Abim'
        district = Location(
            **dict(name=location_name, parent=None, type='district')).save()
        message_attr = self.message.copy()
        message_attr['location'] = district
        message_attr['received_at'] = datetime.datetime(
            2014, 12, 17, 16, 0, 49, 807000)
        message = RapidProMessageBase(**message_attr).save()

        self.message['location'] = district
        message1 = RapidProMessageBase(**self.message).save()

        location_messages = RapidProMessageBase.from_(
            district, **{
                'from': '2014-09-17',
                'to': '2014-10-17'
            })

        self.assertEqual(1, location_messages.count())
        self.assertIn(message1, location_messages)
        self.assertNotIn(message, location_messages)

        empty_queryset = RapidProMessageBase.objects().none()

        location_messages = RapidProMessageBase.from_(
            district, empty_queryset, **{
                'from': '2014-09-17',
                'to': '2014-10-17'
            })

        self.assertEqual(0, location_messages.count())
Exemple #2
0
    def test_get_messages_given_from_date_and_to_date(self):
        location_name = 'Abim'
        district = Location(
            **dict(name=location_name, parent=None, type='district')).save()
        message_attr = self.message.copy()
        message_attr['location'] = district
        message_attr['received_at'] = datetime.datetime(
            2014, 12, 17, 16, 0, 49, 807000)
        message = RapidProMessageBase(**message_attr).save()

        self.message['location'] = district
        message1 = RapidProMessageBase(**self.message).save()

        location_messages = RapidProMessageBase.from_(
            district, **{
                'from': '2014-09-17',
                'to': '2014-10-17'
            })

        self.assertEqual(1, location_messages.count())
        self.assertIn(message1, location_messages)
        self.assertNotIn(message, location_messages)

        location_messages = RapidProMessageBase.from_(
            district, **{
                'from': None,
                'to': None
            })
        self.assertEqual(2, location_messages.count())
Exemple #3
0
    def test_international_sign_is_stripped_from_phone_number_to_identify_mobile_user(
            self):
        message_attr = self.message.copy()
        message_attr['phone_no'] = '00' + self.mobile_user.phone
        rapid_pro_message = RapidProMessageBase(**message_attr)

        self.assertEqual(self.mobile_user, rapid_pro_message.mobile_user())
    def test_message_location_str_returns_the_to_str_of_its_location(self):
        message = self.message.copy()
        message['location'] = self.village

        rapid_pro_message = RapidProMessageBase(**message).save()

        self.assertEqual("Kampala >> Bukoto", rapid_pro_message.location_str())
Exemple #5
0
    def test_message_location_str_returns_the_to_str_of_its_location(self):
        message = self.message.copy()
        message['location'] = self.village

        rapid_pro_message = RapidProMessageBase(**message).save()

        self.assertEqual("Kampala >> Bukoto", rapid_pro_message.location_str())
Exemple #6
0
    def test_get_messages_from_a_location(self):
        location_name = 'Abim'
        district = Location(
            **dict(name=location_name, parent=None, type='district')).save()
        message_attr = self.message.copy()
        message_attr['location'] = district
        message = RapidProMessageBase(**message_attr).save()
        message1 = RapidProMessageBase(**self.message).save()

        location_messages = RapidProMessageBase.from_(district)

        self.assertEqual(1, location_messages.count())
        self.assertIn(message, location_messages)
        self.assertNotIn(message1, location_messages)
Exemple #7
0
 def test_fields(self):
     expected_fields = [
         'text', 'created_at', 'phone_no', 'received_at', 'location'
     ]
     rapidpro_message = RapidProMessageBase()
     for field in expected_fields:
         self.assertTrue(hasattr(rapidpro_message, field))
    def test_get_message_count_given_from_and_to_date(self):
        message_attr = self.message.copy()
        message_attr['received_at'] = datetime.datetime(2014, 11, 17, 16, 0, 49, 807000)
        RapidProMessageBase(**message_attr).save()
        RapidProMessageBase(**self.message).save()

        location_messages_count = RapidProMessageBase.count_(**{'from': '2014-09-17', 'to': '2014-10-17'})
        self.assertEqual(1, location_messages_count)

        location_messages_count = RapidProMessageBase.count_(**{'from': '2014-08-17', 'to': '2014-12-17'})
        self.assertEqual(2, location_messages_count)

        location_messages_count = RapidProMessageBase.count_(**{'from': '2014-08-17'})
        self.assertEqual(2, location_messages_count)

        location_messages_count = RapidProMessageBase.count_(**{'from': None, 'to': None})
        self.assertEqual(2, location_messages_count)
    def test_get_messages_given_from_date_and_to_date(self):
        location_name = 'Abim'
        district = Location(**dict(name=location_name, parent=None, type='district')).save()
        message_attr = self.message.copy()
        message_attr['location'] = district
        message_attr['received_at'] = datetime.datetime(2014, 12, 17, 16, 0, 49, 807000)
        message = RapidProMessageBase(**message_attr).save()

        self.message['location'] = district
        message1 = RapidProMessageBase(**self.message).save()

        location_messages = RapidProMessageBase.from_(district, **{'from': '2014-09-17', 'to': '2014-10-17'})

        self.assertEqual(1, location_messages.count())
        self.assertIn(message1, location_messages)
        self.assertNotIn(message, location_messages)

        location_messages = RapidProMessageBase.from_(district, **{'from': None, 'to': None})
        self.assertEqual(2, location_messages.count())
Exemple #10
0
    def test_get_messages_from_children_are_also_added(self):
        location_name = 'Abim'
        district = Location(
            **dict(name=location_name, parent=None, type='district')).save()
        message_attr = self.message.copy()
        message_attr['location'] = district
        message = RapidProMessageBase(**message_attr).save()

        message1_attr = message_attr.copy()
        location_name = 'Wakiso'
        district_son = Location(**dict(
            name=location_name, parent=district, type='village')).save()
        message1_attr["location"] = district_son
        message1 = RapidProMessageBase(**message1_attr).save()

        location_messages = RapidProMessageBase.from_(district)

        self.assertEqual(2, location_messages.count())
        self.assertIn(message, location_messages)
        self.assertIn(message1, location_messages)
Exemple #11
0
    def test_get_message_count_given_from_and_to_date(self):
        message_attr = self.message.copy()
        message_attr['received_at'] = datetime.datetime(
            2014, 11, 17, 16, 0, 49, 807000)
        RapidProMessageBase(**message_attr).save()
        RapidProMessageBase(**self.message).save()

        location_messages_count = RapidProMessageBase.count_(**{
            'from': '2014-09-17',
            'to': '2014-10-17'
        })
        self.assertEqual(1, location_messages_count)

        location_messages_count = RapidProMessageBase.count_(**{
            'from': '2014-08-17',
            'to': '2014-12-17'
        })
        self.assertEqual(2, location_messages_count)

        location_messages_count = RapidProMessageBase.count_(
            **{'from': '2014-08-17'})
        self.assertEqual(2, location_messages_count)

        location_messages_count = RapidProMessageBase.count_(**{
            'from': None,
            'to': None
        })
        self.assertEqual(2, location_messages_count)
    def test_get_messages_from_a_location(self):
        location_name = 'Abim'
        district = Location(**dict(name=location_name, parent=None, type='district')).save()
        message_attr = self.message.copy()
        message_attr['location'] = district
        message = RapidProMessageBase(**message_attr).save()
        message1 = RapidProMessageBase(**self.message).save()

        location_messages = RapidProMessageBase.from_(district)

        self.assertEqual(1, location_messages.count())
        self.assertIn(message, location_messages)
        self.assertNotIn(message1, location_messages)
    def test_messages_by_from_and_to_date_and_location_when_initial_queryset_is_empty(self):
        location_name = 'Abim'
        district = Location(**dict(name=location_name, parent=None, type='district')).save()
        message_attr = self.message.copy()
        message_attr['location'] = district
        message_attr['received_at'] = datetime.datetime(2014, 12, 17, 16, 0, 49, 807000)
        message = RapidProMessageBase(**message_attr).save()

        self.message['location'] = district
        message1 = RapidProMessageBase(**self.message).save()

        location_messages = RapidProMessageBase.from_(district, **{'from': '2014-09-17', 'to': '2014-10-17'})

        self.assertEqual(1, location_messages.count())
        self.assertIn(message1, location_messages)
        self.assertNotIn(message, location_messages)

        empty_queryset = RapidProMessageBase.objects().none()

        location_messages = RapidProMessageBase.from_(district, empty_queryset, **{'from': '2014-09-17', 'to': '2014-10-17'})

        self.assertEqual(0, location_messages.count())
    def test_get_messages_from_children_are_also_added(self):
        location_name = 'Abim'
        district = Location(**dict(name=location_name, parent=None, type='district')).save()
        message_attr = self.message.copy()
        message_attr['location'] = district
        message = RapidProMessageBase(**message_attr).save()

        message1_attr = message_attr.copy()
        location_name = 'Wakiso'
        district_son = Location(**dict(name=location_name, parent=district, type='village')).save()
        message1_attr["location"] = district_son
        message1 = RapidProMessageBase(**message1_attr).save()

        location_messages = RapidProMessageBase.from_(district)

        self.assertEqual(2, location_messages.count())
        self.assertIn(message, location_messages)
        self.assertIn(message1, location_messages)
    def test_save_rapid_pro_message(self):

        RapidProMessageBase(**self.message).save()
        rp_messages = RapidProMessageBase.objects(**self.message)
        self.assertEqual(1, rp_messages.count())
    def test_message_knows_its_mobile_user(self):
        rapid_pro_message = RapidProMessageBase(**self.message)

        self.assertEqual(self.mobile_user, rapid_pro_message.mobile_user())
Exemple #17
0
    def test_message_location_str_is_empty_if_no_location(self):
        rapid_pro_message = RapidProMessageBase(**self.message).save()

        self.assertEqual("", rapid_pro_message.location_str())
    def test_international_sign_is_stripped_from_phone_number_to_identify_mobile_user(self):
        message_attr = self.message.copy()
        message_attr['phone_no'] = '00' + self.mobile_user.phone
        rapid_pro_message = RapidProMessageBase(**message_attr)

        self.assertEqual(self.mobile_user, rapid_pro_message.mobile_user())
    def test_message_location_str_is_empty_if_no_location(self):
        rapid_pro_message = RapidProMessageBase(**self.message).save()

        self.assertEqual("", rapid_pro_message.location_str())
Exemple #20
0
    def test_message_knows_its_mobile_user(self):
        rapid_pro_message = RapidProMessageBase(**self.message)

        self.assertEqual(self.mobile_user, rapid_pro_message.mobile_user())
Exemple #21
0
    def test_message_source(self):
        rapid_pro_message = RapidProMessageBase(**self.message)

        self.assertEqual('NECOC Volunteer', rapid_pro_message.source())
Exemple #22
0
    def test_save_rapid_pro_message(self):

        RapidProMessageBase(**self.message).save()
        rp_messages = RapidProMessageBase.objects(**self.message)
        self.assertEqual(1, rp_messages.count())
    def test_message_source(self):
        rapid_pro_message = RapidProMessageBase(**self.message)

        self.assertEqual('NECOC Volunteer', rapid_pro_message.source())