Exemple #1
0
    def test_couverture_fluff(self):
        with real_pillow_settings():
            management.call_command(
                'ptop_reindexer_fluff',
                'IntraHealthFormFluffPillow',
            )

        query = sqlalchemy.select(
            [
                self.couverture.c.pps_name,
                self.couverture.c.registered_total_for_region,
                self.couverture.c.registered_total_for_district
            ],
            from_obj=self.couverture,
            order_by=[self.couverture.c.doc_id]
        )
        with self.engine.begin() as connection:
            results = list(connection.execute(query).fetchall())
        self.assertEqual(len(results), 1)

        self.assertListEqual(
            [
                self.pps.name,
                1,
                1
            ],
            list(results[0])
        )
Exemple #2
0
def test_checkpoint_creation(self, reindex_id, pillow_name):
    with real_pillow_settings():
        pillow = get_pillow_by_name(pillow_name)
        random_seq = uuid.uuid4().hex
        pillow.checkpoint.update_to(random_seq)
        self.assertEqual(random_seq, pillow.checkpoint.get_current_sequence_id())
        call_command('ptop_reindexer_v2', reindex_id, cleanup=True, noinput=True)
        pillow = get_pillow_by_name(pillow_name)
        self.assertNotEqual(random_seq, pillow.checkpoint.get_current_sequence_id())
        self.assertEqual(
            str(pillow.get_change_feed().get_checkpoint_value()),
            pillow.checkpoint.get_current_sequence_id(),
        )
Exemple #3
0
def test_no_checkpoint_creation(self, reindex_id, pillow_name):
    # these pillows should not touch checkpoints since they are run with other
    # reindexers
    with real_pillow_settings():
        pillow = get_pillow_by_name(pillow_name)
        random_seq = uuid.uuid4().hex
        pillow.checkpoint.update_to(random_seq)
        self.assertEqual(random_seq, pillow.checkpoint.get_current_sequence_id())
        call_command('ptop_reindexer_v2', reindex_id, cleanup=True, noinput=True)
        pillow = get_pillow_by_name(pillow_name)
        self.assertEqual(
            random_seq,
            pillow.checkpoint.get_current_sequence_id(),
        )
Exemple #4
0
    def test_taux_de_satifisfaction_fluff(self):
        with real_pillow_settings():
            management.call_command(
                'ptop_reindexer_fluff',
                'TauxDeSatisfactionFluffPillow',
            )

        query = sqlalchemy.select(
            [
                self.table.c.region_id,
                self.table.c.district_id,
                self.table.c.product_id,
                self.table.c.product_name,
                self.table.c.commandes_total,
                self.table.c.recus_total
            ],
            from_obj=self.table,
            order_by=[self.table.c.doc_id]
        )
        with self.engine.begin() as connection:
            results = list(connection.execute(query).fetchall())
        self.assertEqual(len(results), 2)

        self.assertListEqual(
            [
                self.region.get_id,
                self.district.get_id,
                self.product2.get_id,
                self.product2.name,
                26,
                23
            ],
            list(results[0])
        )

        self.assertListEqual(
            [
                self.region.get_id,
                self.district.get_id,
                self.product.get_id,
                self.product.name,
                25,
                25
            ],
            list(results[1])
        )
Exemple #5
0
    def setUpClass(cls):
        super(TestReports, cls).setUpClass()
        with open(os.path.join(DATAPATH, 'taux.xml'), encoding='utf-8') as f:
            xml = f.read()
            xml_obj = ElementTree.fromstring(xml)
            xml_obj[2][4].text = cls.mobile_worker.get_id
            xml = ElementTree.tostring(xml_obj)
            cls.taux = submit_form_locally(
                xml, TEST_DOMAIN, auth_context=AuthContext(
                    user_id=cls.mobile_worker.get_id, domain=TEST_DOMAIN, authenticated=True
                )
            ).xform

        with real_pillow_settings():
            management.call_command(
                'ptop_reindexer_fluff',
                'IntraHealthFormFluffPillow'
            )
Exemple #6
0
def test_checkpoint_creation(self, reindex_id, pillow_name):
    with real_pillow_settings():
        pillow = get_pillow_by_name(pillow_name)
        random_seq = uuid.uuid4().hex
        pillow.checkpoint.update_to(random_seq)
        self.assertEqual(random_seq,
                         pillow.checkpoint.get_current_sequence_id())
        call_command('ptop_reindexer_v2',
                     reindex_id,
                     cleanup=True,
                     noinput=True)
        pillow = get_pillow_by_name(pillow_name)
        self.assertNotEqual(random_seq,
                            pillow.checkpoint.get_current_sequence_id())
        self.assertEqual(
            str(pillow.get_change_feed().get_checkpoint_value()),
            pillow.checkpoint.get_current_sequence_id(),
        )
    def test_couverture_fluff(self):
        with real_pillow_settings():
            management.call_command(
                'ptop_reindexer_fluff',
                'IntraHealthFormFluffPillow',
            )

        query = sqlalchemy.select([
            self.couverture.c.pps_name,
            self.couverture.c.registered_total_for_region,
            self.couverture.c.registered_total_for_district
        ],
                                  from_obj=self.couverture,
                                  order_by=[self.couverture.c.doc_id])
        with self.engine.begin() as connection:
            results = list(connection.execute(query).fetchall())
        self.assertEqual(len(results), 1)

        self.assertListEqual([self.pps.name, 1, 1], list(results[0]))
Exemple #8
0
    def test_taux_de_satifisfaction_fluff(self):
        with real_pillow_settings():
            management.call_command(
                'ptop_reindexer_fluff',
                'IntraHealthFormFluffPillow',
            )

        query = sqlalchemy.select(
            [
                self.table.c.region_id,
                self.table.c.district_id,
                self.table.c.product_id,
                self.table.c.product_name,
                self.table.c.commandes_total,
                self.table.c.recus_total
            ],
            from_obj=self.table,
            order_by=[self.table.c.doc_id]
        )
        with self.engine.begin() as connection:
            results = list(connection.execute(query).fetchall())

        self.assertItemsEqual(
            [
                [
                    self.region.get_id,
                    self.district.get_id,
                    self.product.get_id,
                    self.product.name,
                    25,
                    25
                ],
                [
                    self.region.get_id,
                    self.district.get_id,
                    self.product2.get_id,
                    self.product2.name,
                    26,
                    23
                ],
            ],
            [list(result) for result in results]
        )
Exemple #9
0
    def setUpClass(cls):
        super(TestReports, cls).setUpClass()
        cls.taux_table = TauxDeSatisfactionFluff._table
        with cls.engine.begin() as connection:
            cls.taux_table.create(connection, checkfirst=True)

        with open(os.path.join(DATAPATH, 'taux.xml')) as f:
            xml = f.read()
            cls.taux = submit_form_locally(
                xml, TEST_DOMAIN, auth_context=AuthContext(
                    user_id=cls.mobile_worker.get_id, domain=TEST_DOMAIN, authenticated=True
                )
            )[1]

        with real_pillow_settings():
            management.call_command(
                'ptop_reindexer_fluff',
                'TauxDeSatisfactionFluffPillow',
            )
Exemple #10
0
    def setUpClass(cls):
        super(TestReports, cls).setUpClass()
        cls.taux_table = TauxDeSatisfactionFluff._table
        with cls.engine.begin() as connection:
            cls.taux_table.create(connection, checkfirst=True)

        with open(os.path.join(DATAPATH, 'taux.xml')) as f:
            xml = f.read()
            cls.taux = submit_form_locally(
                xml,
                TEST_DOMAIN,
                auth_context=AuthContext(user_id=cls.mobile_worker.get_id,
                                         domain=TEST_DOMAIN,
                                         authenticated=True))[1]

        with real_pillow_settings():
            management.call_command(
                'ptop_reindexer_fluff',
                'TauxDeSatisfactionFluffPillow',
            )
Exemple #11
0
def test_no_checkpoint_creation(self, reindex_id, pillow_name):
    # these pillows should not touch checkpoints since they are run with other
    # reindexers
    with real_pillow_settings():
        pillow = get_pillow_by_name(pillow_name)

        # set these to something obviously wrong
        current_offsets = pillow.checkpoint.get_current_sequence_id()
        bad_offsets = {
            tp: (offset + 38014)
            for tp, offset in current_offsets.items()
        }
        pillow.checkpoint.update_to(bad_offsets)
        self.assertNotEqual(current_offsets,
                            pillow.checkpoint.get_current_sequence_id())
        self.assertEqual(bad_offsets,
                         pillow.checkpoint.get_current_sequence_id())
        call_command('ptop_reindexer_v2',
                     reindex_id,
                     cleanup=True,
                     noinput=True)

        # make sure they are still bad
        pillow = get_pillow_by_name(pillow_name)
        self.assertNotEqual(
            current_offsets,
            pillow.checkpoint.get_current_sequence_id(),
        )
        self.assertEqual(
            bad_offsets,
            pillow.checkpoint.get_current_sequence_id(),
        )
        self.assertNotEqual(
            pillow.get_change_feed().get_latest_offsets_as_checkpoint_value(),
            pillow.checkpoint.get_or_create_wrapped().wrapped_sequence,
        )
        self.assertNotEqual(
            pillow.get_change_feed().get_latest_offsets_as_checkpoint_value(),
            pillow.checkpoint.get_current_sequence_id(),
        )
Exemple #12
0
def test_checkpoint_creation(self, reindex_id, pillow_name):
    # checks that checkpoipnts are set to the latest checkpoints after reindexing
    with real_pillow_settings():
        pillow = get_pillow_by_name(pillow_name)

        # set the offets to something obviously wrong
        current_offsets = pillow.checkpoint.get_current_sequence_as_dict()
        bad_offsets = {tp: (offset + 38014) for tp, offset in current_offsets.items()}
        pillow.checkpoint.update_to(bad_offsets)
        self.assertNotEqual(current_offsets, pillow.checkpoint.get_current_sequence_as_dict())
        self.assertEqual(bad_offsets, pillow.checkpoint.get_current_sequence_as_dict())

        reindex_and_clean(reindex_id)
        pillow = get_pillow_by_name(pillow_name)
        self.assertNotEqual(bad_offsets, pillow.checkpoint.get_current_sequence_as_dict())
        self.assertEqual(
            pillow.get_change_feed().get_latest_offsets_as_checkpoint_value(),
            pillow.checkpoint.get_or_create_wrapped().wrapped_sequence,
        )
        self.assertEqual(
            pillow.get_change_feed().get_latest_offsets_as_checkpoint_value(),
            pillow.checkpoint.get_current_sequence_as_dict(),
        )
Exemple #13
0
 def setUp(self):
     self.settings_context = real_pillow_settings()
     self.settings_context.__enter__()