示例#1
0
def create_pkg_list(request):
    create_app(request)

    pkg_list = []

    for i in range(0, 33):
        pkg = Package(
            metadata=request.instance.app_data['metadata'],
            application=request.instance.app,
            interpreter_name=request.instance.app.interpreter_name,
            interpreter_version=request.instance.app.interpreter_version,
            filename='pkg%d' % i, bytes=1024, checksum='abcdefg',
            builder='fake builder', distro_name=distro_name(),
            distro_version=distro_version(), distro_arch=distro_arch())
        pkg.save()
        pkg_list.append(pkg)

    def cleanup():
        for pkg in pkg_list:
            pkg.delete()
    request.addfinalizer(cleanup)

    request.instance.app.current_package = pkg_list[0]
    request.instance.app.packages = pkg_list
    request.instance.app.save()

    request.instance.pkg_list = pkg_list
示例#2
0
 def test_pkg_delete_post(self):
     self.login_as_user()
     pkg = self.pkg_list[len(self.pkg_list)-1]
     url = reverse('package_delete', args=[pkg.safe_id])
     resp = self.client.post(url, {'confirm': True})
     self.assertEqual(resp.status_code, 302)
     self.assertEqual(Package.objects(id=pkg.id).first(), None)
示例#3
0
    def test_package_delete_all_owned(self):
        packages = {}
        i = 10
        for user, app in self.user_list_apps.items():
            pkg = self.pkg_list[i]
            pkg.application = app
            pkg.save()
            packages[user] = pkg
            i += 1

        self.assertHttpAccepted(self.api_client.delete(
            '/api/v1/package/', format='json',
            **self.get_apikey_auth(self.user)))

        self.assertEqual(len(Package.objects()), 11)

        for user, pkg in packages.items():
            resp = self.api_client.get(
                '/api/v1/package/%s/' % pkg.safe_id, format='json',
                **self.get_apikey_auth(user))
            self.assertValidJSONResponse(resp)
            self.assertEqual(self.deserialize(resp)['builder'], 'fake builder')
            self.assertEqual(self.deserialize(resp)['bytes'], '1024')

        resp = self.api_client.get('/api/v1/package/', format='json',
                                   **self.get_apikey_auth(self.user))
        self.assertValidJSONResponse(resp)
        self.assertEqual(len(self.deserialize(resp)['objects']), 1)

        resp = self.api_client.get(
            '/api/v1/package/%s/' % self.app.current_package.safe_id,
            format='json', **self.get_apikey_auth(self.user))
        self.assertValidJSONResponse(resp)
        self.assertEqual(self.deserialize(resp)['bytes'],
                         str(self.app.current_package.bytes))
示例#4
0
def create_pkg(request):
    create_app(request)

    pkg = Package(metadata=request.instance.app_data['metadata'],
                  application=request.instance.app,
                  interpreter_name=request.instance.app.interpreter_name,
                  interpreter_version=request.instance.app.interpreter_version,
                  filename='pkg', bytes=1024, checksum='abcdefg',
                  builder='fake builder', distro_name=distro_name(),
                  distro_version=distro_version(), distro_arch=distro_arch())
    pkg.save()

    def cleanup():
        pkg.delete()
    request.addfinalizer(cleanup)

    request.instance.app.current_package = pkg
    request.instance.app.packages = [pkg]
    request.instance.app.save()

    request.instance.pkg = pkg
示例#5
0
    def create_package(self, app, task, metadata_obj, metadata, build_result,
                       parent_package):
        log.info("Building completed, saving package")
        pkg = Package(metadata=metadata,
                      application=app,
                      task=task,
                      interpreter_name=metadata_obj.interpreter.type,
                      interpreter_version=build_result.interpreter_version,
                      bytes=build_result.bytes,
                      filename=build_result.filename,
                      checksum=build_result.checksum,
                      parent=build_result.parent,
                      builder=self.backend.name,
                      distro_name=build_result.distro_name,
                      distro_version=build_result.distro_version,
                      distro_arch=build_result.distro_arch)
        if parent_package and build_result.parent == parent_package.filename:
            pkg.parent_package = parent_package
        if build_result.vcs_revision.get('id'):
            pkg.revision_id = build_result.vcs_revision.get('id')
        if build_result.vcs_revision.get('author'):
            pkg.revision_author = build_result.vcs_revision.get('author')
        if build_result.vcs_revision.get('date'):
            pkg.revision_date = build_result.vcs_revision.get('date')
        if build_result.vcs_revision.get('description'):
            pkg.revision_description = build_result.vcs_revision.get(
                'description')
        if build_result.vcs_revision.get('changelog'):
            pkg.revision_changelog = build_result.vcs_revision.get(
                'changelog')
        pkg.save()
        log.info(_("Package saved with id {id}").format(id=pkg.safe_id))

        app.update(add_to_set__packages=pkg, set__current_package=pkg)
        app.reload()
        app.upgrade_application()
        app.trim_package_files()
示例#6
0
 def get_queryset(self):
     return Package.objects(application__in=self.request.user.applications)
示例#7
0
 def paginated_objects(self):
     return Package.objects(application=self.object)