def setUp(self): super(TestUsersService, self).setUp() session = DBSession() user = User(name=u'bodhi') session.add(user) session.flush()
def test_post_json_comment(self): self.app.post_json('/comments/', self.make_comment(text='awesome')) session = DBSession() up = session.query(Update).filter_by(title='bodhi-2.0-1.fc17').one() session.close() self.assertEquals(len(up.comments), 3) self.assertEquals(up.comments[-1]['text'], 'awesome')
def upgrade(): engine = op.get_bind() DBSession.configure(bind=engine) Base.metadata.bind = engine # Add the new columns op.add_column('releases', sa.Column('stable_tag', sa.UnicodeText())) op.add_column('releases', sa.Column('testing_tag', sa.UnicodeText())) op.add_column('releases', sa.Column('candidate_tag', sa.UnicodeText())) op.add_column('releases', sa.Column('pending_testing_tag', sa.UnicodeText())) op.add_column('releases', sa.Column('pending_stable_tag', sa.UnicodeText())) op.add_column('releases', sa.Column('override_tag', sa.UnicodeText())) # Add values for all releases in those new columns with transaction.manager: for r in DBSession.query(Release): r.stable_tag = "%s-updates" % r.dist_tag r.testing_tag = "%s-testing" % r.stable_tag r.candidate_tag = "%s-candidate" % r.stable_tag r.pending_testing_tag = "%s-pending" % r.testing_tag r.pending_stable_tag = "%s-pending" % r.stable_tag r.override_tag = "%s-override" % r.dist_tag # Now make the new columns not-nullable op.alter_column('releases', 'stable_tag', nullable=False) op.alter_column('releases', 'testing_tag', nullable=False) op.alter_column('releases', 'candidate_tag', nullable=False) op.alter_column('releases', 'pending_testing_tag', nullable=False) op.alter_column('releases', 'pending_stable_tag', nullable=False) op.alter_column('releases', 'override_tag', nullable=False) # And drop the old columns op.drop_column('releases', '_stable_tag') op.drop_column('releases', '_testing_tag') op.drop_column('releases', '_candidate_tag')
def setUp(self): engine = create_engine(DB_PATH) DBSession.configure(bind=engine) Base.metadata.create_all(engine) self.db = DBSession() populate(self.db) # Initialize our temporary repo self.tempdir = tempfile.mkdtemp("bodhi") self.temprepo = join(self.tempdir, "f17-updates-testing") mkmetadatadir(join(self.temprepo, "f17-updates-testing", "i386")) self.repodata = join(self.temprepo, "f17-updates-testing", "i386", "repodata") assert exists(join(self.repodata, "repomd.xml")) DevBuildsys.__rpms__ = [ { "arch": "src", "build_id": 6475, "buildroot_id": 1883, "buildtime": 1178868422, "epoch": None, "id": 62330, "name": "bodhi", "nvr": "bodhi-2.0-1.fc17", "release": "1.fc17", "size": 761742, "version": "2.0", } ]
def setUp(self): fd, self.db_filename = tempfile.mkstemp(prefix='bodhi-testing-', suffix='.db') db_path = 'sqlite:///%s' % self.db_filename # The BUILD_ID environment variable is set by Jenkins and allows us to # detect if # we are running the tests in jenkins or not # https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-below if os.environ.get('BUILD_ID'): faitout = 'http://209.132.184.152/faitout/' try: import requests req = requests.get('%s/new' % faitout) if req.status_code == 200: db_path = req.text print 'Using faitout at: %s' % db_path except: pass engine = create_engine(db_path) DBSession.configure(bind=engine) Base.metadata.create_all(engine) self.db_factory = transactional_session_maker with self.db_factory() as session: populate(session) assert session.query(Update).count() == 1 self.koji = buildsys.get_session() self.koji.clear() # clear out our dev introspection self.msg = makemsg() self.tempdir = tempfile.mkdtemp('bodhi') self.masher = Masher(FakeHub(), db_factory=self.db_factory, mash_dir=self.tempdir)
def test_filter_by_like(self): """ Test that filtering by like returns one package and not the other. """ DBSession.add(Package(name='a_second_package')) resp = self.app.get('/packages/', dict(like='odh')) body = resp.json_body self.assertEquals(len(body['packages']), 1)
def test_create_override_for_newer_build(self, publish): session = DBSession() old_build = Build.get(u'bodhi-2.0-1.fc17', session) build = Build(nvr=u'bodhi-2.0-2.fc17', package=old_build.package, release=old_build.release) session.add(build) session.flush() expiration_date = datetime.utcnow() + timedelta(days=1) data = {'nvr': build.nvr, 'notes': u'blah blah blah', 'expiration_date': expiration_date, 'csrf_token': self.get_csrf_token()} res = self.app.post('/overrides/', data) publish.assert_any_call(topic='buildroot_override.tag', msg=mock.ANY) publish.assert_any_call( topic='buildroot_override.untag', msg=mock.ANY) o = res.json_body self.assertEquals(o['build_id'], build.id) self.assertEquals(o['notes'], 'blah blah blah') self.assertEquals(o['expiration_date'], expiration_date.strftime("%Y-%m-%d %H:%M:%S")) self.assertEquals(o['expired_date'], None) old_build = Build.get(u'bodhi-2.0-1.fc17', session) self.assertNotEquals(old_build.override['expired_date'], None)
def test_cannot_edit_override_build(self, publish): session = DBSession() release = Release.get(u'F17', session) old_nvr = u'bodhi-2.0-1.fc17' res = self.app.get('/overrides/%s' % old_nvr) o = res.json_body['override'] expiration_date = o['expiration_date'] old_build_id = o['build_id'] build = Build(nvr=u'bodhi-2.0-2.fc17', release=release) session.add(build) session.flush() o.update({ 'nvr': build.nvr, 'edited': old_nvr, 'csrf_token': self.get_csrf_token(), }) res = self.app.post('/overrides/', o) override = res.json_body self.assertEquals(override['build_id'], old_build_id) self.assertEquals(override['notes'], 'blah blah blah') self.assertEquals(override['expiration_date'], expiration_date) self.assertEquals(override['expired_date'], None) self.assertEquals(len(publish.call_args_list), 0)
def test_unexpire_override(self, publish): session = DBSession() # First expire a buildroot override old_nvr = u'bodhi-2.0-1.fc17' override = Build.get(old_nvr, session).override override.expire() session.add(override) session.flush() publish.assert_called_once_with( topic='buildroot_override.untag', msg=mock.ANY) publish.reset_mock() # And now push its expiration_date into the future res = self.app.get('/overrides/%s' % old_nvr) o = res.json_body['override'] expiration_date = datetime.now() + timedelta(days=1) expiration_date = expiration_date.strftime("%Y-%m-%d %H:%M:%S") o.update({'nvr': o['build']['nvr'], 'edited': old_nvr, 'expiration_date': expiration_date, 'csrf_token': self.get_csrf_token()}) res = self.app.post('/overrides/', o) override = res.json_body self.assertEquals(override['build'], o['build']) self.assertEquals(override['notes'], o['notes']) self.assertEquals(override['expiration_date'], o['expiration_date']) self.assertEquals(override['expired_date'], None) publish.assert_called_once_with( topic='buildroot_override.tag', msg=mock.ANY)
def tearDown(self): log.debug('Removing session') DBSession.remove() if DB_NAME: try: import requests requests.get('%s/clean/%s' % (FAITOUT, DB_NAME)) except: pass
def test_list_overrides_by_username_without_override(self): session = DBSession() session.add(User(name=u'bochecha')) session.flush() res = self.app.get('/overrides/', {'user': '******'}) body = res.json_body self.assertEquals(len(body['overrides']), 0)
def tearDown(self): shutil.rmtree(self.tempdir) try: DBSession.remove() finally: try: os.remove(self.db_filename) except: pass
def test_list_comments_by_update_owner_with_none(self): session = DBSession() user = User(name=u'ralph') session.add(user) session.flush() res = self.app.get('/comments/', {"update_owner": "ralph"}) body = res.json_body self.assertEquals(len(body['comments']), 0) self.assertNotIn('errors', body)
def test_list_overrides_by_packages_without_override(self): session = DBSession() session.add(Package(name=u'python')) session.flush() res = self.app.get('/overrides/', {'packages': 'python'}) body = res.json_body self.assertEquals(len(body['overrides']), 0)
def downgrade(): engine = op.get_bind() DBSession.configure(bind=engine) Base.metadata.bind = engine with transaction.manager: updates = DBSession.query(Update) for u in updates: u.critpath = None
def test_list_releases_by_update_alias(self): session = DBSession() update = session.query(Update).first() update.alias = u'some_alias' session.flush() res = self.app.get('/releases/', {"updates": 'some_alias'}) body = res.json_body self.assertEquals(len(body['releases']), 1) self.assertEquals(body['releases'][0]['name'], 'F17')
def upgrade(): engine = op.get_bind() DBSession.configure(bind=engine) Base.metadata.bind = engine with transaction.manager: updates = DBSession.query(Update) for u in updates: if u.suggest is None: u.suggest = UpdateSuggestion.unspecified
def upgrade(): op.add_column('releases', sa.Column('branch', sa.Unicode(length=10))) op.create_unique_constraint(None, 'releases', ['branch']) engine = op.get_bind() DBSession.configure(bind=engine) Base.metadata.bind = engine with transaction.manager: for release in DBSession.query(Release).all(): release.branch = release.name.lower()
def upgrade(): engine = op.get_bind() DBSession.configure(bind=engine) Base.metadata.bind = engine with transaction.manager: updates = DBSession.query(Update) for u in updates: if u.pushed is None: u.pushed = False
def setUp(self): engine = create_engine(DB_PATH) DBSession.configure(bind=engine) log.debug('Creating all models for %s' % engine) Base.metadata.create_all(engine) self.db = DBSession() populate(self.db) self.app = TestApp(main({}, testing=u'guest', **self.app_settings)) # Track sql statements in every test self.sql_statements = [] def track(conn, cursor, statement, param, ctx, many): self.sql_statements.append(statement) event.listen(engine, "before_cursor_execute", track)
def setUp(self): super(TestReleasesService, self).setUp() session = DBSession() release = Release( name=u'F22', long_name=u'Fedora 22', id_prefix=u'FEDORA', version=u'22', dist_tag=u'f22', stable_tag=u'f22-updates', testing_tag=u'f22-updates-testing', candidate_tag=u'f22-updates-candidate', pending_testing_tag=u'f22-updates-testing-pending', pending_stable_tag=u'f22-updates-pending', override_tag=u'f22-override', branch=u'f22') session.add(release) session.flush()
def test_list_overrides_by_releases_without_override(self): session = DBSession() session.add(Release(name=u'F42', long_name=u'Fedora 42', id_prefix=u'FEDORA', version=u'42', dist_tag=u'f42', stable_tag=u'f42-updates', testing_tag=u'f42-updates-testing', candidate_tag=u'f42-updates-candidate', pending_testing_tag=u'f42-updates-testing-pending', pending_stable_tag=u'f42-updates-pending', override_tag=u'f42-override', branch=u'f42')) session.flush() res = self.app.get('/overrides/', {'releases': 'F42'}) body = res.json_body self.assertEquals(len(body['overrides']), 0)
def test_create_override(self, publish): session = DBSession() release = Release.get(u'F17', session) package = Package(name=u'not-bodhi') session.add(package) build = Build(nvr=u'not-bodhi-2.0-2.fc17', package=package, release=release) session.add(build) session.flush() expiration_date = datetime.utcnow() + timedelta(days=1) data = {'nvr': build.nvr, 'notes': u'blah blah blah', 'expiration_date': expiration_date, 'csrf_token': self.get_csrf_token()} res = self.app.post('/overrides/', data) publish.assert_called_once_with( topic='buildroot_override.tag', msg=mock.ANY) self.assertEquals(len(publish.call_args_list), 1) o = res.json_body self.assertEquals(o['build_id'], build.id) self.assertEquals(o['notes'], 'blah blah blah') self.assertEquals(o['expiration_date'], expiration_date.strftime("%Y-%m-%d %H:%M:%S")) self.assertEquals(o['expired_date'], None)
def test_no_self_karma(self): " Make sure you can't give +1 karma to your own updates.. " comment = self.make_comment('bodhi-2.0-1.fc17', karma=1) # The author of this comment is "guest" session = DBSession() up = session.query(Update).filter_by(title='bodhi-2.0-1.fc17').one() self.assertEquals(up.user.name, 'guest') r = self.app.post_json('/comments/', comment) comment = r.json_body['comment'] self.assertEquals(comment['user']['name'], u'guest') self.assertEquals(comment['update']['title'], u'bodhi-2.0-1.fc17') caveats = r.json_body['caveats'] self.assertEquals(len(caveats), 1) self.assertEquals(caveats[0]['name'], 'karma') self.assertEquals(caveats[0]['description'], "You may not give karma to your own updates.") self.assertEquals(comment['karma'], 0) # This is the real check
def test_list_builds_pagination(self): # First, stuff a second build in there session = DBSession() build = Build(nvr=u'bodhi-3.0-1.fc21') session.add(build) session.flush() # Then, test pagination res = self.app.get('/builds/', {"rows_per_page": 1}) body = res.json_body self.assertEquals(len(body['builds']), 1) build1 = body['builds'][0] res = self.app.get('/builds/', {"rows_per_page": 1, "page": 2}) body = res.json_body self.assertEquals(len(body['builds']), 1) build2 = body['builds'][0] self.assertNotEquals(build1, build2)
def __init__(self, hub, db_factory=None, *args, **kwargs): if not db_factory: config_uri = "/etc/bodhi/production.ini" self.settings = get_appsettings(config_uri) engine = engine_from_config(self.settings, "sqlalchemy.") DBSession.configure(bind=engine) Base.metadata.create_all(engine) self.db_factory = transactional_session_maker else: self.db_factory = db_factory prefix = hub.config.get("topic_prefix") env = hub.config.get("environment") self.topic = [prefix + "." + env + ".bodhi.update.request.testing", prefix + "." + env + ".bodhi.update.edit"] self.handle_bugs = bool(self.settings.get("bodhi_email")) if not self.handle_bugs: log.warn("No bodhi_email defined; not fetching bug details") super(UpdatesHandler, self).__init__(hub, *args, **kwargs) log.info("Bodhi updates handler listening on:\n" "%s" % pprint.pformat(self.topic))
def upgrade(): engine = op.get_bind() DBSession.configure(bind=engine) Base.metadata.bind = engine critpath_pkgs = {} for release in DBSession.query(Release): relname = release.name critpath_pkgs[relname] = sorted(get_critpath_pkgs(relname.lower())) with transaction.manager: updates = DBSession.query(Update) for up in updates: for build in up.builds: if build.package.name in critpath_pkgs[up.release.name]: up.critpath = True break else: up.critpath = False
def test_list_comments_by_update_no_comments(self): session = DBSession() update = Update( title=u'bodhi-2.0-200.fc17', #builds=[build], #user=user, request=UpdateRequest.testing, type=UpdateType.enhancement, notes=u'Useful details!', #release=release, date_submitted=datetime(1984, 11, 02), requirements=u'rpmlint', stable_karma=3, unstable_karma=-3, ) session.add(update) session.flush() res = self.app.get('/comments/', {"updates": "bodhi-2.0-200.fc17"}) body = res.json_body self.assertEquals(len(body['comments']), 0)
def setup(self): engine = create_engine('sqlite://') DBSession.configure(bind=engine) Base.metadata.create_all(engine) try: new_attrs = {} new_attrs.update(self.attrs) new_attrs.update(self.do_get_dependencies()) self.obj = self.klass(**new_attrs) DBSession.add(self.obj) DBSession.flush() return self.obj except: DBSession.rollback() raise
def downgrade(): engine = op.get_bind() DBSession.configure(bind=engine) Base.metadata.bind = engine # Add the old columns op.add_column('releases', sa.Column('_stable_tag', sa.UnicodeText())) op.add_column('releases', sa.Column('_testing_tag', sa.UnicodeText())) op.add_column('releases', sa.Column('_candidate_tag', sa.UnicodeText())) with transaction.manager: for r in DBSession.query(Release): r._stable_tag = r.stable_tag r._testing_tag = r.testing_tag r._candidate_tag = r.candidate_tag # And drop the new columns op.drop_column('releases', 'stable_tag') op.drop_column('releases', 'testing_tag') op.drop_column('releases', 'candidate_tag') op.drop_column('releases', 'pending_testing_tag') op.drop_column('releases', 'pending_stable_tag') op.drop_column('releases', 'override_tag')