Esempio n. 1
0
 def test_stable_build_active_stable_download_count(self):
     package = PackageFactory()
     build = BuildFactory(
         active=True,
         version__report_url=None,
         version__package=package,
         architectures=[Architecture.find("cedarview")],
         firmware=Firmware.find(1594),
     )
     DownloadFactory.create_batch(1, build=build, date=datetime.now())
     DownloadFactory.create_batch(2,
                                  build=build,
                                  date=datetime.now() - timedelta(days=30))
     DownloadFactory.create_batch(4,
                                  build=build,
                                  date=datetime.now() - timedelta(days=100))
     db.session.commit()
     data = dict(arch="cedarview", build="1594", language="enu")
     response = self.client.post(url_for("nas.catalog"), data=data)
     self.assert200(response)
     self.assertHeader(response, "Content-Type", "application/json")
     catalog = json.loads(response.data.decode(response.charset))
     self.assertEqual(len(catalog), 1)
     self.assertEqual(catalog[0]["download_count"], 7)
     self.assertEqual(catalog[0]["recent_download_count"], 3)
Esempio n. 2
0
 def test_on_model_delete(self):
     package = PackageFactory()
     db.session.commit()
     self.assertEqual(len(Package.query.all()), 1)
     package_path = os.path.join(current_app.config["DATA_PATH"],
                                 package.name)
     self.assertTrue(os.path.exists(package_path))
     with self.logged_user("package_admin", "admin"):
         self.client.post(url_for("package.delete_view",
                                  id=str(package.id)))
     self.assertEqual(len(Package.query.all()), 0)
     self.assertTrue(not os.path.exists(package_path))
Esempio n. 3
0
    def test_post_existing_package_maintainer_user(self):
        user = UserFactory(roles=[Role.find('developer')])
        package = PackageFactory(maintainers=[user])
        db.session.commit()

        build = BuildFactory.build(version__package=package)
        db.session.expire(package)
        with create_spk(build) as spk:
            self.assert201(
                self.client.post(url_for('api.packages'),
                                 headers=authorization_header(user),
                                 data=spk.read()))
Esempio n. 4
0
    def test_post_existing_package_not_author_not_maintainer_user(self):
        user = UserFactory(roles=[Role.find('developer')])
        package = PackageFactory()
        db.session.commit()

        with create_spk(BuildFactory.build(version__package=package)) as spk:
            response = self.client.post(url_for('api.packages'),
                                        headers=authorization_header(user),
                                        data=spk.read())
        self.assert403(response)
        self.assertIn('Insufficient permissions on this package',
                      response.data.decode(response.charset))
Esempio n. 5
0
 def test_create(self):
     package = PackageFactory(add_screenshot=False)
     db.session.commit()
     self.assertEqual(len(package.screenshots), 0)
     with self.logged_user('package_admin'):
         response = self.client.post(url_for('screenshotview.create_view'),
                                     data=dict(package=str(package.id),
                                               path=(create_image(
                                                   'Test', 1280,
                                                   1024), 'test.png')))
     self.assertEqual(len(package.screenshots), 1)
     self.assertTrue(
         package.screenshots[0].path.endswith('screenshot_1.png'))
Esempio n. 6
0
 def test_create(self):
     package = PackageFactory(add_screenshot=False)
     db.session.commit()
     self.assertEqual(len(package.screenshots), 0)
     with self.logged_user("package_admin"):
         self.client.post(
             url_for("screenshot.create_view"),
             data=dict(
                 package=str(package.id),
                 path=(create_image("Test", 1280, 1024), "test.png"),
             ),
         )
     self.assertEqual(len(package.screenshots), 1)
     self.assertTrue(
         package.screenshots[0].path.endswith("screenshot_1.png"))
Esempio n. 7
0
def populate():
    """Populate the database with some packages"""
    from spkrepo.tests.common import BuildFactory, PackageFactory, VersionFactory

    with db.session.no_autoflush:
        # nzbget
        nzbget_package = PackageFactory(name="nzbget")
        nzbget_versions = [
            VersionFactory(
                package=nzbget_package,
                upstream_version="12.0",
                version=10,
                dependencies=None,
                report_url=None,
                install_wizard=True,
                upgrade_wizard=False,
            ),
            VersionFactory(
                package=nzbget_package,
                upstream_version="13.0",
                version=11,
                dependencies=None,
                report_url=None,
                install_wizard=True,
                upgrade_wizard=False,
            ),
        ]
        nzbget_builds = []
        for version in nzbget_versions:
            builds = BuildFactory.create_batch(2, version=version, active=True)
            nzbget_builds.extend(builds)

        # sickbeard
        sickbeard_package = PackageFactory(name="sickbeard")
        sickbeard_versions = [
            VersionFactory(
                package=sickbeard_package,
                upstream_version="20140528",
                version=3,
                dependencies="git",
                service_dependencies=[],
                report_url=None,
                install_wizard=False,
                upgrade_wizard=False,
                startable=True,
            ),
            VersionFactory(
                package=sickbeard_package,
                upstream_version="20140702",
                version=4,
                dependencies="git",
                service_dependencies=[],
                report_url=None,
                install_wizard=False,
                upgrade_wizard=False,
                startable=True,
            ),
        ]
        sickbeard_builds = []
        for version in sickbeard_versions:
            sickbeard_builds.append(
                BuildFactory(
                    version=version,
                    architectures=[Architecture.find("noarch")],
                    active=True,
                ))

        # git
        git_package = PackageFactory(name="git")
        git_versions = [
            VersionFactory(
                package=git_package,
                upstream_version="1.8.4",
                version=3,
                dependencies=None,
                service_dependencies=[],
                report_url=None,
                install_wizard=False,
                upgrade_wizard=False,
                startable=False,
            ),
            VersionFactory(
                package=git_package,
                upstream_version="2.1.2",
                version=4,
                dependencies=None,
                service_dependencies=[],
                report_url=None,
                install_wizard=False,
                upgrade_wizard=False,
                startable=False,
            ),
        ]
        git_builds = []
        for version in git_versions:
            builds = BuildFactory.create_batch(3, version=version, active=True)
            git_builds.extend(builds)

        # bitlbee
        bitlbee_package = PackageFactory(name="bitlbee")
        bitlbee_versions = [
            VersionFactory(
                package=bitlbee_package,
                upstream_version="3.2.2",
                version=9,
                dependencies=None,
                service_dependencies=[],
                report_url=None,
                install_wizard=False,
                upgrade_wizard=False,
                startable=True,
            ),
            VersionFactory(
                package=bitlbee_package,
                upstream_version="3.2.3",
                version=10,
                dependencies=None,
                service_dependencies=[],
                report_url=None,
                install_wizard=False,
                upgrade_wizard=False,
                startable=True,
            ),
            VersionFactory(
                package=bitlbee_package,
                upstream_version="3.3.0",
                version=11,
                dependencies=None,
                service_dependencies=[],
                install_wizard=False,
                upgrade_wizard=False,
                startable=True,
            ),
        ]
        bitlbee_builds = []
        for version in bitlbee_versions:
            builds = BuildFactory.create_batch(3, version=version, active=True)
            bitlbee_builds.extend(builds)
    db.session.commit()
Esempio n. 8
0
def populate():
    """Populate the database with some packages"""
    from spkrepo.tests.common import BuildFactory, PackageFactory, VersionFactory
    with db.session.no_autoflush:
        # nzbget
        nzbget_package = PackageFactory(name='nzbget')
        nzbget_versions = [
            VersionFactory(package=nzbget_package,
                           upstream_version='12.0',
                           version=10,
                           dependencies=None,
                           report_url=None,
                           install_wizard=True,
                           upgrade_wizard=False),
            VersionFactory(package=nzbget_package,
                           upstream_version='13.0',
                           version=11,
                           dependencies=None,
                           report_url=None,
                           install_wizard=True,
                           upgrade_wizard=False)
        ]
        nzbget_builds = []
        for version in nzbget_versions:
            builds = BuildFactory.create_batch(2, version=version, active=True)
            nzbget_builds.extend(builds)

        # sickbeard
        sickbeard_package = PackageFactory(name='sickbeard')
        sickbeard_versions = [
            VersionFactory(package=sickbeard_package,
                           upstream_version='20140528',
                           version=3,
                           dependencies='git',
                           service_dependencies=[],
                           report_url=None,
                           install_wizard=False,
                           upgrade_wizard=False,
                           startable=True),
            VersionFactory(package=sickbeard_package,
                           upstream_version='20140702',
                           version=4,
                           dependencies='git',
                           service_dependencies=[],
                           report_url=None,
                           install_wizard=False,
                           upgrade_wizard=False,
                           startable=True)
        ]
        sickbeard_builds = []
        for version in sickbeard_versions:
            sickbeard_builds.append(
                BuildFactory(version=version,
                             architectures=[Architecture.find('noarch')],
                             active=True))

        # git
        git_package = PackageFactory(name='git')
        git_versions = [
            VersionFactory(package=git_package,
                           upstream_version='1.8.4',
                           version=3,
                           dependencies=None,
                           service_dependencies=[],
                           report_url=None,
                           install_wizard=False,
                           upgrade_wizard=False,
                           startable=False),
            VersionFactory(package=git_package,
                           upstream_version='2.1.2',
                           version=4,
                           dependencies=None,
                           service_dependencies=[],
                           report_url=None,
                           install_wizard=False,
                           upgrade_wizard=False,
                           startable=False)
        ]
        git_builds = []
        for version in git_versions:
            builds = BuildFactory.create_batch(3, version=version, active=True)
            git_builds.extend(builds)

        # bitlbee
        bitlbee_package = PackageFactory(name='bitlbee')
        bitlbee_versions = [
            VersionFactory(package=bitlbee_package,
                           upstream_version='3.2.2',
                           version=9,
                           dependencies=None,
                           service_dependencies=[],
                           report_url=None,
                           install_wizard=False,
                           upgrade_wizard=False,
                           startable=True),
            VersionFactory(package=bitlbee_package,
                           upstream_version='3.2.3',
                           version=10,
                           dependencies=None,
                           service_dependencies=[],
                           report_url=None,
                           install_wizard=False,
                           upgrade_wizard=False,
                           startable=True),
            VersionFactory(package=bitlbee_package,
                           upstream_version='3.3.0',
                           version=11,
                           dependencies=None,
                           service_dependencies=[],
                           install_wizard=False,
                           upgrade_wizard=False,
                           startable=True)
        ]
        bitlbee_builds = []
        for version in bitlbee_versions:
            builds = BuildFactory.create_batch(3, version=version, active=True)
            bitlbee_builds.extend(builds)
    db.session.commit()