def test_getBuildrootOverrides(self): """Testing getBuildOverrides query.""" release = models.Release.get('F17') package = models.RpmPackage(name='just-testing') self.db.add(package) build = models.RpmBuild(nvr='just-testing-1.0-2.fc17', package=package, release=release) self.db.add(build) another_user = models.User(name='aUser') self.db.add(another_user) expiration_date = datetime.datetime(2020, 10, 13, 16, 16, 22, 438484) submission_date = datetime.datetime(2020, 10, 12, 16, 16, 22, 438484) override = models.BuildrootOverride(build=build, submitter=another_user, notes='Crazy! 😱', expiration_date=expiration_date, submission_date=submission_date) self.db.add(override) self.db.flush() client = Client(schema) self.db.commit() executed = client.execute("""{ getBuildrootOverrides(buildNvr: "just-testing-1.0-2.fc17") { submissionDate expirationDate }}""") assert executed == { 'data': { 'getBuildrootOverrides': [{ 'expirationDate': "2020-10-13T16:16:22.438484", 'submissionDate': "2020-10-12T16:16:22.438484", }] } } executed = client.execute("""{ getBuildrootOverrides(submissionDate: "2020-10-12T16:16:22.438484", expirationDate: "2020-10-13T16:16:22.438484") { notes }}""") assert executed == { 'data': { 'getBuildrootOverrides': [{ 'notes': "Crazy! 😱" }] } } executed = client.execute("""{ getBuildrootOverrides(submitterUsername: "******", expirationDate: "2020-10-13T16:16:22.438484") { notes }}""") assert executed == { 'data': { 'getBuildrootOverrides': [{ 'notes': "Crazy! 😱" }] } }
def setUp(self): """ Set up an archived release with an Update so we can test the filtering. """ super(TestFilterReleases, self).setUp() self.user = self.db.query(models.User).all()[0] archived_release = models.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_signing_tag=u'f22-updates-testing-signing', pending_testing_tag=u'f22-updates-testing-pending', pending_stable_tag=u'f22-updates-pending', override_tag=u'f22-override', branch=u'f22', state=models.ReleaseState.archived) self.db.add(archived_release) # Let's add an obscure package called bodhi to the release. pkg = self.db.query(models.RpmPackage).filter_by(name=u'bodhi').one() build = models.RpmBuild(nvr=u'bodhi-2.3.2-1.fc22', release=archived_release, package=pkg) self.db.add(build) # And an Update with the RpmBuild. self.archived_release_update = models.Update( title=u'bodhi-2.3.2-1.fc22', builds=[build], user=self.user, request=models.UpdateRequest.stable, notes=u'Useful details!', release=archived_release, date_submitted=datetime(2016, 10, 28), requirements=u'', stable_karma=3, unstable_karma=-3, type=models.UpdateType.bugfix) self.db.add(self.archived_release_update) self.db.commit() test_config = base.original_config.copy() test_config['mash_dir'] = '/mashdir/' mock_config = mock.patch.dict('bodhi.server.push.config', test_config) mock_config.start() self.addCleanup(mock_config.stop)
def test_bad_update_doesnt_block_others(self, remove): """ Assert that one bad update in the set of batched updates doesn't block the others. """ runner = testing.CliRunner() update_1 = models.Update.query.first() update_1_title = update_1.title update_1.request = models.UpdateRequest.batched update_1.locked = False update_1.date_testing = datetime.utcnow() - timedelta(days=7) build_2 = models.RpmBuild(nvr='bodhi-3.1.0-1.fc17', package=update_1.builds[0].package) self.db.add(build_2) update_2 = models.Update(title=build_2.nvr, builds=[build_2], type=models.UpdateType.enhancement, notes='blah', status=models.UpdateStatus.testing, request=models.UpdateRequest.batched, user=update_1.user, release=update_1.release) update_2_title = update_2.title self.db.add(update_2) self.db.commit() result = runner.invoke(dequeue_stable.dequeue_stable, []) self.assertEqual(result.exit_code, 0) self.assertTrue(config.config['not_yet_tested_msg'] in result.output) self.assertEqual( models.Update.query.filter_by(title=update_1_title).one().request, models.UpdateRequest.stable) # set_request() rejected this update since it hasn't met testing requirements. self.assertEqual( models.Update.query.filter_by(title=update_2_title).one().request, models.UpdateRequest.batched) # It should also have received a stern comment from Bodhi. c = models.Update.query.filter_by( title=update_2_title).one().comments[-1] self.assertEqual(c.user.name, 'bodhi') self.assertEqual( c.text, 'Bodhi is unable to request this update for stabilization: {}'. format(config.config['not_yet_tested_msg'])) remove.assert_called_once_with()
def test_defaults_to_filtering_correct_releases(self): """ Ensure that _filter_releases() filters out archived and disabled releases by default. """ # To make sure the filter is skipping and including the right stuff, let's add a disabled # release and a pending release. Builds from the disabled one should be exlcuded and the # pending one should be included. disabled_release = models.Release( name=u'F21', long_name=u'Fedora 21', id_prefix=u'FEDORA', version=u'21', dist_tag=u'f21', stable_tag=u'f21-updates', testing_tag=u'f21-updates-testing', candidate_tag=u'f21-updates-candidate', pending_signing_tag=u'f21-updates-testing-signing', pending_testing_tag=u'f21-updates-testing-pending', pending_stable_tag=u'f21-updates-pending', override_tag=u'f21-override', branch=u'f21', state=models.ReleaseState.disabled) pending_release = models.Release( name=u'F25', long_name=u'Fedora 25', id_prefix=u'FEDORA', version=u'25', dist_tag=u'f25', stable_tag=u'f25-updates', testing_tag=u'f25-updates-testing', candidate_tag=u'f25-updates-candidate', pending_signing_tag=u'f25-updates-testing-signing', pending_testing_tag=u'f25-updates-testing-pending', pending_stable_tag=u'f25-updates-pending', override_tag=u'f25-override', branch=u'f25', state=models.ReleaseState.pending) self.db.add(disabled_release) self.db.add(pending_release) # Let's add the bodhi package to both releases. pkg = self.db.query(models.RpmPackage).filter_by(name=u'bodhi').one() disabled_build = models.RpmBuild(nvr=u'bodhi-2.3.2-1.fc21', release=disabled_release, package=pkg) pending_build = models.RpmBuild(nvr=u'bodhi-2.3.2-1.fc25', release=pending_release, package=pkg) self.db.add(disabled_build) self.db.add(pending_build) # Now let's create updates for both packages. disabled_release_update = models.Update( title=u'bodhi-2.3.2-1.fc21', builds=[disabled_build], user=self.user, request=models.UpdateRequest.stable, notes=u'Useful details!', release=disabled_release, date_submitted=datetime(2016, 10, 28), requirements=u'', stable_karma=3, unstable_karma=-3, type=models.UpdateType.bugfix) pending_release_update = models.Update( title=u'bodhi-2.3.2-1.fc25', builds=[pending_build], user=self.user, request=models.UpdateRequest.stable, notes=u'Useful details!', release=pending_release, date_submitted=datetime(2016, 10, 28), requirements=u'', stable_karma=3, unstable_karma=-3, type=models.UpdateType.bugfix) self.db.add(disabled_release_update) self.db.add(pending_release_update) self.db.commit() query = self.db.query(models.Update) query = push._filter_releases(self.db, query) # Make sure the archived update didn't get in this business self.assertEqual(set([u.release.state for u in query]), set([models.ReleaseState.current, models.ReleaseState.pending]))
def create_update(session, build_nvrs, release_name='F17'): """ Use the given session to create and return an Update with the given iterable of build_nvrs. Each build_nvr should be a string describing the name, version, and release for the build separated by dashes. For example, build_nvrs might look like this: ('bodhi-2.3.3-1.fc24', 'python-fedora-atomic-composer-2016.3-1.fc24') You can optionally pass a release_name to select a different release than the default F17, but the release must already exist in the database. Args: build_nvrs (iterable): An iterable of strings of NVRs to put into the update. release_name (str): The name of the release to associate with the update. Returns: bodhi.server.models.Update: The generated update. """ release = session.query(models.Release).filter_by(name=release_name).one() user = session.query(models.User).filter_by(name='guest').one() builds = [] for nvr in build_nvrs: name, version, rel = nvr.rsplit('-', 2) try: package = session.query( models.RpmPackage).filter_by(name=name).one() except NoResultFound: package = models.RpmPackage(name=name) session.add(package) try: testcase = session.query( models.TestCase).filter_by(name='Wat').one() except NoResultFound: testcase = models.TestCase(name='Wat') session.add(testcase) build = models.RpmBuild(nvr=nvr, release=release, package=package, signed=True) build.testcases.append(testcase) builds.append(build) session.add(build) # Add a buildroot override for this build expiration_date = datetime.utcnow() expiration_date = expiration_date + timedelta(days=1) override = models.BuildrootOverride(build=build, submitter=user, notes='blah blah blah', expiration_date=expiration_date) session.add(override) update = models.Update(builds=builds, user=user, request=models.UpdateRequest.testing, notes='Useful details!', type=models.UpdateType.bugfix, date_submitted=datetime(1984, 11, 2), requirements='rpmlint', stable_karma=3, unstable_karma=-3, release=release) session.add(update) return update