Exemple #1
0
    def test_fix_xforms_with_missing_xmlns_task_fixed(self):
        """Tests the ability to fix xforms with the periodic cron task
        """

        good_form, bad_form, good_xform, bad_xforms = self.build_app_with_bad_form(
        )
        # Fix bad builds
        for bad_xform in bad_xforms:
            app = Application.get(bad_xform.build_id)
            for form in app.get_forms():
                if form.xmlns == 'undefined':
                    form.xmlns = 'my-fixed-xmlns'
            app.save()

        self._refresh_pillow()

        with tempdir() as tmp:
            with patch('corehq.apps.cleanup.tasks.UNDEFINED_XMLNS_LOG_DIR',
                       tmp):
                with patch('corehq.apps.cleanup.tasks.mail_admins_async'
                           ) as mocked_mail:
                    stats, log_file_path = fix_xforms_with_missing_xmlns()
                    self.assertTrue(mocked_mail.delay.called)

        self.assertTrue(stats['fixed'][DOMAIN], len(bad_xforms))
Exemple #2
0
    def test_fix_xforms_with_missing_xmlns_task(self):
        """Tests the ability to find anomalies that violate our asssumptions
        about all applications and builds being fixes
        """

        good_form, bad_form, good_xform, bad_xforms = self.build_app_with_bad_form()
        self._refresh_pillow()

        with tempdir() as tmp:
            with patch('corehq.apps.cleanup.tasks.UNDEFINED_XMLNS_LOG_DIR', tmp):
                with patch('corehq.apps.cleanup.tasks.mail_admins_async') as mocked_mail:
                    stats, log_file_path = fix_xforms_with_missing_xmlns()
                    self.assertTrue(mocked_mail.delay.called)

            self.assertTrue(
                (DOMAIN, bad_xforms[0].build_id) in stats['builds_with_undefined_xmlns']
            )
            self.assertEqual(stats['not_fixed_undefined_xmlns'][DOMAIN], len(bad_xforms))
    def test_fix_xforms_with_missing_xmlns_task(self):
        """Tests the ability to find anomalies that violate our asssumptions
        about all applications and builds being fixes
        """

        good_form, bad_form, good_xform, bad_xforms = self.build_app_with_bad_form()
        self._refresh_pillow()

        with tempdir() as tmp:
            with patch('corehq.apps.cleanup.tasks.UNDEFINED_XMLNS_LOG_DIR', tmp):
                with patch('corehq.apps.cleanup.tasks.mail_admins_async') as mocked_mail:
                    stats, log_file_path = fix_xforms_with_missing_xmlns()
                    self.assertTrue(mocked_mail.delay.called)

            self.assertTrue(
                (DOMAIN, bad_xforms[0].build_id) in stats['builds_with_undefined_xmlns']
            )
            self.assertEqual(stats['not_fixed_undefined_xmlns'][DOMAIN], len(bad_xforms))
    def test_fix_xforms_with_missing_xmlns_task_fixed(self):
        """Tests the ability to fix xforms with the periodic cron task
        """

        good_form, bad_form, good_xform, bad_xforms = self.build_app_with_bad_form()
        # Fix bad builds
        for bad_xform in bad_xforms:
            app = Application.get(bad_xform.build_id)
            for form in app.get_forms():
                if form.xmlns == 'undefined':
                    form.xmlns = 'my-fixed-xmlns'
            app.save()

        self._refresh_pillow()

        with tempdir() as tmp:
            with patch('corehq.apps.cleanup.tasks.UNDEFINED_XMLNS_LOG_DIR', tmp):
                with patch('corehq.apps.cleanup.tasks.mail_admins_async') as mocked_mail:
                    stats, log_file_path = fix_xforms_with_missing_xmlns()
                    self.assertTrue(mocked_mail.delay.called)

        self.assertTrue(stats['fixed'][DOMAIN], len(bad_xforms))