示例#1
0
def heartbeat(request, domain, app_build_id):
    """
    An endpoint for CommCare mobile to get latest CommCare APK and app version
        info. (Should serve from cache as it's going to be busy view)

    'app_build_id' (that comes from URL) can be id of any version of the app
    'app_id' (urlparam) is usually id of an app that is not a copy
        mobile simply needs it to be resent back in the JSON, and doesn't
        need any validation on it. This is pulled from @uniqueid from profile.xml
    """
    app_id = request.GET.get('app_id', '')
    build_profile_id = request.GET.get('build_profile_id', '')

    try:
        info = GlobalAppConfig.get_latest_version_info(domain, app_id,
                                                       build_profile_id)
    except (Http404, AssertionError):
        # If it's not a valid master app id, find it by talking to couch
        notify_exception(request, 'Received an invalid heartbeat request')
        app = get_app_cached(domain, app_build_id)
        info = GlobalAppConfig.get_latest_version_info(domain, app.master_id,
                                                       build_profile_id)

    info["app_id"] = app_id

    if not toggles.SKIP_UPDATING_USER_REPORTING_METADATA.enabled(domain):
        update_user_reporting_data(app_build_id, app_id, build_profile_id,
                                   request.couch_user, request)

    if _should_force_log_submission(request):
        info['force_logs'] = True
    return JsonResponse(info)
示例#2
0
    def test_args(self):
        with self.assertRaises(AssertionError):
            # should not be id of a copy
            config = GlobalAppConfig.by_app_id(self.domain, self.v3_build.id)
            config.get_latest_app_version(build_profile_id='')

        with self.assertRaises(Http404):
            config = GlobalAppConfig.by_app_id(self.domain, 'wrong-id')
            config.get_latest_app_version(build_profile_id='')
示例#3
0
 def test_app_prompt(self):
     app_config = self.app.global_app_config
     app_config.save()
     test_cases = [
         ('off', '', {}),
         ('on', '', {
             'value': self.v3_build.version,
             'force': False
         }),
         ('forced', '', {
             'value': self.v3_build.version,
             'force': True
         }),
         ('off', self.build_profile_id, {}),
         ('on', self.build_profile_id, {
             'value': self.v2_build.version,
             'force': False
         }),
         ('forced', self.build_profile_id, {
             'value': self.v2_build.version,
             'force': True
         }),
     ]
     for config, build_profile_id, response in test_cases:
         app_config = self.app.global_app_config
         app_config.app_prompt = config
         app_config.save()
         config = GlobalAppConfig.by_app_id(self.domain, self.app.origin_id)
         self.assertEqual(config.get_latest_app_version(build_profile_id),
                          response)
示例#4
0
 def test_apk_prompt(self):
     from corehq.apps.builds.utils import get_default_build_spec
     latest_apk = get_default_build_spec().version
     test_cases = [
         ('off', {}),
         ('on', {'value': latest_apk, 'force': False}),
         ('forced', {'value': latest_apk, 'force': True}),
     ]
     for config, response in test_cases:
         app_config = self.app.global_app_config
         app_config.apk_prompt = config
         app_config.save()
         config = GlobalAppConfig.by_app_id(self.domain, self.app.origin_id)
         self.assertEqual(
             config.get_latest_apk_version(),
             response
         )
示例#5
0
 def test_app_prompt_preset(self):
     preset_app = 21  # some random version
     test_cases = [
         ('off', {}),
         ('on', {'value': preset_app, 'force': False}),
         ('forced', {'value': preset_app, 'force': True}),
     ]
     app_config = self.app.global_app_config
     app_config.app_version = preset_app
     app_config.save()
     for config, response in test_cases:
         app_config = self.app.global_app_config
         app_config.app_prompt = config
         app_config.save()
         config = GlobalAppConfig.by_app_id(self.domain, self.app.origin_id)
         self.assertEqual(
             config.get_latest_app_version(build_profile_id=''),
             response
         )
示例#6
0
 def test_apk_prompt_preset(self):
     preset_apk = '2.20.0/latest'  # some random version
     test_cases = [
         ('off', {}),
         ('on', {'value': '2.20.0', 'force': False}),
         ('forced', {'value': '2.20.0', 'force': True}),
     ]
     app_config = self.app.global_app_config
     app_config.apk_version = preset_apk
     app_config.save()
     for config, response in test_cases:
         app_config = self.app.global_app_config
         app_config.apk_prompt = config
         app_config.save()
         config = GlobalAppConfig.by_app_id(self.domain, self.app.origin_id)
         self.assertEqual(
             config.get_latest_apk_version(),
             response
         )
示例#7
0
 def _fresh_config(self, app_id):
     config = GlobalAppConfig.by_app_id(self.domain, app_id)
     config.app_prompt = 'on'
     return config