def test_use_existing_milestone(self): # Test that existing milestones are returned by getMilestone(). product = getUtility(IProductSet).getByName('firefox') one_point_zero = product.getMilestone('1.0') self.assertNotEqual(one_point_zero, None) importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle') milestone = importer.getMilestone('1.0') self.assertEqual(one_point_zero, milestone)
def test_create_milestone(self): # Test that getMilestone() can create new milestones. product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle') milestone = importer.getMilestone('foo-bar') self.assertEqual(milestone.name, 'foo-bar') self.assertEqual(milestone.product, product) self.assertEqual(milestone.productseries, product.development_focus)
def test_nobody_person(self): # Test that BugImporter.getPerson() returns None where appropriate product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle') self.assertEqual(importer.getPerson(None), None) personnode = ET.fromstring('''\ <person xmlns="https://launchpad.net/xmlns/2006/bugs" name="nobody" />''') self.assertEqual(importer.getPerson(personnode), None)
def test_find_existing_person(self): # Test that getPerson() returns an existing person. person = self.factory.makePerson(email='*****@*****.**') product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle') personnode = ET.fromstring('''\ <person xmlns="https://launchpad.net/xmlns/2006/bugs" name="mark" email="*****@*****.**">Foo User</person>''') self.assertEqual(importer.getPerson(personnode), person)
def test_load_no_cache(self): # Test that loadCache() when no cache file exists resets the # bug ID map and pending duplicates lists. cache_filename = os.path.join(self.tmpdir, 'bug-map.pickle') self.assertFalse(os.path.exists(cache_filename)) importer = bugimport.BugImporter(None, None, cache_filename) importer.bug_id_map = 'bogus' importer.pending_duplicates = 'bogus' importer.loadCache() self.assertEqual(importer.bug_id_map, {}) self.assertEqual(importer.pending_duplicates, {})
def test_public_security_bug(self): # Test that we can import a public security bug. # The createBug() method does not let us create such a bug # directly, so this checks that it works. product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle', verify_users=True) bugnode = ET.fromstring(public_security_bug) bug101 = importer.importBug(bugnode) self.assertNotEqual(bug101, None) self.assertEqual(bug101.private, False) self.assertEqual(bug101.security_related, True)
def test_load_cache(self): # Test that loadCache() restores the state set by saveCache(). cache_filename = os.path.join(self.tmpdir, 'bug-map.pickle') self.assertFalse(os.path.exists(cache_filename)) importer = bugimport.BugImporter(None, None, cache_filename) importer.bug_id_map = {42: 1, 100: 2} importer.pending_duplicates = {50: [1, 2]} importer.saveCache() self.assertTrue(os.path.exists(cache_filename)) importer.bug_id_map = 'bogus' importer.pending_duplicates = 'bogus' importer.loadCache() self.assertEqual(importer.bug_id_map, {42: 1, 100: 2}) self.assertEqual(importer.pending_duplicates, {50: [1, 2]})
def test_find_existing_person(self): # Test that getPerson() returns an existing person. person = getUtility(IPersonSet).getByEmail('*****@*****.**') self.assertEqual(person, None) person, email = getUtility(IPersonSet).createPersonAndEmail( email='*****@*****.**', rationale=PersonCreationRationale.OWNER_CREATED_LAUNCHPAD) self.assertNotEqual(person, None) product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle') personnode = ET.fromstring('''\ <person xmlns="https://launchpad.net/xmlns/2006/bugs" name="mark" email="*****@*****.**">Foo User</person>''') self.assertEqual(importer.getPerson(personnode), person)
def test_create_person_conflicting_name(self): # Test that getPerson() can correctly create new users when # they have a short name that conflicts with an existing user # in the database. person1 = getUtility(IPersonSet).getByName('mark') self.assertNotEqual(person1, None) product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle') personnode = ET.fromstring('''\ <person xmlns="https://launchpad.net/xmlns/2006/bugs" name="mark" email="*****@*****.**">Foo User</person>''') person2 = importer.getPerson(personnode) self.assertNotEqual(person2, None) self.assertNotEqual(person1.id, person2.id) self.assertNotEqual(person2.name, 'mark')
def test_verify_existing_person(self): # Test that getPerson() will validate the email of an existing # user when verify_users=True. person = self.factory.makePerson( email='*****@*****.**', account_status=AccountStatus.NOACCOUNT) self.assertEqual(person.preferredemail, None) product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle', verify_users=True) personnode = ET.fromstring('''\ <person xmlns="https://launchpad.net/xmlns/2006/bugs" name="foo" email="*****@*****.**">Foo User</person>''') person = importer.getPerson(personnode) self.assertNotEqual(person.preferredemail, None) self.assertEqual(person.preferredemail.email, '*****@*****.**')
def test_verify_doesnt_clobber_preferred_email(self): # Test that getPerson() does not clobber an existing verified # email address when verify_users=True. person = self.factory.makePerson(email='*****@*****.**') email = getUtility(IEmailAddressSet).new('*****@*****.**', person) person.setPreferredEmail(email) self.assertEqual(person.preferredemail.email, '*****@*****.**') product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle', verify_users=True) personnode = ET.fromstring('''\ <person xmlns="https://launchpad.net/xmlns/2006/bugs" name="foo" email="*****@*****.**">Foo User</person>''') person = importer.getPerson(personnode) self.assertNotEqual(person.preferredemail, None) self.assertEqual(person.preferredemail.email, '*****@*****.**')
def test_duplicate_bug(self): # Process two bugs, the second being a duplicate of the first. product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle', verify_users=True) bugnode = ET.fromstring(sample_bug) bug42 = importer.importBug(bugnode) self.assertNotEqual(bug42, None) bugnode = ET.fromstring(duplicate_bug) bug100 = importer.importBug(bugnode) self.assertNotEqual(bug100, None) self.assertEqual(bug100.duplicateof, bug42) self.assertNoPendingNotifications(bug100) self.assertNoPendingNotifications(bug42)
def test_verify_new_person(self): # Test that getPerson() creates new users with their preferred # email address set when verify_users=True. product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle', verify_users=True) personnode = ET.fromstring('''\ <person xmlns="https://launchpad.net/xmlns/2006/bugs" name="foo" email="*****@*****.**">Foo User</person>''') person = importer.getPerson(personnode) self.assertNotEqual(person, None) self.assertNotEqual(person.preferredemail, None) self.assertEqual(person.preferredemail.email, '*****@*****.**') self.assertEqual(person.creation_rationale, PersonCreationRationale.BUGIMPORT) self.assertEqual(person.creation_comment, 'when importing bugs for NetApplet')
def test_verify_existing_person(self): # Test that getPerson() will validate the email of an existing # user when verify_users=True. person, email = getUtility(IPersonSet).createPersonAndEmail( rationale=PersonCreationRationale.OWNER_CREATED_LAUNCHPAD, email='*****@*****.**') self.assertEqual(person.preferredemail, None) product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle', verify_users=True) personnode = ET.fromstring('''\ <person xmlns="https://launchpad.net/xmlns/2006/bugs" name="foo" email="*****@*****.**">Foo User</person>''') person = importer.getPerson(personnode) self.assertNotEqual(person.preferredemail, None) self.assertEqual(person.preferredemail.email, '*****@*****.**')
def test_verify_doesnt_clobber_preferred_email(self): # Test that getPerson() does not clobber an existing verified # email address when verify_users=True. person, email = getUtility(IPersonSet).createPersonAndEmail( '*****@*****.**', PersonCreationRationale.OWNER_CREATED_LAUNCHPAD) transaction.commit() self.failIf(person.account is None, 'Person must have an account.') email = getUtility(IEmailAddressSet).new('*****@*****.**', person) person.setPreferredEmail(email) transaction.commit() self.assertEqual(person.preferredemail.email, '*****@*****.**') product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle', verify_users=True) personnode = ET.fromstring('''\ <person xmlns="https://launchpad.net/xmlns/2006/bugs" name="foo" email="*****@*****.**">Foo User</person>''') person = importer.getPerson(personnode) self.assertNotEqual(person.preferredemail, None) self.assertEqual(person.preferredemail.email, '*****@*****.**')
def test_create_person(self): # Test that getPerson() can create new users. person = getUtility(IPersonSet).getByEmail('*****@*****.**') self.assertEqual(person, None) product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle') personnode = ET.fromstring('''\ <person xmlns="https://launchpad.net/xmlns/2006/bugs" name="foo" email="*****@*****.**">Foo User</person>''') person = importer.getPerson(personnode) # Commit as we just made changes to two different stores, and the # rest of these tests require the changes to be visible. transaction.commit() self.assertNotEqual(person, None) self.assertEqual(person.name, 'foo') self.assertEqual(person.displayname, 'Foo User') self.assertEqual(person.guessedemails.count(), 1) self.assertEqual(person.guessedemails[0].email, '*****@*****.**') self.assertEqual(person.creation_rationale, PersonCreationRationale.BUGIMPORT) self.assertEqual(person.creation_comment, 'when importing bugs for NetApplet')
def test_pending_duplicate_bug(self): # Same as above, but process the pending duplicate bug first. product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle', verify_users=True) bugnode = ET.fromstring(duplicate_bug) bug100 = importer.importBug(bugnode) self.assertNotEqual(bug100, None) self.assertTrue(42 in importer.pending_duplicates) self.assertEqual(importer.pending_duplicates[42], [bug100.id]) bugnode = ET.fromstring(sample_bug) bug42 = importer.importBug(bugnode) self.assertNotEqual(bug42, None) # bug 42 removed from pending duplicates self.assertTrue(42 not in importer.pending_duplicates) self.assertEqual(bug100.duplicateof, bug42) self.assertNoPendingNotifications(bug100) self.assertNoPendingNotifications(bug42)
def test_import_bug(self): # Test that various features of the bug are imported from the XML. product = getUtility(IProductSet).getByName('netapplet') importer = bugimport.BugImporter(product, 'bugs.xml', 'bug-map.pickle', verify_users=True) bugnode = ET.fromstring(sample_bug) bug = importer.importBug(bugnode) self.assertNotEqual(bug, None) # check bug attributes self.assertEqual(bug.owner.preferredemail.email, '*****@*****.**') self.assertEqual(bug.datecreated.isoformat(), '2004-10-12T12:00:00+00:00') self.assertEqual(bug.title, 'A test bug') self.assertEqual(bug.description, 'A modified bug description') self.assertEqual(bug.private, True) self.assertEqual(bug.security_related, True) self.assertEqual(bug.name, 'some-bug') self.assertEqual(sorted(cve.sequence for cve in bug.cves), ['2005-2730', '2005-2736', '2005-2737']) self.assertEqual(bug.tags, ['bar', 'foo']) self.assertEqual(len(bug.getDirectSubscribers()), 2) self.assertEqual( sorted(person.preferredemail.email for person in bug.getDirectSubscribers()), ['*****@*****.**', '*****@*****.**']) # There are two bug watches self.assertEqual(bug.watches.count(), 2) self.assertEqual(sorted(watch.url for watch in bug.watches), [ 'http://bugzilla.gnome.org/show_bug.cgi?id=43', 'https://bugzilla.mozilla.org/show_bug.cgi?id=42' ]) # There should only be one bug task (on netapplet): self.assertEqual(len(bug.bugtasks), 1) bugtask = bug.bugtasks[0] self.assertEqual(bugtask.product, product) self.assertEqual(bugtask.datecreated.isoformat(), '2004-10-12T12:00:00+00:00') self.assertEqual(bugtask.importance, BugTaskImportance.HIGH) self.assertEqual(bugtask.status, BugTaskStatus.CONFIRMED) self.assertEqual(bugtask.assignee.preferredemail.email, '*****@*****.**') self.assertNotEqual(bugtask.milestone, None) self.assertEqual(bugtask.milestone.name, 'future') # there are five comments: self.assertEqual(bug.messages.count(), 5) message1 = bug.messages[0] message2 = bug.messages[1] message3 = bug.messages[2] message4 = bug.messages[3] message5 = bug.messages[4] # Message 1: self.assertEqual(message1.owner.preferredemail.email, '*****@*****.**') self.assertEqual(message1.datecreated.isoformat(), '2004-10-12T12:00:00+00:00') self.assertEqual(message1.subject, 'A test bug') self.assertEqual(message1.text_contents, 'Original description') self.assertEqual(len(message1.bugattachments), 1) attachment = message1.bugattachments[0] self.assertEqual(attachment.type, BugAttachmentType.UNSPECIFIED) self.assertEqual(attachment.title, 'Hello') self.assertEqual(attachment.libraryfile.filename, 'hello.txt') self.assertEqual(attachment.libraryfile.mimetype, 'text/plain') # Message 2: self.assertEqual(message2.owner.preferredemail.email, '*****@*****.**') self.assertEqual(message2.datecreated.isoformat(), '2005-01-01T11:00:00+00:00') self.assertEqual(message2.subject, 'Re: A test bug') self.assertEqual(message2.text_contents, 'A comment from an anonymous user') # Message 3: self.assertEqual(message3.owner.preferredemail.email, '*****@*****.**') self.assertEqual(message3.datecreated.isoformat(), '2005-01-01T13:00:00+00:00') self.assertEqual(message3.subject, 'Re: A test bug') self.assertEqual( message3.text_contents, 'A comment from mark about CVE-2005-2730\n\n' ' * list item 1\n * list item 2\n\nAnother paragraph') self.assertEqual(len(message3.bugattachments), 2) # grab the attachments in the appropriate order [attachment1, attachment2] = list(message3.bugattachments) if attachment1.type == BugAttachmentType.PATCH: attachment1, attachment2 = attachment2, attachment1 self.assertEqual(attachment1.type, BugAttachmentType.UNSPECIFIED) # default title and filename self.assertEqual(attachment1.title, 'unknown') self.assertEqual(attachment1.libraryfile.filename, 'unknown') # mime type guessed from content self.assertEqual(attachment1.libraryfile.mimetype, 'text/html') self.assertEqual(attachment2.type, BugAttachmentType.PATCH) # title defaults to filename self.assertEqual(attachment2.title, 'foo.patch') self.assertEqual(attachment2.libraryfile.filename, 'foo.patch') # mime type forced to text/plain because we have a patch self.assertEqual(attachment2.libraryfile.mimetype, 'text/plain') # Message 4: self.assertEqual(message4.owner.preferredemail.email, '*****@*****.**') self.assertEqual(message4.datecreated.isoformat(), '2005-01-01T14:00:00+00:00') self.assertEqual(message4.subject, 'Re: A test bug') self.assertEqual(message4.text_contents, '<empty comment>') self.assertEqual(len(message4.bugattachments), 0) # Message 5: self.assertEqual(message5.owner.preferredemail.email, '*****@*****.**') self.assertEqual(message5.datecreated.isoformat(), '2005-01-01T15:00:00+00:00') self.assertEqual(message5.subject, 'Re: A test bug') self.assertEqual(message5.text_contents, '') self.assertEqual(len(message5.bugattachments), 1) attachment = message5.bugattachments[0] self.assertEqual(attachment.type, BugAttachmentType.UNSPECIFIED) self.assertEqual(attachment.title, 'Hello') self.assertEqual(attachment.libraryfile.filename, 'hello.txt') self.assertEqual(attachment.libraryfile.mimetype, 'text/plain') self.assertNoPendingNotifications(bug)