Example #1
0
    def test_contact_ward_field(self):

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), dict())
        Contact.objects.create(
            uuid="C-007",
            org=self.nigeria,
            gender="M",
            born=1990,
            occupation="Student",
            registered_on=json_date_to_datetime("2014-01-02T03:04:05.000"),
            state="R-LAGOS",
            district="R-OYO",
            ward="R-IKEJA",
        )
        field_count = ReportersCounter.get_counts(self.nigeria)

        self.assertEqual(field_count["ward:R-IKEJA"], 1)

        Contact.objects.create(
            uuid="C-008",
            org=self.nigeria,
            gender="M",
            born=1980,
            occupation="Teacher",
            registered_on=json_date_to_datetime("2014-01-02T03:07:05.000"),
            state="R-LAGOS",
            district="R-OYO",
            ward="R-IKEJA",
        )

        field_count = ReportersCounter.get_counts(self.nigeria)
        self.assertEqual(field_count["ward:R-IKEJA"], 2)
        Contact.objects.all().delete()
Example #2
0
    def test_contact_ward_field(self):

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), dict())
        Contact.objects.create(
            uuid='C-007',
            org=self.nigeria,
            gender='M',
            born=1990,
            occupation='Student',
            registered_on=json_date_to_datetime('2014-01-02T03:04:05.000'),
            state='R-LAGOS',
            district='R-OYO',
            ward='R-IKEJA')
        field_count = ReportersCounter.get_counts(self.nigeria)

        self.assertEqual(field_count['ward:R-IKEJA'], 1)

        Contact.objects.create(
            uuid='C-008',
            org=self.nigeria,
            gender='M',
            born=1980,
            occupation='Teacher',
            registered_on=json_date_to_datetime('2014-01-02T03:07:05.000'),
            state='R-LAGOS',
            district='R-OYO',
            ward='R-IKEJA')

        field_count = ReportersCounter.get_counts(self.nigeria)
        self.assertEqual(field_count['ward:R-IKEJA'], 2)
        Contact.objects.all().delete()
Example #3
0
    def test_contact_ward_field(self):

        temba_contact = TembaContact.create(uuid='C-0011', name="Jan", urns=['tel:123'],
                                            groups=['G-001', 'G-007'],
                                            fields={'registration_date': '2014-01-02T03:04:05.000000Z', 'state':'Lagos',
                                                    'lga': '', 'ward': 'Ikeja', 'occupation': 'Student', 'born': '1990',
                                                    'gender': 'Male'},
                                            language='eng')

        kwargs = Contact.kwargs_from_temba(self.nigeria, temba_contact)
        # invalid parent boundary (district) will yield empty ward
        self.assertEqual(kwargs, dict(uuid='C-0011', org=self.nigeria, gender='M', born=1990, occupation='Student',
                                      registered_on=json_date_to_datetime('2014-01-02T03:04:05.000'), state='R-LAGOS',
                                      district='', ward=''))

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), dict())
        Contact.objects.create(uuid='C-007', org=self.nigeria, gender='M', born=1990, occupation='Student',
                               registered_on=json_date_to_datetime('2014-01-02T03:04:05.000'), state='R-LAGOS',
                               district='R-OYO', ward='R-IKEJA')
        field_count = ReportersCounter.get_counts(self.nigeria)

        self.assertEqual(field_count['ward:R-IKEJA'], 1)

        Contact.objects.create(uuid='C-008', org=self.nigeria, gender='M', born=1980, occupation='Teacher',
                               registered_on=json_date_to_datetime('2014-01-02T03:07:05.000'), state='R-LAGOS',
                               district='R-OYO', ward='R-IKEJA')

        field_count = ReportersCounter.get_counts(self.nigeria)
        self.assertEqual(field_count['ward:R-IKEJA'], 2)
        Contact.objects.all().delete()
Example #4
0
    def test_reporters_counter(self):
        self.assertEqual(ReportersCounter.get_counts(self.nigeria), dict())
        Contact.objects.create(uuid='C-007', org=self.nigeria, gender='M', born=1990, occupation='Student',
                               registered_on=json_date_to_datetime('2014-01-02T03:04:05.000'), state='R-LAGOS',
                               district='R-OYO')

        expected = dict()
        expected['total-reporters'] = 1
        expected['gender:m'] = 1
        expected['occupation:student'] = 1
        expected['born:1990'] = 1
        expected['registered_on:2014-01-02'] = 1
        expected['state:R-LAGOS'] = 1
        expected['district:R-OYO'] = 1

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), expected)

        Contact.objects.create(uuid='C-008', org=self.nigeria, gender='M', born=1980, occupation='Teacher',
                               registered_on=json_date_to_datetime('2014-01-02T03:07:05.000'), state='R-LAGOS',
                               district='R-OYO')

        expected = dict()
        expected['total-reporters'] = 2
        expected['gender:m'] = 2
        expected['occupation:student'] = 1
        expected['occupation:teacher'] = 1
        expected['born:1990'] = 1
        expected['born:1980'] = 1
        expected['registered_on:2014-01-02'] = 2
        expected['state:R-LAGOS'] = 2
        expected['district:R-OYO'] = 2

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), expected)
Example #5
0
    def test_contact_ward_field(self):

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), dict())
        Contact.objects.create(
            uuid="C-007",
            org=self.nigeria,
            gender="M",
            born=1990,
            occupation="Student",
            registered_on=json_date_to_datetime("2014-01-02T03:04:05.000"),
            state="R-LAGOS",
            district="R-OYO",
            ward="R-IKEJA",
        )
        field_count = ReportersCounter.get_counts(self.nigeria)

        self.assertEqual(field_count["ward:R-IKEJA"], 1)

        Contact.objects.create(
            uuid="C-008",
            org=self.nigeria,
            gender="M",
            born=1980,
            occupation="Teacher",
            registered_on=json_date_to_datetime("2014-01-02T03:07:05.000"),
            state="R-LAGOS",
            district="R-OYO",
            ward="R-IKEJA",
        )

        field_count = ReportersCounter.get_counts(self.nigeria)
        self.assertEqual(field_count["ward:R-IKEJA"], 2)
        Contact.objects.all().delete()
Example #6
0
    def test_reporters_counter(self):
        self.assertEqual(ReportersCounter.get_counts(self.nigeria), dict())
        Contact.objects.create(
            uuid='C-007',
            org=self.nigeria,
            gender='M',
            born=1990,
            occupation='Student',
            registered_on=json_date_to_datetime('2014-01-02T03:04:05.000'),
            state='R-LAGOS',
            district='R-OYO')

        expected = dict()
        expected['total-reporters'] = 1
        expected['gender:m'] = 1
        expected['occupation:student'] = 1
        expected['born:1990'] = 1
        expected['registered_on:2014-01-02'] = 1
        expected['state:R-LAGOS'] = 1
        expected['district:R-OYO'] = 1

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), expected)

        Contact.objects.create(
            uuid='C-008',
            org=self.nigeria,
            gender='M',
            born=1980,
            occupation='Teacher',
            registered_on=json_date_to_datetime('2014-01-02T03:07:05.000'),
            state='R-LAGOS',
            district='R-OYO')

        expected = dict()
        expected['total-reporters'] = 2
        expected['gender:m'] = 2
        expected['occupation:student'] = 1
        expected['occupation:teacher'] = 1
        expected['born:1990'] = 1
        expected['born:1980'] = 1
        expected['registered_on:2014-01-02'] = 2
        expected['state:R-LAGOS'] = 2
        expected['district:R-OYO'] = 2

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), expected)

        self.assertEqual(
            ReportersCounter.get_counts(self.nigeria,
                                        ['total-reporters', 'gender:m']), {
                                            'total-reporters': 2,
                                            'gender:m': 2
                                        })
Example #7
0
    def test_reporters_counter(self):
        self.assertEqual(ReportersCounter.get_counts(self.nigeria), dict())
        Contact.objects.create(
            uuid="C-007",
            org=self.nigeria,
            gender="M",
            born=1990,
            occupation="Student",
            registered_on=json_date_to_datetime("2014-01-02T03:04:05.000"),
            state="R-LAGOS",
            district="R-OYO",
        )

        expected = dict()
        expected["total-reporters"] = 1
        expected["gender:m"] = 1
        expected["occupation:student"] = 1
        expected["born:1990"] = 1
        expected["registered_on:2014-01-02"] = 1
        expected["state:R-LAGOS"] = 1
        expected["district:R-OYO"] = 1

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), expected)

        Contact.objects.create(
            uuid="C-008",
            org=self.nigeria,
            gender="M",
            born=1980,
            occupation="Teacher",
            registered_on=json_date_to_datetime("2014-01-02T03:07:05.000"),
            state="R-LAGOS",
            district="R-OYO",
        )

        expected = dict()
        expected["total-reporters"] = 2
        expected["gender:m"] = 2
        expected["occupation:student"] = 1
        expected["occupation:teacher"] = 1
        expected["born:1990"] = 1
        expected["born:1980"] = 1
        expected["registered_on:2014-01-02"] = 2
        expected["state:R-LAGOS"] = 2
        expected["district:R-OYO"] = 2

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), expected)

        self.assertEqual(
            ReportersCounter.get_counts(self.nigeria, ["total-reporters", "gender:m"]),
            {"total-reporters": 2, "gender:m": 2},
        )
Example #8
0
def update_cache_org_contact_counts(org):
    from ureport.contacts.models import ReportersCounter

    key = ORG_CONTACT_COUNT_KEY % org.pk
    org_contacts_counts = ReportersCounter.get_counts(org)
    cache.set(key, org_contacts_counts, ORG_CONTACT_COUNT_TIMEOUT)
    return org_contacts_counts
Example #9
0
def get_org_contacts_counts(org):

    from ureport.contacts.models import ReportersCounter

    key = ORG_CONTACT_COUNT_KEY % org.pk
    org_contacts_counts = cache.get(key, None)
    if org_contacts_counts:
        return org_contacts_counts

    org_contacts_counts = ReportersCounter.get_counts(org)
    cache.set(key, org_contacts_counts, ORG_CONTACT_COUNT_TIMEOUT)
    return org_contacts_counts
Example #10
0
    def test_contact_ward_field(self):

        temba_contact = TembaContact.create(uuid='C-0011',
                                            name="Jan",
                                            urns=['tel:123'],
                                            groups=['G-001', 'G-007'],
                                            fields={
                                                'registration_date':
                                                '2014-01-02T03:04:05.000000Z',
                                                'state': 'Lagos',
                                                'lga': '',
                                                'ward': 'Ikeja',
                                                'occupation': 'Student',
                                                'born': '1990',
                                                'gender': 'Male'
                                            },
                                            language='eng')

        kwargs = Contact.kwargs_from_temba(self.nigeria, temba_contact)
        # invalid parent boundary (district) will yield empty ward
        self.assertEqual(
            kwargs,
            dict(
                uuid='C-0011',
                org=self.nigeria,
                gender='M',
                born=1990,
                occupation='Student',
                registered_on=json_date_to_datetime('2014-01-02T03:04:05.000'),
                state='R-LAGOS',
                district='',
                ward=''))

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), dict())
        Contact.objects.create(
            uuid='C-007',
            org=self.nigeria,
            gender='M',
            born=1990,
            occupation='Student',
            registered_on=json_date_to_datetime('2014-01-02T03:04:05.000'),
            state='R-LAGOS',
            district='R-OYO',
            ward='R-IKEJA')
        field_count = ReportersCounter.get_counts(self.nigeria)

        self.assertEqual(field_count['ward:R-IKEJA'], 1)

        Contact.objects.create(
            uuid='C-008',
            org=self.nigeria,
            gender='M',
            born=1980,
            occupation='Teacher',
            registered_on=json_date_to_datetime('2014-01-02T03:07:05.000'),
            state='R-LAGOS',
            district='R-OYO',
            ward='R-IKEJA')

        field_count = ReportersCounter.get_counts(self.nigeria)
        self.assertEqual(field_count['ward:R-IKEJA'], 2)
        Contact.objects.all().delete()
Example #11
0
    def test_reporters_counter(self):
        self.assertEqual(ReportersCounter.get_counts(self.nigeria), dict())
        Contact.objects.create(
            uuid="C-007",
            org=self.nigeria,
            gender="M",
            born=1990,
            occupation="Student",
            registered_on=json_date_to_datetime("2014-01-02T03:04:05.000"),
            state="R-LAGOS",
            district="R-OYO",
        )

        expected = dict()
        expected["total-reporters"] = 1
        expected["gender:m"] = 1
        expected["occupation:student"] = 1
        expected["born:1990"] = 1
        expected["registered_on:2014-01-02"] = 1
        expected["registered_gender:2014-01-01:m"] = 1
        expected["registered_born:2014-01-01:1990"] = 1
        expected["registered_state:2014-01-01:R-LAGOS"] = 1
        expected["state:R-LAGOS"] = 1
        expected["district:R-OYO"] = 1

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), expected)

        Contact.objects.create(
            uuid="C-008",
            org=self.nigeria,
            gender="M",
            born=1980,
            occupation="Teacher",
            registered_on=json_date_to_datetime("2014-01-02T03:07:05.000"),
            state="R-LAGOS",
            district="R-OYO",
        )

        expected = dict()
        expected["total-reporters"] = 2
        expected["gender:m"] = 2
        expected["occupation:student"] = 1
        expected["occupation:teacher"] = 1
        expected["born:1990"] = 1
        expected["born:1980"] = 1
        expected["registered_on:2014-01-02"] = 2
        expected["registered_gender:2014-01-01:m"] = 2
        expected["registered_born:2014-01-01:1990"] = 1
        expected["registered_born:2014-01-01:1980"] = 1
        expected["registered_state:2014-01-01:R-LAGOS"] = 2
        expected["state:R-LAGOS"] = 2
        expected["district:R-OYO"] = 2

        self.assertEqual(ReportersCounter.get_counts(self.nigeria), expected)

        self.assertEqual(
            ReportersCounter.get_counts(self.nigeria,
                                        ["total-reporters", "gender:m"]),
            {
                "total-reporters": 2,
                "gender:m": 2
            },
        )