Beispiel #1
0
    def test_package_archives_foreign_key_constraint(self):
        vendor = Vendor('repo1')
        archive = PackageArchive('firefox', 'v1', 'r1', 'i586', 'dummy',
                                 '12.1', 'vendor', 'voted', date.today(), 1)
        db_session.add(archive)

        self.assertRaises(IntegrityError, db_session.commit)
Beispiel #2
0
    def test_package_archives_foreign_key_constraint(self):
        vendor = Vendor('repo1')
        archive = PackageArchive('firefox', 'v1', 'r1', 'i586', 'dummy',
                                 '12.1', 'vendor', 'voted', date.today(), 1)
        db_session.add(archive)

        self.assertRaises(IntegrityError, db_session.commit)
Beispiel #3
0
    def test_system_creation(self):
        self.assertEqual(System.query.all(), [])

        sys = System('hwuuid')
        db_session.add(sys)
        db_session.commit()

        self.assertEqual(System.query.all(), [sys])
Beispiel #4
0
    def test_submission_creation(self):
        self.assertEqual(Submission.query.all(), [])

        sub = Submission('openSUSE', '12.1', 'i586', 'POPCORN v0.0.1')
        db_session.add(sub)
        db_session.commit()

        self.assertEqual(Submission.query.all(), [sub])
Beispiel #5
0
    def test_system_foreign_key_constraint(self):
        db_session.add(System("hw_uu", "i586", "bogus", "bogus"))

        self.assertRaises(IntegrityError, db_session.flush)
        db_session.rollback()

        db_session.add(System("hw_uu", "bogus", "Fedora", "16"))
        self.assertRaises(IntegrityError, db_session.flush)
Beispiel #6
0
    def test_system_creation(self):
        self.assertEqual(System.query.all(), [])

        sys = System('hwuuid')
        db_session.add(sys)
        db_session.commit()

        self.assertEqual(System.query.all(), [sys])
Beispiel #7
0
    def test_system_foreign_key_constraint(self):
        db_session.add(System('hw_uu', 'i586', 'bogus', 'bogus'))

        self.assertRaises(IntegrityError, db_session.flush)
        db_session.rollback()

        db_session.add(System('hw_uu', 'bogus', 'Fedora', '16'))
        self.assertRaises(IntegrityError, db_session.flush)
Beispiel #8
0
    def test_submission_creation(self):
        self.assertEqual(Submission.query.all(), [])

        sub = Submission('openSUSE', '12.1', 'i586', 'POPCORN v0.0.1')
        db_session.add(sub)
        db_session.commit()

        self.assertEqual(Submission.query.all(), [sub])
Beispiel #9
0
def parse_text(data):
    """Parse a plaintext submission, recording everything in the database"""
    datalines = data.splitlines()
    (popcorn, version, distro, distrover, arch, hw_uuid) = datalines[0].split()

    try:  # TEST THIS
        system = System.query.filter_by(sys_hwuuid=hw_uuid).one()
    except NoResultFound:
        system = System(hw_uuid, arch, distro, distrover)
        try:
            Arch.query.filter_by(arch=arch).one()
        except NoResultFound:
            raise FormatError("unknown arch - " + arch)

        try:
            Distro.query.filter_by(distro_name=distro,
                                   distro_version=distrover).one()
        except NoResultFound:
            distro = Distro(distro, distrover)
            db_session.add(distro)
        db_session.add(system)

    # TODO: think about moving this to the model
    if not _can_submit(system):
        raise EarlySubmissionError(system.last_submission.sub_date)

    today = date.today()
    sub = Submission(system.sys_hwuuid, version, today)
    db_session.add(sub)
    for line in datalines[1:]:
        try:
            (status, name, version, release,
             epoch, arch, vendor) = line.split(None, 6)
        except ValueError, e:  # test this
            raise FormatError(e.message)

        try:
            status = {'v': 'voted',
                      'r': 'recent',
                      'o': 'old',
                      'n': 'nofiles'}[status]
        except KeyError:
            raise FormatError("the package's status could not be recognized")

        try:
            vendor = Vendor.query.filter_by(vendor_name=vendor[:20]).one()
        except NoResultFound:
            vendor = Vendor(vendor)
            db_session.add(vendor)
            try:
                db_session.flush()
            except DataError:  # TODO mail this to the admins
                raise

        sp = SubmissionPackage(hw_uuid, today, name, version, release,
                               epoch, arch, vendor.vendor_name, status)
        db_session.add(sp)
Beispiel #10
0
 def test_package_archive_creation(self):
     vendor = Vendor('repo1')
     archive = PackageArchive('firefox', 'v1', 'r1', 'i586',
                              'http://repo.url', 'voted', 'openSUSE',
                              '12.1', date.today(), 1)
     db_session.add(vendor)
     db_session.flush()
     db_session.add(archive)
     db_session.flush()
     self.assertEqual(PackageArchive.query.first(), archive)
Beispiel #11
0
 def test_package_archive_creation(self):
     vendor = Vendor('repo1')
     archive = PackageArchive('firefox', 'v1', 'r1', 'i586',
                              'http://repo.url', 'voted', 'openSUSE',
                              '12.1', date.today(), 1)
     db_session.add(vendor)
     db_session.flush()
     db_session.add(archive)
     db_session.flush()
     self.assertEqual(PackageArchive.query.first(), archive)
Beispiel #12
0
    def test_submission_creation(self):
        sub = Submission("hw_uuid1", "POPCORN v0.0.1")

        s1 = System.query.first()
        self.assertEqual(s1.submissions, [])

        db_session.add(sub)
        db_session.commit()

        self.assertEqual(Submission.query.all(), [sub])
        self.assertEqual(s1.submissions, [sub])
Beispiel #13
0
    def setUp(self):
        super(TestArchivePackages, self).setUp()
        self.old_date = date.today() - timedelta(days=400)
        self.today = date.today()

        sub1 = Submission('openSUSE', '12.1', 'i586', 'POPCORN v0.0.1',
                          self.old_date)
        db_session.add(sub1)
        db_session.flush()

        subp1 = SubmissionPackage(sub1.sub_id, self.old_date, 'python', '2.7',
                                  '3', '', 'i586', 'http://repo.url', 'voted')
        subp2 = SubmissionPackage(sub1.sub_id, self.old_date, 'chrome', '2.7',
                                  '3', '', 'i586', 'http://repo.url', 'voted')
        db_session.add_all([subp1, subp2])
        db_session.flush()
        update_archives(self.old_date)
Beispiel #14
0
    def setUp(self):
        engine = create_engine('sqlite:///:memory:')
        # engine = create_engine('sqlite:///test.db')

        event.listen(engine, 'connect', _fk_pragma_on_connect)
        db_session.configure(bind=engine)

        Base.metadata.create_all(bind=engine)

        db_session.add_all([Arch('i586'), Arch('x86_64'), Arch('noarch')])
        db_session.add_all([Distro('Fedora', '16'),
                           Distro('openSUSE', '12.1')])
        db_session.add_all([PackageStatus('voted'), PackageStatus('recent'),
                            PackageStatus('no-files'), PackageStatus('old')])
        db_session.add(Vendor('http://repo.url'))
        db_session.flush()

        self.db_session = db_session
Beispiel #15
0
    def setUp(self):
        super(TestArchivePackages, self).setUp()
        self.old_date = date.today() - timedelta(days=400)
        self.today = date.today()

        sub1 = Submission('openSUSE', '12.1', 'i586', 'POPCORN v0.0.1',
                          self.old_date)
        db_session.add(sub1)
        db_session.flush()

        subp1 = SubmissionPackage(sub1.sub_id, self.old_date, 'python',
                                  '2.7', '3', '', 'i586', 'http://repo.url',
                                  'voted')
        subp2 = SubmissionPackage(sub1.sub_id, self.old_date, 'chrome',
                                  '2.7', '3', '', 'i586', 'http://repo.url',
                                  'voted')
        db_session.add_all([subp1, subp2])
        db_session.flush()
        update_archives(self.old_date)
Beispiel #16
0
    def test_archive_package_count(self):
        sub2 = Submission('Fedora', '16', 'i586', 'v1')
        db_session.add(sub2)
        db_session.flush()

        subp3 = SubmissionPackage(sub2.sub_id, self.today, 'python',
                                  '2.7', '3', '', 'i586', 'http://repo.url',
                                  'voted')
        subp4 = SubmissionPackage(sub2.sub_id, self.today, 'chrome',
                                  '2.7', '3', '', 'i586', 'http://repo.url',
                                  'voted')

        db_session.add_all([subp3, subp4])
        db_session.flush()

        sub3 = Submission('Fedora', '16', 'i586', 'v1')
        db_session.add(sub3)
        db_session.flush()

        subp5 = SubmissionPackage(sub3.sub_id, self.today, 'python',
                                  '2.7', '3', '', 'i586', 'http://repo.url',
                                  'voted')

        db_session.add(subp5)
        db_session.flush()

        update_archives(date.today())

        self.assertEqual(len(PackageArchive.query.all()), 4)

        query = PackageArchive.query.filter_by(pkg_name='python',
                                               month=self.today.replace(day=1))
        count = self.assertEqual(query.one().count, 2)
Beispiel #17
0
    def test_archive_package_count(self):
        sub2 = Submission('Fedora', '16', 'i586', 'v1')
        db_session.add(sub2)
        db_session.flush()

        subp3 = SubmissionPackage(sub2.sub_id, self.today, 'python', '2.7',
                                  '3', '', 'i586', 'http://repo.url', 'voted')
        subp4 = SubmissionPackage(sub2.sub_id, self.today, 'chrome', '2.7',
                                  '3', '', 'i586', 'http://repo.url', 'voted')

        db_session.add_all([subp3, subp4])
        db_session.flush()

        sub3 = Submission('Fedora', '16', 'i586', 'v1')
        db_session.add(sub3)
        db_session.flush()

        subp5 = SubmissionPackage(sub3.sub_id, self.today, 'python', '2.7',
                                  '3', '', 'i586', 'http://repo.url', 'voted')

        db_session.add(subp5)
        db_session.flush()

        update_archives(date.today())

        self.assertEqual(len(PackageArchive.query.all()), 4)

        query = PackageArchive.query.filter_by(pkg_name='python',
                                               month=self.today.replace(day=1))
        count = self.assertEqual(query.one().count, 2)
Beispiel #18
0
    def setUp(self):
        engine = create_engine("sqlite:///:memory:")
        # engine = create_engine('sqlite:///test.db')

        event.listen(engine, "connect", _fk_pragma_on_connect)
        db_session.configure(bind=engine)

        Base.metadata.create_all(bind=engine)

        db_session.add_all([Arch("i586"), Arch("x86_64"), Arch("noarch")])
        db_session.add_all([Distro("Fedora", "16"), Distro("openSUSE", "12.1")])
        db_session.add_all(
            [PackageStatus("voted"), PackageStatus("recent"), PackageStatus("no-files"), PackageStatus("old")]
        )
        db_session.add(Vendor("http://repo.url"))
        db_session.flush()

        # system is dependent on both arches and distros already being in the db
        db_session.add_all([System("hw_uuid1", "i586", "Fedora", "16"), System("hw_uuid2", "i586", "openSUSE", "12.1")])
        db_session.commit()

        self.db_session = db_session
Beispiel #19
0
    def setUp(self):
        engine = create_engine('sqlite:///:memory:')
        # engine = create_engine('sqlite:///test.db')

        event.listen(engine, 'connect', _fk_pragma_on_connect)
        db_session.configure(bind=engine)

        Base.metadata.create_all(bind=engine)

        db_session.add_all([Arch('i586'), Arch('x86_64'), Arch('noarch')])
        db_session.add_all(
            [Distro('Fedora', '16'),
             Distro('openSUSE', '12.1')])
        db_session.add_all([
            PackageStatus('voted'),
            PackageStatus('recent'),
            PackageStatus('no-files'),
            PackageStatus('old')
        ])
        db_session.add(Vendor('http://repo.url'))
        db_session.flush()

        self.db_session = db_session
Beispiel #20
0
    def setUp(self):
        engine = create_engine('sqlite:///:memory:')
        # engine = create_engine('sqlite:///test.db')

        event.listen(engine, 'connect', _fk_pragma_on_connect)
        db_session.configure(bind=engine)

        Base.metadata.create_all(bind=engine)

        db_session.add_all([Arch('i586'), Arch('x86_64'), Arch('noarch')])
        db_session.add_all([Distro('Fedora', '16'),
                           Distro('openSUSE', '12.1')])
        db_session.add_all([PackageStatus('voted'), PackageStatus('recent'),
                            PackageStatus('no-files'), PackageStatus('old')])
        db_session.add(Vendor('http://repo.url'))
        db_session.flush()

        # system is dependent on both arches and distros already being
        # in the db
        db_session.add_all([System('hw_uuid1', 'i586', 'Fedora', '16'),
                            System('hw_uuid2', 'i586', 'openSUSE', '12.1')])
        db_session.commit()

        self.db_session = db_session
Beispiel #21
0
    def test_submission_package_creation(self):
        sub = Submission("hw_uuid1", "POPCORN v0.0.1")
        vendor = Vendor("repo1")
        subp = SubmissionPackage("hw_uuid1", date.today(), "python", "2.7", "3", "", "i586", "repo1", "voted")
        db_session.add(sub)
        db_session.add(vendor)
        db_session.flush()
        db_session.add(subp)
        db_session.flush()

        self.assertEqual(SubmissionPackage.query.first(), subp)
Beispiel #22
0
    def test_submission_package_creation(self):
        sub = Submission('hw_uuid1', 'POPCORN v0.0.1')
        vendor = Vendor('repo1')
        subp = SubmissionPackage('hw_uuid1', date.today(), 'python', '2.7',
                                 '3', '', 'i586', 'repo1', 'voted')
        db_session.add(sub)
        db_session.add(vendor)
        db_session.flush()
        db_session.add(subp)
        db_session.flush()

        self.assertEqual(SubmissionPackage.query.first(), subp)
Beispiel #23
0
    def test_submission_package_creation(self):
        sub = Submission('openSUSE', '12.1', 'i586', 'POPCORN v0.0.1')
        vendor = Vendor('repo1')

        db_session.add(sub)
        db_session.add(vendor)
        db_session.flush()

        subp = SubmissionPackage(sub.sub_id, date.today(), 'python', '2.7',
                                 '3', '', 'i586', 'repo1', 'voted')
        db_session.add(subp)
        db_session.flush()

        self.assertEqual(SubmissionPackage.query.first(), subp)
Beispiel #24
0
    def test_submission_foreign_key_constraint(self):
        sub = Submission('bogus', '12.1', 'i586', 'POPCORN v0.0.1')
        db_session.add(sub)

        self.assertRaises(IntegrityError, db_session.commit)
Beispiel #25
0
    def test_submission_foreign_key_constraint(self):
        sub = Submission('bogus', '12.1', 'i586', 'POPCORN v0.0.1')
        db_session.add(sub)

        self.assertRaises(IntegrityError, db_session.commit)
Beispiel #26
0
    def test_submission_foreign_key_constraint(self):
        sub = Submission("bogus", "POPCORN v0.0.1")
        db_session.add(sub)

        self.assertRaises(IntegrityError, db_session.commit)
Beispiel #27
0
        try:
            vendor = Vendor.query.filter_by(vendor_name=vendor[:20]).one()
        except NoResultFound:
            vendor = Vendor(vendor)
            db_session.add(vendor)
            try:
                db_session.flush()
            except DataError:  # TODO mail this to the admins
                raise
            except IntegrityError, e:
                print str(e)

        sp = SubmissionPackage(submission.sub_id, date.today(), name, version,
                               release, epoch, arch, vendor.vendor_name,
                               status)
        db_session.add(sp)

    try:
        db_session.commit()
    except DataError:  # TODO mail this to the admins
        raise


def _can_submit(system):
    """Checks the Submission interval for this System

    :system: a System object

    If the interval has elapsed or there are no previous submissions, it
    will return True, otherwise returns False.
Beispiel #28
0
def parse_text(data):
    """Parse a plaintext submission, recording everything in the database"""
    datalines = data.splitlines()
    (popcorn, version, distro, distrover, arch, hw_uuid) = datalines[0].split()

    # we only use the underscore to make transporting easier, they
    # shouldn't be there otherwise
    distro = distro.replace('_', ' ')

    try:
        system = System.query.filter_by(sys_hwuuid=hw_uuid).one()
    except NoResultFound:
        system = System(hw_uuid)
        db_session.add(system)
    else:
        # TODO: think about moving this to the model
        if not _can_submit(system):
            raise EarlySubmissionError(system.last_sub_date)
        system.last_sub_date = date.today()

    submission = Submission(distro, distrover, arch, version)

    try:
        Arch.query.filter_by(arch=arch).one()
    except NoResultFound:
        raise FormatError("unknown arch - " + arch)

    try:
        Distro.query.filter_by(distro_name=distro,
                               distro_version=distrover).one()
    except NoResultFound:
        distro = Distro(distro, distrover)
        db_session.add(distro)

    db_session.add(submission)
    db_session.flush()

    for line in datalines[1:]:
        try:
            (status, name, version, release,
             epoch, arch, vendor) = line.split(None, 6)
        except ValueError, e:  # test this
            raise FormatError(e.message)

        try:
            status = {'v': 'voted',
                      'r': 'recent',
                      'o': 'old',
                      'n': 'nofiles'}[status]
        except KeyError:
            raise FormatError("the package's status could not be recognized")

        try:
            vendor = Vendor.query.filter_by(vendor_name=vendor[:20]).one()
        except NoResultFound:
            vendor = Vendor(vendor)
            db_session.add(vendor)
            try:
                db_session.flush()
            except DataError:  # TODO mail this to the admins
                raise
            except IntegrityError, e:
                print str(e)