def test_edited_update_bug_not_in_update(self, work_on_bugs, fetch_test_cases, sleep): """ Test with a message that indicates that the update is being edited, and the list of bugs contains one that UpdatesHandler does not find in the update. """ bug = models.Bug(bug_id=123456) self.db.add(bug) self.db.commit() h = updates.UpdatesHandler() h.db_factory = base.TransactionalSessionMaker(self.Session) update = models.Build.query.filter_by(nvr='bodhi-2.0-1.fc17').one().update message = Message( topic='bodhi.update.edit', body={'msg': {'update': {'alias': update.alias}, 'new_bugs': ['12345', '123456']}} ) h(message) self.assertEqual(work_on_bugs.call_count, 1) self.assertTrue(isinstance(work_on_bugs.mock_calls[0][1][0], sqlalchemy.orm.session.Session)) self.assertEqual(work_on_bugs.mock_calls[0][1][1].title, 'bodhi-2.0-1.fc17') self.assertEqual([b.bug_id for b in work_on_bugs.mock_calls[0][1][2]], [12345, 123456]) self.assertEqual(fetch_test_cases.call_count, 1) self.assertTrue(isinstance(fetch_test_cases.mock_calls[0][1][0], sqlalchemy.orm.session.Session)) sleep.assert_called_once_with(1) # Bug with id '123456' should be attached to update bug = models.Bug.query.filter_by(bug_id=123456).one() update = models.Build.query.filter_by(nvr='bodhi-2.0-1.fc17').one().update self.assertIn(bug, update.bugs)
def populate(db): """ Create some data for tests to use. Args: db (sqlalchemy.orm.session.Session): The database session. """ user = models.User(name='guest') db.add(user) anonymous = models.User(name='anonymous') db.add(anonymous) provenpackager = models.Group(name='provenpackager') db.add(provenpackager) packager = models.Group(name='packager') db.add(packager) user.groups.append(packager) release = models.Release(name='F17', long_name='Fedora 17', id_prefix='FEDORA', version='17', dist_tag='f17', stable_tag='f17-updates', testing_tag='f17-updates-testing', candidate_tag='f17-updates-candidate', pending_signing_tag='f17-updates-signing-pending', pending_testing_tag='f17-updates-testing-pending', pending_stable_tag='f17-updates-pending', override_tag='f17-override', branch='f17', state=models.ReleaseState.current, create_automatic_updates=True, package_manager=models.PackageManager.unspecified, testing_repository=None) db.add(release) db.flush() # This mock will help us generate a consistent update alias. with mock.patch(target='uuid.uuid4', return_value='wat'): update = create_update(db, ['bodhi-2.0-1.fc17']) update.type = models.UpdateType.bugfix update.severity = models.UpdateSeverity.medium bug = models.Bug(bug_id=12345) db.add(bug) update.bugs.append(bug) comment = models.Comment(karma=1, text="wow. amaze.") db.add(comment) comment.user = user update.comments.append(comment) comment = models.Comment(karma=0, text="srsly. pretty good.") comment.user = anonymous db.add(comment) update.comments.append(comment) db.add(update) db.commit()
def test_update_details_keywords_str(self): """Assert that we split the keywords into a list when they are a str.""" bz = bugs.Bugzilla() bz._bz = mock.MagicMock() bug = mock.MagicMock() bug.keywords = 'some words but sEcuriTy is in the middle of them' bug_entity = models.Bug() bz.update_details(bug, bug_entity) self.assertTrue(bug_entity.security)
def test_edited_update_bug_not_in_update(self, work_on_bugs, fetch_test_cases, sleep): """ Test an update edition when the list of bugs contains one that UpdatesHandler does not find in the update. """ bug = models.Bug(bug_id=123456) self.db.add(bug) self.db.commit() h = updates.UpdatesHandler() h.db_factory = base.TransactionalSessionMaker(self.Session) update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update h.run(api_version=1, data={ 'action': 'edit', 'update': { 'alias': update.alias, 'builds': [{ 'nvr': 'bodhi-2.0-1.fc17' }], 'user': { 'name': 'brodhi' }, 'status': str(update.status), 'request': str(update.request) }, 'new_bugs': [12345, 123456] }) self.assertEqual(work_on_bugs.call_count, 1) self.assertTrue( isinstance(work_on_bugs.mock_calls[0][1][0], sqlalchemy.orm.session.Session)) self.assertEqual(work_on_bugs.mock_calls[0][1][1].title, 'bodhi-2.0-1.fc17') self.assertEqual([b.bug_id for b in work_on_bugs.mock_calls[0][1][2]], [12345, 123456]) self.assertEqual(fetch_test_cases.call_count, 1) self.assertTrue( isinstance(fetch_test_cases.mock_calls[0][1][0], sqlalchemy.orm.session.Session)) sleep.assert_called_once_with(1) # Bug with id '123456' should be attached to update bug = models.Bug.query.filter_by(bug_id=123456).one() update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update self.assertIn(bug, update.bugs)
def test_bug_not_associated_to_update(self, modified): """Test that a bug is added to the update if not already associated.""" bug = models.Bug(bug_id=123456) self.db.add(bug) self.db.commit() update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update work_on_bugs_main(update.alias, [ 123456, ]) bug = models.Bug.query.filter_by(bug_id=123456).one() update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update assert bug in update.bugs assert modified.assert_called_once
def test_edited_update_bug_not_in_update(self, work_on_bugs, fetch_test_cases): """ Test an update edition when the list of bugs contains one that UpdatesHandler does not find in the update. """ bug = models.Bug(bug_id=123456) self.db.add(bug) self.db.commit() update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update self.h.run(api_version=1, data={ 'action': 'edit', 'update': { 'alias': update.alias, 'builds': [{ 'nvr': 'bodhi-2.0-1.fc17' }], 'user': { 'name': 'brodhi' }, 'status': str(update.status), 'request': str(update.request) }, 'new_bugs': [12345, 123456] }) assert work_on_bugs.call_count == 1 assert isinstance(work_on_bugs.mock_calls[0][1][0], sqlalchemy.orm.session.Session) assert work_on_bugs.mock_calls[0][1][1].title == 'bodhi-2.0-1.fc17' assert [b.bug_id for b in work_on_bugs.mock_calls[0][1][2]] == [12345, 123456] assert fetch_test_cases.call_count == 1 assert isinstance(fetch_test_cases.mock_calls[0][1][0], sqlalchemy.orm.session.Session) # Bug with id '123456' should be attached to update bug = models.Bug.query.filter_by(bug_id=123456).one() update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update assert bug in update.bugs
def test_skip_tracker_bug(self, debug): """Tracker security bugs should get skipped.""" u = models.Update.query.first() u.type = models.UpdateType.security b = u.bugs[0] b.parent = False b.title = 'this should not appear' u.bugs.append(models.Bug(bug_id=54321, parent=True, title='this should appear')) t = mail.get_template(u) # Assemble the template for easier asserting. t = '\n'.join([l for l in t[0]]) self.assertTrue('54321 - this should appear' in t) self.assertFalse('this should not appear' in t) self.assertEqual(debug.call_count, 1) self.assertIn('Skipping tracker bug', debug.mock_calls[0][1][0]) self.assertIn('12345', debug.mock_calls[0][1][0]) self.assertIn('this should not appear', debug.mock_calls[0][1][0])
def test_api_version_2(self, work_on_bugs, fetch_test_cases): """Test API version 2""" bug = models.Bug(bug_id=123456) self.db.add(bug) self.db.commit() h = updates.UpdatesHandler() h.db_factory = base.TransactionalSessionMaker(self.Session) update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update h.run(api_version=2, data={ 'action': 'testing', 'update_alias': update.alias, }) assert work_on_bugs.call_count == 1 called_update = work_on_bugs.mock_calls[0][1][1] assert called_update.title == 'bodhi-2.0-1.fc17' assert fetch_test_cases.call_count == 1 called_update = fetch_test_cases.mock_calls[0][1][1] assert called_update.title == 'bodhi-2.0-1.fc17'