예제 #1
0
 def test(self):
     self.domain = 'alskdjfablasdkffsdlkfjabas'
     project = create_domain(name=self.domain)
     app = Application(domain=self.domain, version=4)
     app.save()
     app_id = app.get_id
     build = Application(domain=self.domain, version=3)
     build.copy_of = app_id
     build.save()
     build_id = build.get_id
     cache.clear()
     try:
         self._test(build_id, app_id, build_id)
         self._test(app_id, app_id, None)
         self._test('alskdjflaksdjf', 'alskdjflaksdjf', None)
         app.delete_app()
         # does this work just as well for a deleted app?
         cache.clear()
         self._test(build_id, app_id, build_id)
         build.delete_app()
         cache.clear()
         form = self._test(build_id, app_id, build_id)
         self._test_app_version(self.domain, form, build)
         # (test cache hit)
         self._test_app_version(self.domain, form, build)
     finally:
         project.delete()
예제 #2
0
    def test_repeat_record_created(self):
        '''
        Tests that whenever an application with a repeater is saved that a repeat record is created.
        '''
        application = Application(domain=self.domain)
        application.save()

        repeat_records = RepeatRecord.all(domain=self.domain,
                                          due_before=datetime.utcnow())
        self.assertEqual(len(repeat_records), 0)

        app_structure_repeater = AppStructureRepeater(domain=self.domain,
                                                      url=self.forwarding_url)
        app_structure_repeater.save()

        application.save()
        repeat_records = RepeatRecord.all(domain=self.domain,
                                          due_before=datetime.utcnow())

        self.assertEqual(len(repeat_records), 1)
        for repeat_record in repeat_records:
            self.assertEqual(repeat_record.url, self.forwarding_url)
            self.assertEqual(repeat_record.get_payload(), application.get_id)
            repeat_record.delete()

        application.delete()
        app_structure_repeater.delete()
예제 #3
0
 def test_build_id(self):
     app = Application(domain=self.domain)
     app.save()
     config = RestoreConfig(
         project=self.project,
         restore_user=self.restore_user,
         params=RestoreParams(app=app, ),
     )
     config.get_payload()  # this generates the sync log
     sync_log = SyncLog.last_for_user(self.restore_user.user_id)
     self.assertEqual(self.restore_user.user_id, sync_log.user_id)
     self.assertEqual(self.restore_user.domain, sync_log.domain)
     self.assertEqual(app._id, sync_log.build_id)
     self.addCleanup(app.delete)
예제 #4
0
 def test_build_id(self):
     app = Application(domain=self.domain)
     app.save()
     config = RestoreConfig(
         project=self.project,
         restore_user=self.restore_user,
         params=RestoreParams(
             app=app,
         ),
     )
     config.get_payload()  # this generates the sync log
     sync_log = SyncLog.last_for_user(self.restore_user.user_id)
     self.assertEqual(self.restore_user.user_id, sync_log.user_id)
     self.assertEqual(self.restore_user.domain, sync_log.domain)
     self.assertEqual(app._id, sync_log.build_id)
     self.addCleanup(app.delete)
예제 #5
0
class TestAppStructureRepeater(TestCase):
    @classmethod
    def setUpClass(cls):
        super(TestAppStructureRepeater, cls).setUpClass()
        cls.client = Client()
        cls.domain = 'bedazzled'
        cls.forwarding_url = 'http://not-a-real-url-at-all'

    def tearDown(self):
        delete_all_repeat_records()

    def test_repeat_record_not_created(self):
        """
        When an application without a repeater is saved, then a repeat record should not be created
        """
        self.application = Application(domain=self.domain)
        self.application.save()
        self.addCleanup(self.application.delete)

        # Enqueued repeat records have next_check set 48 hours in the future.
        later = datetime.utcnow() + timedelta(hours=48 + 1)
        repeat_records = RepeatRecord.all(domain=self.domain, due_before=later)
        self.assertEqual(len(repeat_records), 0)

    def test_repeat_record_created(self):
        """
        When an application with a repeater is saved, then a repeat record should be created
        """
        self.app_structure_repeater = AppStructureRepeater(
            domain=self.domain, url=self.forwarding_url)
        self.app_structure_repeater.save()
        self.addCleanup(self.app_structure_repeater.delete)

        self.application = Application(domain=self.domain)
        self.application.save()
        self.addCleanup(self.application.delete)

        later = datetime.utcnow() + timedelta(hours=48 + 1)
        repeat_records = RepeatRecord.all(domain=self.domain, due_before=later)
        self.assertEqual(len(repeat_records), 1)

    def test_repeat_record_forwarded(self):
        """
        When an application with a repeater is saved, then HQ should try to forward the repeat record
        """
        self.app_structure_repeater = AppStructureRepeater(
            domain=self.domain, url=self.forwarding_url)
        self.app_structure_repeater.save()
        self.addCleanup(self.app_structure_repeater.delete)

        with patch('corehq.motech.repeaters.models.simple_post') as mock_fire:
            self.application = Application(domain=self.domain)
            self.application.save()
            self.addCleanup(self.application.delete)

            self.assertEqual(mock_fire.call_count, 1)
예제 #6
0
    def test_repeat_record_created(self):
        '''
        Tests that whenever an application with a repeater is saved that a repeat record is created.
        '''
        application = Application(domain=self.domain)
        application.save()

        repeat_records = RepeatRecord.all(domain=self.domain, due_before=datetime.utcnow())
        self.assertEqual(len(repeat_records), 0)

        app_structure_repeater = AppStructureRepeater(domain=self.domain, url=self.forwarding_url)
        app_structure_repeater.save()

        application.save()
        repeat_records = RepeatRecord.all(domain=self.domain, due_before=datetime.utcnow())

        self.assertEqual(len(repeat_records), 1)
        for repeat_record in repeat_records:
                self.assertEqual(repeat_record.repeater.get_url(repeat_record), self.forwarding_url)
                self.assertEqual(repeat_record.get_payload(), application.get_id)
                repeat_record.delete()

        application.delete()
        app_structure_repeater.delete()
예제 #7
0
    def setUpClass(cls):
        super(TestGlobalAppConfig, cls).setUpClass()
        cls.project = Domain(name=cls.domain)
        cls.project.save()

        cls.build_profile_id = 'english'
        app = Application(
            domain=cls.domain,
            name='foo',
            langs=["en"],
            version=1,
            modules=[Module()],
            build_profiles={
                cls.build_profile_id: BuildProfile(langs=['en'], name='English only'),
            }
        )  # app is v1

        app.save()  # app is now v2

        cls.v2_build = app.make_build()
        cls.v2_build.is_released = True
        cls.v2_build.save()  # v2 is starred

        app.save()  # app is now v3
        cls.v3_build = app.make_build()
        cls.v3_build.is_released = True
        cls.v3_build.save()  # v3 is starred

        app.save()  # app is v4

        # Add a build-profile-specific release at v2
        cls.latest_profile = LatestEnabledBuildProfiles(
            domain=cls.domain,
            app_id=app.get_id,
            build_profile_id=cls.build_profile_id,
            version=cls.v2_build.version,
            build_id=cls.v2_build.get_id,
            active=True,
        )
        cls.latest_profile.save()

        cls.app = app
예제 #8
0
    def setUpClass(cls):
        super(TestLatestAppInfo, cls).setUpClass()
        cls.project = Domain(name=cls.domain)
        cls.project.save()

        app = Application(domain=cls.domain,
                          name='foo',
                          langs=["en"],
                          version=1,
                          modules=[Module()])  # app is v1

        app.save()  # app is v2
        cls.v2_build = app.make_build()
        cls.v2_build.is_released = True
        cls.v2_build.save()  # There is a starred build at v2

        app.save()  # app is v3
        app.make_build().save()  # There is a build at v3

        app.save()  # app is v4
        cls.app = app
예제 #9
0
    def setUpClass(cls):
        super(TestLatestAppInfo, cls).setUpClass()
        cls.project = Domain(name=cls.domain)
        cls.project.save()

        app = Application(
            domain=cls.domain,
            name='foo',
            langs=["en"],
            version=1,
            modules=[Module()]
        )  # app is v1

        app.save()  # app is v2
        cls.v2_build = app.make_build()
        cls.v2_build.is_released = True
        cls.v2_build.save()  # There is a starred build at v2

        app.save()  # app is v3
        app.make_build().save()  # There is a build at v3

        app.save()  # app is v4
        cls.app = app
예제 #10
0
class TestAppStructureRepeater(TestCase, DomainSubscriptionMixin):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.client = Client()
        cls.forwarding_url = 'http://not-a-real-url-at-all'

        cls.domain = 'bedazzled'
        cls.domain_obj = Domain.get_or_create_with_name(cls.domain)

        # DATA_FORWARDING is on PRO and above
        cls.setup_subscription(cls.domain, SoftwarePlanEdition.PRO)

    @classmethod
    def tearDownClass(cls):
        cls.teardown_subscriptions()
        cls.domain_obj.delete()
        clear_plan_version_cache()
        super().tearDownClass()

    def tearDown(self):
        delete_all_repeat_records()
        super().tearDown()

    def test_repeat_record_not_created(self):
        """
        When an application without a repeater is saved, then a repeat record should not be created
        """
        self.application = Application(domain=self.domain)
        self.application.save()
        self.addCleanup(self.application.delete)

        # Enqueued repeat records have next_check set 48 hours in the future.
        later = datetime.utcnow() + timedelta(hours=48 + 1)
        repeat_records = RepeatRecord.all(domain=self.domain, due_before=later)
        self.assertEqual(len(repeat_records), 0)

    def test_repeat_record_created(self):
        """
        When an application with a repeater is saved, then a repeat record should be created
        """
        self.app_structure_repeater = AppStructureRepeater(
            domain=self.domain, url=self.forwarding_url)
        self.app_structure_repeater.save()
        self.addCleanup(self.app_structure_repeater.delete)

        self.application = Application(domain=self.domain)
        self.application.save()
        self.addCleanup(self.application.delete)

        later = datetime.utcnow() + timedelta(hours=48 + 1)
        repeat_records = RepeatRecord.all(domain=self.domain, due_before=later)
        self.assertEqual(len(repeat_records), 1)

    def test_repeat_record_forwarded(self):
        """
        When an application with a repeater is saved, then HQ should try to forward the repeat record
        """
        self.app_structure_repeater = AppStructureRepeater(
            domain=self.domain, url=self.forwarding_url)
        self.app_structure_repeater.save()
        self.addCleanup(self.app_structure_repeater.delete)

        with patch(
                'corehq.motech.repeaters.models.simple_request') as mock_fire:
            self.application = Application(domain=self.domain)
            self.application.save()
            self.addCleanup(self.application.delete)

            self.assertEqual(mock_fire.call_count, 1)