def test_should_return_0_if_no_disaster_everywhere(self):
        location_stats_service = LocationStatsService(location=self.district)
        stats = location_stats_service.aggregate_stats()
        disasters_stats = stats.disasters

        self.assertEqual(0, disasters_stats.count)
        self.assertEqual(0, disasters_stats.percentage)
Ejemplo n.º 2
0
    def test_should_return_0_if_no_disaster_everywhere(self):
        location_stats_service = LocationStatsService(location=self.district)
        stats = location_stats_service.aggregate_stats()
        disasters_stats = stats.disasters

        self.assertEqual(0, disasters_stats.count)
        self.assertEqual(0, disasters_stats.percentage)
Ejemplo n.º 3
0
    def test_should_serialize_location_stats_service_integration(self):
        disaster_type = DisasterType(
            **dict(name='Flood', description="Some flood"))
        disaster_type.save()

        disaster_attr = dict(name=disaster_type,
                             locations=[self.district],
                             description="Big Flood",
                             date="2014-12-01",
                             status="Assessment")

        Disaster(**disaster_attr).save()

        location_stats_service = LocationStatsService(location=self.district)
        queryset = location_stats_service.aggregate_stats()
        serialized_object = LocationStatsSerializer(queryset)
        serialized_data = {
            'messages': {
                'count': 1,
                'percentage': 50,
                'reporter_ratio': 0
            },
            'disasters': {
                'count': 1,
                'percentage': 100,
                'reporter_ratio': 0
            }
        }

        self.assertEqual(serialized_data, serialized_object.data)
    def test_should_return_0_if_location_not_existing(self):
        inexistant_location = None

        location_stats_service = LocationStatsService(location=inexistant_location)
        stats = location_stats_service.aggregate_stats()
        message_stats = stats.messages

        self.assertEqual(0, message_stats.count)
        self.assertEqual(0, message_stats.percentage)
Ejemplo n.º 5
0
    def test_should_return_0_if_location_not_existing(self):
        inexistant_location = None

        location_stats_service = LocationStatsService(
            location=inexistant_location)
        stats = location_stats_service.aggregate_stats()
        message_stats = stats.messages

        self.assertEqual(0, message_stats.count)
        self.assertEqual(0, message_stats.percentage)
Ejemplo n.º 6
0
    def test_should_retrieve_message_count_in_a_location(self):
        Disaster(**self.disaster_attr).save()
        attr2 = self.disaster_attr.copy()
        attr2["status"] = "Closed"
        Disaster(**attr2).save()

        location_stats_service = LocationStatsService(location=self.district)
        stats = location_stats_service.aggregate_stats()
        disasters_stats = stats.disasters

        self.assertEqual(2, disasters_stats.count)
        self.assertEqual(100, disasters_stats.percentage)
Ejemplo n.º 7
0
    def test_should_retrieve_messages_percentage_in_a_location(self):
        RapidProMessage(**self.message).save()
        message1 = self.message.copy()
        message1["text"] = "some message that is not coming from Kampala"
        RapidProMessage(**message1).save()

        location_stats_service = LocationStatsService(location=self.district)
        stats = location_stats_service.aggregate_stats()
        message_stats = stats.messages

        self.assertEqual(1, message_stats.count)
        self.assertEqual(50, message_stats.percentage)
Ejemplo n.º 8
0
    def test_should_retrieve_message_count_in_a_location(self):
        RapidProMessage(**self.message).save()
        message1 = self.message.copy()
        message1["phone_number"] = "12345"
        RapidProMessage(**message1).save()

        location_stats_service = LocationStatsService(location=self.district)
        stats = location_stats_service.aggregate_stats()
        message_stats = stats.messages

        self.assertEqual(2, message_stats.count)
        self.assertEqual(100, message_stats.percentage)
    def test_should_retrieve_disasters_percentage_in_a_location(self):
        Disaster(**self.disaster_attr).save()
        attr2 = self.disaster_attr.copy()
        attr2["locations"] = [Location(**dict(name="Location that is not Kampala", type="district")).save()]
        Disaster(**attr2).save()

        location_stats_service = LocationStatsService(location=self.district)
        stats = location_stats_service.aggregate_stats()
        disasters_stats = stats.disasters

        self.assertEqual(1, disasters_stats.count)
        self.assertEqual(50, disasters_stats.percentage)
    def test_should_retrieve_message_count_in_a_location(self):
        Disaster(**self.disaster_attr).save()
        attr2 = self.disaster_attr.copy()
        attr2["status"] = "Closed"
        Disaster(**attr2).save()

        location_stats_service = LocationStatsService(location=self.district)
        stats = location_stats_service.aggregate_stats()
        disasters_stats = stats.disasters

        self.assertEqual(2, disasters_stats.count)
        self.assertEqual(100, disasters_stats.percentage)
    def test_should_retrieve_messages_percentage_in_a_location(self):
        RapidProMessage(**self.message).save()
        message1 = self.message.copy()
        message1["text"] = "some message that is not coming from Kampala"
        RapidProMessage(**message1).save()

        location_stats_service = LocationStatsService(location=self.district)
        stats = location_stats_service.aggregate_stats()
        message_stats = stats.messages

        self.assertEqual(1, message_stats.count)
        self.assertEqual(50, message_stats.percentage)
    def test_should_retrieve_message_count_in_a_location(self):
        RapidProMessage(**self.message).save()
        message1 = self.message.copy()
        message1["phone_number"] = "12345"
        RapidProMessage(**message1).save()

        location_stats_service = LocationStatsService(location=self.district)
        stats = location_stats_service.aggregate_stats()
        message_stats = stats.messages

        self.assertEqual(2, message_stats.count)
        self.assertEqual(100, message_stats.percentage)
Ejemplo n.º 13
0
    def test_should_retrieve_disasters_percentage_in_a_location(self):
        Disaster(**self.disaster_attr).save()
        attr2 = self.disaster_attr.copy()
        attr2["locations"] = [
            Location(**dict(name='Location that is not Kampala',
                            type='district')).save()
        ]
        Disaster(**attr2).save()

        location_stats_service = LocationStatsService(location=self.district)
        stats = location_stats_service.aggregate_stats()
        disasters_stats = stats.disasters

        self.assertEqual(1, disasters_stats.count)
        self.assertEqual(50, disasters_stats.percentage)
    def test_should_serialize_location_stats_service_integration(self):
        disaster_type = DisasterType(**dict(name='Flood', description="Some flood"))
        disaster_type.save()

        disaster_attr = dict(name=disaster_type, locations=[self.district], description="Big Flood", date="2014-12-01",
                             status="Assessment")

        Disaster(**disaster_attr).save()

        location_stats_service = LocationStatsService(location=self.district)
        queryset = location_stats_service.aggregate_stats()
        serialized_object = LocationStatsSerializer(queryset)
        serialized_data = {'messages': {'count': 1, 'percentage': 50, 'reporter_ratio': 0},
                           'disasters': {'count': 1, 'percentage': 100, 'reporter_ratio': 0}}

        self.assertEqual(serialized_data, serialized_object.data)