示例#1
0
    def test_prune_autogenerated_builds(self):
        kafka_seq = get_topic_offset(topics.APP)
        couch_seq = get_current_seq(Application.get_db())
        # Build #1, manually generated
        app = self._create_app('test-prune-app')
        build1 = app.make_build()
        build1.save()
        self.assertFalse(build1.is_auto_generated)

        # Build #2, auto-generated
        app.save()
        autogenerate_build(app, 'username')

        # Build #3, manually generated
        app.save()
        build3 = app.make_build()
        build3.save()

        # All 3 builds should show up in ES
        self.refresh_elasticsearch(kafka_seq, couch_seq)
        build_ids_in_es = AppES().domain(self.domain).is_build().values_list(
            '_id', flat=True)
        self.assertEqual(len(build_ids_in_es), 3)

        # prune, which should delete the autogenerated build
        prune_auto_generated_builds(self.domain, app.id)

        # Build2 should no longer be in ES
        self.refresh_elasticsearch(kafka_seq, couch_seq)
        build_ids_in_es = AppES().domain(self.domain).is_build().values_list(
            '_id', flat=True)
        self.assertItemsEqual(build_ids_in_es, [build1._id, build3._id])
示例#2
0
def download_media_profile(request, domain, app_id):
    if not request.app.copy_of:
        username = request.GET.get('username', 'unknown user')
        autogenerate_build(request.app, username)
    else:
        request._always_allow_browser_caching = True
    profile = _get_build_profile_id(request)
    return HttpResponse(
        request.app.create_profile(with_media=True, build_profile_id=profile))
示例#3
0
def download_odk_profile(request, domain, app_id):
    """
    See ApplicationBase.create_profile

    """
    if not request.app.copy_of:
        username = request.GET.get('username', 'unknown user')
        autogenerate_build(request.app, username)
    else:
        request._always_allow_browser_caching = True
    profile = _get_build_profile_id(request)
    return HttpResponse(request.app.create_profile(is_odk=True,
                                                   build_profile_id=profile),
                        content_type="commcare/profile")
示例#4
0
    def testPruneAutoGeneratedBuilds(self, mock):
        # Build #1, manually generated
        app = import_app(self._yesno_source, self.domain)
        for module in app.modules:
            module.get_or_create_unique_id()
        app.save()
        build1 = app.make_build()
        build1.save()
        self.assertFalse(build1.is_auto_generated)

        # Build #2, auto-generated
        app.save()
        autogenerate_build(app, "username")
        build_ids = get_build_ids(app.domain, app.id)
        self.assertEqual(len(build_ids), 2)
        self.assertEqual(build_ids[1], build1.id)
        build2 = get_app(app.domain, build_ids[0])
        self.assertTrue(build2.is_auto_generated)

        # First prune: delete nothing because the auto build is the most recent
        prune_auto_generated_builds(self.domain, app.id)
        self.assertEqual(len(get_build_ids(app.domain, app.id)), 2)

        # Build #3, manually generated
        app.save()
        build3 = app.make_build()
        build3.save()

        # Release the auto-generated build and prune again, should still delete nothing
        build2.is_released = True
        build2.save()
        prune_auto_generated_builds(self.domain, app.id)
        self.assertEqual(len(get_build_ids(app.domain, app.id)), 3)

        # Un-release the auto-generated build and prune again, which should delete it
        build2.is_released = False
        build2.save()
        prune_auto_generated_builds(self.domain, app.id)
        build_ids = get_build_ids(app.domain, app.id)
        self.assertEqual(len(build_ids), 2)
        self.assertNotIn(build2.id, build_ids)
示例#5
0
def download_practice_user_restore(request, domain, app_id):
    if not request.app.copy_of:
        autogenerate_build(request.app, request.user.username)
    return HttpResponse(
        request.app.create_practice_user_restore()
    )