def test_get_string(self): # Test NameBlacklistSet.get() with string id. name_blacklist = self.name_blacklist_set.create(u'foo', u'bar') store = IStore(name_blacklist) store.flush() retrieved = self.name_blacklist_set.get(str(name_blacklist.id)) self.assertEqual(name_blacklist, retrieved)
def test_get_string(self): # Test NameBlacklistSet.get() with string id. name_blacklist = self.name_blacklist_set.create(u'foo', u'bar') store = IStore(name_blacklist) store.flush() retrieved = self.name_blacklist_set.get(str(name_blacklist.id)) self.assertEqual(name_blacklist, retrieved)
def test_with_snapbuild_metadata_as_none(self): db_build = self.factory.makeSnapBuild() unsecure_db_build = removeSecurityProxy(db_build) unsecure_db_build.store_upload_metadata = None store = IStore(SnapBuild) store.flush() loaded_build = store.find(SnapBuild, id=unsecure_db_build.id).one() job = SnapStoreUploadJob.create(loaded_build) self.assertEqual({}, job.store_metadata)
def addComponent(self, component_name): """Adds a component that is synced from a remote bug tracker""" component = BugTrackerComponent() component.name = component_name component.component_group = self store = IStore(BugTrackerComponent) store.add(component) store.flush() return component
def runMListSync(self, source_dir): """Run mlist-sync.py.""" store = IStore(self.team) store.flush() commit() store.invalidate() proc = Popen( ('scripts/mlist-sync.py', '--hostname', self.host_name, source_dir), stdout=PIPE, stderr=PIPE, cwd=config.root, env=dict(LPCONFIG=DatabaseFunctionalLayer.appserver_config_name)) stdout, stderr = proc.communicate() return proc.returncode, stderr
def addCustomComponent(self, component_name): """Adds a component locally that isn't synced from a remote tracker """ component = BugTrackerComponent() component.name = component_name component.component_group = self component.is_custom = True store = IStore(BugTrackerComponent) store.add(component) store.flush() return component
def test_with_snapbuild_metadata_as_none_set_status(self): db_build = self.factory.makeSnapBuild() unsecure_db_build = removeSecurityProxy(db_build) unsecure_db_build.store_upload_metadata = None store = IStore(SnapBuild) store.flush() loaded_build = store.find(SnapBuild, id=unsecure_db_build.id).one() job = SnapStoreUploadJob.create(loaded_build) job.status_url = 'http://example.org' store.flush() loaded_build = store.find(SnapBuild, id=unsecure_db_build.id).one() self.assertEqual('http://example.org', loaded_build.store_upload_metadata['status_url'])
def runMListSync(self, source_dir): """Run mlist-sync.py.""" store = IStore(self.team) store.flush() commit() store.invalidate() proc = Popen( ('scripts/mlist-sync.py', '--hostname', self.host_name, source_dir), stdout=PIPE, stderr=PIPE, cwd=config.root, env=dict(LPCONFIG=DatabaseFunctionalLayer.appserver_config_name)) stdout, stderr = proc.communicate() return proc.returncode, stderr
class TestNameBlacklist(TestCaseWithFactory): layer = ZopelessDatabaseLayer def setUp(self): super(TestNameBlacklist, self).setUp() self.name_blacklist_set = getUtility(INameBlacklistSet) self.caret_foo_exp = self.name_blacklist_set.create(u'^foo') self.foo_exp = self.name_blacklist_set.create(u'foo') self.verbose_exp = self.name_blacklist_set.create(u'v e r b o s e') team = self.factory.makeTeam() self.admin_exp = self.name_blacklist_set.create(u'fnord', admin=team) self.store = IStore(self.foo_exp) self.store.flush() def name_blacklist_match(self, name, user_id=None): '''Return the result of the name_blacklist_match stored procedure.''' user_id = user_id or 0 result = self.store.execute( "SELECT name_blacklist_match(%s, %s)", (name, user_id)) return result.get_one()[0] def is_blacklisted_name(self, name, user_id=None): '''Call the is_blacklisted_name stored procedure and return the result ''' user_id = user_id or 0 result = self.store.execute( "SELECT is_blacklisted_name(%s, %s)", (name, user_id)) blacklisted = result.get_one()[0] self.assertIsNotNone(blacklisted, 'is_blacklisted_name returned NULL') return bool(blacklisted) def test_name_blacklist_match(self): # A name that is not blacklisted returns NULL/None self.assertIsNone(self.name_blacklist_match(u"bar")) # A name that is blacklisted returns the id of the row in the # NameBlacklist table that matched. Rows are tried in order, and the # first match is returned. self.assertEqual( self.name_blacklist_match(u"foobar"), self.caret_foo_exp.id) self.assertEqual( self.name_blacklist_match(u"barfoo"), self.foo_exp.id) def test_name_blacklist_match_admin_does_not_match(self): # A user in the expresssion's admin team is exempt from the # backlisted name restriction. user = self.admin_exp.admin.teamowner self.assertEqual( None, self.name_blacklist_match(u"fnord", user.id)) def test_name_blacklist_match_launchpad_admin_can_change(self): # A Launchpad admin is exempt from any backlisted name restriction # that has an admin. user = self.factory.makePerson() admins = getUtility(ILaunchpadCelebrities).admin admins.addMember(user, user) self.assertEqual( None, self.name_blacklist_match(u"fnord", user.id)) def test_name_blacklist_match_launchpad_admin_cannot_change(self): # A Launchpad admin cannot override backlisted names without admins. user = self.factory.makePerson() admins = getUtility(ILaunchpadCelebrities).admin admins.addMember(user, user) self.assertEqual( self.foo_exp.id, self.name_blacklist_match(u"barfoo", user.id)) def test_name_blacklist_match_cache(self): # If the blacklist is changed in the DB, these changes are noticed. # This test is needed because the stored procedure keeps a cache # of the compiled regular expressions. self.assertEqual( self.name_blacklist_match(u"foobar"), self.caret_foo_exp.id) self.caret_foo_exp.regexp = u'nomatch' self.assertEqual( self.name_blacklist_match(u"foobar"), self.foo_exp.id) self.foo_exp.regexp = u'nomatch2' self.assertIsNone(self.name_blacklist_match(u"foobar")) def test_is_blacklisted_name(self): # is_blacklisted_name() is just a wrapper around name_blacklist_match # that is friendlier to use in a boolean context. self.assertFalse(self.is_blacklisted_name(u"bar")) self.assertTrue(self.is_blacklisted_name(u"foo")) self.caret_foo_exp.regexp = u'bar' self.foo_exp.regexp = u'bar2' self.assertFalse(self.is_blacklisted_name(u"foo")) def test_is_blacklisted_name_admin_false(self): # Users in the expression's admin team are will return False. user = self.admin_exp.admin.teamowner self.assertFalse(self.is_blacklisted_name(u"fnord", user.id)) def test_case_insensitive(self): self.assertTrue(self.is_blacklisted_name(u"Foo")) def test_verbose(self): # Testing the VERBOSE flag is used when compiling the regexp self.assertTrue(self.is_blacklisted_name(u"verbose"))
class TestPersonSet(TestCaseWithFactory): """Test `IPersonSet`.""" layer = DatabaseFunctionalLayer def setUp(self): super(TestPersonSet, self).setUp() login(ANONYMOUS) self.addCleanup(logout) self.person_set = getUtility(IPersonSet) def test_isNameBlacklisted(self): cursor().execute( "INSERT INTO NameBlacklist(id, regexp) VALUES (-100, 'foo')") self.failUnless(self.person_set.isNameBlacklisted('foo')) self.failIf(self.person_set.isNameBlacklisted('bar')) def test_isNameBlacklisted_user_is_admin(self): team = self.factory.makeTeam() name_blacklist_set = getUtility(INameBlacklistSet) self.admin_exp = name_blacklist_set.create(u'fnord', admin=team) self.store = IStore(self.admin_exp) self.store.flush() user = team.teamowner self.assertFalse(self.person_set.isNameBlacklisted('fnord', user)) def test_getByEmail_ignores_case_and_whitespace(self): person1_email = '*****@*****.**' person1 = self.person_set.getByEmail(person1_email) self.failIf(person1 is None, "PersonSet.getByEmail() could not find %r" % person1_email) person2 = self.person_set.getByEmail(' [email protected] ') self.failIf( person2 is None, "PersonSet.getByEmail() should ignore case and whitespace.") self.assertEqual(person1, person2) def test_getByEmail_ignores_unvalidated_emails(self): person = self.factory.makePerson() self.factory.makeEmail('*****@*****.**', person, email_status=EmailAddressStatus.NEW) found = self.person_set.getByEmail('*****@*****.**') self.assertTrue(found is None) def test_getPrecachedPersonsFromIDs(self): # The getPrecachedPersonsFromIDs() method should only make one # query to load all the extraneous data. Accessing the # attributes should then cause zero queries. person_ids = [self.factory.makePerson().id for i in range(3)] with StormStatementRecorder() as recorder: persons = list( self.person_set.getPrecachedPersonsFromIDs( person_ids, need_karma=True, need_ubuntu_coc=True, need_location=True, need_archive=True, need_preferred_email=True, need_validity=True)) self.assertThat(recorder, HasQueryCount(LessThan(2))) with StormStatementRecorder() as recorder: for person in persons: person.is_valid_person person.karma person.is_ubuntu_coc_signer person.location, person.archive person.preferredemail self.assertThat(recorder, HasQueryCount(LessThan(1))) def test_getPrecachedPersonsFromIDs_is_ubuntu_coc_signer(self): # getPrecachedPersonsFromIDs() sets is_ubuntu_coc_signer # correctly. person_ids = [self.factory.makePerson().id for i in range(3)] SignedCodeOfConduct(owner=person_ids[0], active=True) flush_database_caches() persons = list( self.person_set.getPrecachedPersonsFromIDs(person_ids, need_ubuntu_coc=True)) self.assertContentEqual(zip(person_ids, [True, False, False]), [(p.id, p.is_ubuntu_coc_signer) for p in persons]) def test_getByOpenIDIdentifier_returns_person(self): # getByOpenIDIdentifier takes a full OpenID identifier and # returns the corresponding person. person = self.factory.makePerson() with person_logged_in(person): identifier = person.account.openid_identifiers.one().identifier self.assertEqual( person, self.person_set.getByOpenIDIdentifier( u'http://openid.launchpad.dev/+id/%s' % identifier)) self.assertEqual( person, self.person_set.getByOpenIDIdentifier( u'http://ubuntu-openid.launchpad.dev/+id/%s' % identifier)) def test_getByOpenIDIdentifier_for_nonexistent_identifier_is_none(self): # None is returned if there's no matching person. self.assertIs( None, self.person_set.getByOpenIDIdentifier( u'http://openid.launchpad.dev/+id/notanid')) def test_getByOpenIDIdentifier_for_bad_domain_is_none(self): # Even though the OpenIDIdentifier table doesn't store the # domain, we verify it against our known OpenID faux-vhosts. # If it doesn't match, we don't even try to check the identifier. person = self.factory.makePerson() with person_logged_in(person): identifier = person.account.openid_identifiers.one().identifier self.assertIs( None, self.person_set.getByOpenIDIdentifier( u'http://not.launchpad.dev/+id/%s' % identifier)) def test_find__accepts_queries_with_or_operator(self): # PersonSet.find() allows to search for OR combined terms. person_one = self.factory.makePerson(name='baz') person_two = self.factory.makeTeam(name='blah') result = list(self.person_set.find('baz OR blah')) self.assertEqual([person_one, person_two], result) def test_findPerson__accepts_queries_with_or_operator(self): # PersonSet.findPerson() allows to search for OR combined terms. person_one = self.factory.makePerson(name='baz', email='*****@*****.**') person_two = self.factory.makePerson(name='blah', email='*****@*****.**') result = list(self.person_set.findPerson('baz OR blah')) self.assertEqual([person_one, person_two], result) # Note that these OR searches do not work for email addresses. result = list( self.person_set.findPerson('[email protected] OR [email protected]')) self.assertEqual([], result) def test_findPerson__case_insensitive_email_address_search(self): # A search for email addresses is case insensitve. person_one = self.factory.makePerson(name='baz', email='*****@*****.**') person_two = self.factory.makePerson(name='blah', email='*****@*****.**') result = list(self.person_set.findPerson('*****@*****.**')) self.assertEqual([person_one], result) result = list(self.person_set.findPerson('*****@*****.**')) self.assertEqual([person_two], result) def test_findTeam__accepts_queries_with_or_operator(self): # PersonSet.findTeam() allows to search for OR combined terms. team_one = self.factory.makeTeam(name='baz', email='*****@*****.**') team_two = self.factory.makeTeam(name='blah', email='*****@*****.**') result = list(self.person_set.findTeam('baz OR blah')) self.assertEqual([team_one, team_two], result) # Note that these OR searches do not work for email addresses. result = list( self.person_set.findTeam('[email protected] OR [email protected]')) self.assertEqual([], result) def test_findTeam__case_insensitive_email_address_search(self): # A search for email addresses is case insensitve. team_one = self.factory.makeTeam(name='baz', email='*****@*****.**') team_two = self.factory.makeTeam(name='blah', email='*****@*****.**') result = list(self.person_set.findTeam('*****@*****.**')) self.assertEqual([team_one], result) result = list(self.person_set.findTeam('*****@*****.**')) self.assertEqual([team_two], result)
class TestNameBlacklist(TestCaseWithFactory): layer = ZopelessDatabaseLayer def setUp(self): super(TestNameBlacklist, self).setUp() self.name_blacklist_set = getUtility(INameBlacklistSet) self.caret_foo_exp = self.name_blacklist_set.create(u'^foo') self.foo_exp = self.name_blacklist_set.create(u'foo') self.verbose_exp = self.name_blacklist_set.create(u'v e r b o s e') team = self.factory.makeTeam() self.admin_exp = self.name_blacklist_set.create(u'fnord', admin=team) self.store = IStore(self.foo_exp) self.store.flush() def name_blacklist_match(self, name, user_id=None): '''Return the result of the name_blacklist_match stored procedure.''' user_id = user_id or 0 result = self.store.execute( "SELECT name_blacklist_match(%s, %s)", (name, user_id)) return result.get_one()[0] def is_blacklisted_name(self, name, user_id=None): '''Call the is_blacklisted_name stored procedure and return the result ''' user_id = user_id or 0 result = self.store.execute( "SELECT is_blacklisted_name(%s, %s)", (name, user_id)) blacklisted = result.get_one()[0] self.failIf(blacklisted is None, 'is_blacklisted_name returned NULL') return bool(blacklisted) def test_name_blacklist_match(self): # A name that is not blacklisted returns NULL/None self.failUnless(self.name_blacklist_match(u"bar") is None) # A name that is blacklisted returns the id of the row in the # NameBlacklist table that matched. Rows are tried in order, and the # first match is returned. self.assertEqual( self.name_blacklist_match(u"foobar"), self.caret_foo_exp.id) self.assertEqual( self.name_blacklist_match(u"barfoo"), self.foo_exp.id) def test_name_blacklist_match_admin_does_not_match(self): # A user in the expresssion's admin team is exempt from the # backlisted name restriction. user = self.admin_exp.admin.teamowner self.assertEqual( None, self.name_blacklist_match(u"fnord", user.id)) def test_name_blacklist_match_launchpad_admin_can_change(self): # A Launchpad admin is exempt from any backlisted name restriction # that has an admin. user = self.factory.makePerson() admins = getUtility(ILaunchpadCelebrities).admin admins.addMember(user, user) self.assertEqual( None, self.name_blacklist_match(u"fnord", user.id)) def test_name_blacklist_match_launchpad_admin_cannot_change(self): # A Launchpad admin cannot override backlisted names without admins. user = self.factory.makePerson() admins = getUtility(ILaunchpadCelebrities).admin admins.addMember(user, user) self.assertEqual( self.foo_exp.id, self.name_blacklist_match(u"barfoo", user.id)) def test_name_blacklist_match_cache(self): # If the blacklist is changed in the DB, these changes are noticed. # This test is needed because the stored procedure keeps a cache # of the compiled regular expressions. self.assertEqual( self.name_blacklist_match(u"foobar"), self.caret_foo_exp.id) self.caret_foo_exp.regexp = u'nomatch' self.assertEqual( self.name_blacklist_match(u"foobar"), self.foo_exp.id) self.foo_exp.regexp = u'nomatch2' self.failUnless(self.name_blacklist_match(u"foobar") is None) def test_is_blacklisted_name(self): # is_blacklisted_name() is just a wrapper around name_blacklist_match # that is friendlier to use in a boolean context. self.failUnless(self.is_blacklisted_name(u"bar") is False) self.failUnless(self.is_blacklisted_name(u"foo") is True) self.caret_foo_exp.regexp = u'bar' self.foo_exp.regexp = u'bar2' self.failUnless(self.is_blacklisted_name(u"foo") is False) def test_is_blacklisted_name_admin_false(self): # Users in the expression's admin team are will return False. user = self.admin_exp.admin.teamowner self.assertFalse(self.is_blacklisted_name(u"fnord", user.id)) def test_case_insensitive(self): self.failUnless(self.is_blacklisted_name(u"Foo") is True) def test_verbose(self): # Testing the VERBOSE flag is used when compiling the regexp self.failUnless(self.is_blacklisted_name(u"verbose") is True)
def setUp(self): """Set up some native x86 builds for the test archive.""" super(TestBuildPackageJob, self).setUp() # The builds will be set up as follows: # # j: 3 gedit p: hppa v:False e:0:01:00 *** s: 1001 # j: 4 gedit p: 386 v:False e:0:02:00 *** s: 1002 # j: 5 firefox p: hppa v:False e:0:03:00 *** s: 1003 # j: 6 firefox p: 386 v:False e:0:04:00 *** s: 1004 # j: 7 cobblers p: hppa v:False e:0:05:00 *** s: 1005 # j: 8 cobblers p: 386 v:False e:0:06:00 *** s: 1006 # j: 9 thunderpants p: hppa v:False e:0:07:00 *** s: 1007 # j:10 thunderpants p: 386 v:False e:0:08:00 *** s: 1008 # j:11 apg p: hppa v:False e:0:09:00 *** s: 1009 # j:12 apg p: 386 v:False e:0:10:00 *** s: 1010 # j:13 vim p: hppa v:False e:0:11:00 *** s: 1011 # j:14 vim p: 386 v:False e:0:12:00 *** s: 1012 # j:15 gcc p: hppa v:False e:0:13:00 *** s: 1013 # j:16 gcc p: 386 v:False e:0:14:00 *** s: 1014 # j:17 bison p: hppa v:False e:0:15:00 *** s: 1015 # j:18 bison p: 386 v:False e:0:16:00 *** s: 1016 # j:19 flex p: hppa v:False e:0:17:00 *** s: 1017 # j:20 flex p: 386 v:False e:0:18:00 *** s: 1018 # j:21 postgres p: hppa v:False e:0:19:00 *** s: 1019 # j:22 postgres p: 386 v:False e:0:20:00 *** s: 1020 # # j=job, p=processor, v=virtualized, e=estimated_duration, s=score # First mark all builds in the sample data as already built. store = IStore(BinaryPackageBuild) sample_data = store.find(BinaryPackageBuild) for build in sample_data: build.buildstate = BuildStatus.FULLYBUILT store.flush() # We test builds that target a primary archive. self.non_ppa = self.factory.makeArchive( name="primary", purpose=ArchivePurpose.PRIMARY) self.non_ppa.require_virtualized = False self.builds = [] sourcenames = [ "gedit", "firefox", "cobblers", "thunderpants", "apg", "vim", "gcc", "bison", "flex", "postgres", ] for sourcename in sourcenames: self.builds.extend( self.publisher.getPubSource( sourcename=sourcename, status=PackagePublishingStatus.PUBLISHED, archive=self.non_ppa, architecturehintlist='any').createMissingBuilds()) # We want the builds to have a lot of variety when it comes to score # and estimated duration etc. so that the queries under test get # exercised properly. score = 1000 duration = 0 for build in self.builds: score += 1 duration += 60 bq = build.buildqueue_record bq.lastscore = score removeSecurityProxy(bq).estimated_duration = timedelta( seconds=duration)
class TestOopsReferences(TestCaseWithFactory): layer = DatabaseFunctionalLayer def setUp(self): super(TestOopsReferences, self).setUp() self.store = IStore(Message) def test_oops_in_messagechunk(self): oopsid = "OOPS-abcdef1234" MessageSet().fromText('foo', "foo %s bar" % oopsid) self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "product=1", {})) self.failUnlessEqual( set(), referenced_oops(now + day, now + day, "product=1", {})) def test_oops_in_messagesubject(self): oopsid = "OOPS-abcdef1234" self.factory.makeEmailMessage() MessageSet().fromText("Crash with %s" % oopsid, "body") self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "product=1", {})) self.failUnlessEqual( set(), referenced_oops(now + day, now + day, "product=1", {})) def test_oops_in_bug_title(self): oopsid = "OOPS-abcdef1234" bug = self.factory.makeBug() with person_logged_in(bug.owner): bug.title = "Crash with %s" % oopsid self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "product=1", {})) self.failUnlessEqual( set(), referenced_oops(now + day, now + day, "product=1", {})) def test_oops_in_bug_description(self): oopsid = "OOPS-abcdef1234" bug = self.factory.makeBug() with person_logged_in(bug.owner): bug.description = "Crash with %s" % oopsid self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "product=1", {})) self.failUnlessEqual( set(), referenced_oops(now + day, now + day, "product=1", {})) def test_oops_in_question_title(self): oopsid = "OOPS-abcdef1234" question = self.factory.makeQuestion(title="Crash with %s" % oopsid) self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "product=%(product)s", {'product': question.product.id})) self.failUnlessEqual( set([]), referenced_oops(now + day, now + day, "product=%(product)s", {'product': question.product.id})) def test_oops_in_question_wrong_context(self): oopsid = "OOPS-abcdef1234" question = self.factory.makeQuestion(title="Crash with %s" % oopsid) self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.store.flush() self.failUnlessEqual( set(), referenced_oops(now - day, now, "product=%(product)s", {'product': question.product.id + 1})) def test_oops_in_question_description(self): oopsid = "OOPS-abcdef1234" question = self.factory.makeQuestion( description="Crash with %s" % oopsid) self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "product=%(product)s", {'product': question.product.id})) self.failUnlessEqual( set([]), referenced_oops(now + day, now + day, "product=%(product)s", {'product': question.product.id})) def test_oops_in_question_whiteboard(self): oopsid = "OOPS-abcdef1234" question = self.factory.makeQuestion() with person_logged_in(question.owner): question.whiteboard = "Crash with %s" % oopsid self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "product=%(product)s", {'product': question.product.id})) self.failUnlessEqual( set([]), referenced_oops(now + day, now + day, "product=%(product)s", {'product': question.product.id})) def test_oops_in_question_distribution(self): oopsid = "OOPS-abcdef1234" distro = self.factory.makeDistribution() question = self.factory.makeQuestion(target=distro) with person_logged_in(question.owner): question.whiteboard = "Crash with %s" % oopsid self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "distribution=%(distribution)s", {'distribution': distro.id})) self.failUnlessEqual( set([]), referenced_oops(now + day, now + day, "distribution=%(distribution)s", {'distribution': distro.id})) def test_referenced_oops_in_urls_bug_663249(self): # Sometimes OOPS ids appears as part of an URL. These should could as # a reference even though they are not formatted specially - this # requires somewhat special handling in the reference calculation # function. oopsid_old = "OOPS-abcdef1234" oopsid_new = "OOPS-4321" bug_old = self.factory.makeBug() bug_new = self.factory.makeBug() with person_logged_in(bug_old.owner): bug_old.description = ( "foo https://lp-oops.canonical.com/oops.py?oopsid=%s bar" % oopsid_old) with person_logged_in(bug_new.owner): bug_new.description = ( "foo https://oops.canonical.com/oops.py?oopsid=%s bar" % oopsid_new) self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid_old, oopsid_new]), referenced_oops(now - day, now, "product=1", {})) self.failUnlessEqual( set([]), referenced_oops(now + day, now + day, "product=1", {}))
def setUp(self): """Set up some native x86 builds for the test archive.""" super(TestBuildPackageJob, self).setUp() # The builds will be set up as follows: # # j: 3 gedit p: hppa v:False e:0:01:00 *** s: 1001 # j: 4 gedit p: 386 v:False e:0:02:00 *** s: 1002 # j: 5 firefox p: hppa v:False e:0:03:00 *** s: 1003 # j: 6 firefox p: 386 v:False e:0:04:00 *** s: 1004 # j: 7 cobblers p: hppa v:False e:0:05:00 *** s: 1005 # j: 8 cobblers p: 386 v:False e:0:06:00 *** s: 1006 # j: 9 thunderpants p: hppa v:False e:0:07:00 *** s: 1007 # j:10 thunderpants p: 386 v:False e:0:08:00 *** s: 1008 # j:11 apg p: hppa v:False e:0:09:00 *** s: 1009 # j:12 apg p: 386 v:False e:0:10:00 *** s: 1010 # j:13 vim p: hppa v:False e:0:11:00 *** s: 1011 # j:14 vim p: 386 v:False e:0:12:00 *** s: 1012 # j:15 gcc p: hppa v:False e:0:13:00 *** s: 1013 # j:16 gcc p: 386 v:False e:0:14:00 *** s: 1014 # j:17 bison p: hppa v:False e:0:15:00 *** s: 1015 # j:18 bison p: 386 v:False e:0:16:00 *** s: 1016 # j:19 flex p: hppa v:False e:0:17:00 *** s: 1017 # j:20 flex p: 386 v:False e:0:18:00 *** s: 1018 # j:21 postgres p: hppa v:False e:0:19:00 *** s: 1019 # j:22 postgres p: 386 v:False e:0:20:00 *** s: 1020 # # j=job, p=processor, v=virtualized, e=estimated_duration, s=score # First mark all builds in the sample data as already built. store = IStore(BinaryPackageBuild) sample_data = store.find(BinaryPackageBuild) for build in sample_data: build.buildstate = BuildStatus.FULLYBUILT store.flush() # We test builds that target a primary archive. self.non_ppa = self.factory.makeArchive(name="primary", purpose=ArchivePurpose.PRIMARY) self.non_ppa.require_virtualized = False self.builds = [] sourcenames = [ "gedit", "firefox", "cobblers", "thunderpants", "apg", "vim", "gcc", "bison", "flex", "postgres", ] for sourcename in sourcenames: self.builds.extend( self.publisher.getPubSource( sourcename=sourcename, status=PackagePublishingStatus.PUBLISHED, archive=self.non_ppa, architecturehintlist='any').createMissingBuilds()) # We want the builds to have a lot of variety when it comes to score # and estimated duration etc. so that the queries under test get # exercised properly. score = 1000 duration = 0 for build in self.builds: score += 1 duration += 60 bq = build.buildqueue_record bq.lastscore = score removeSecurityProxy(bq).estimated_duration = timedelta( seconds=duration)
class TestOopsReferences(TestCaseWithFactory): layer = DatabaseFunctionalLayer def setUp(self): super(TestOopsReferences, self).setUp() self.store = IStore(Message) def test_oops_in_messagechunk(self): oopsid = "OOPS-abcdef1234" MessageSet().fromText('foo', "foo %s bar" % oopsid) self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual(set([oopsid]), referenced_oops(now - day, now, "product=1", {})) self.failUnlessEqual( set(), referenced_oops(now + day, now + day, "product=1", {})) def test_oops_in_messagesubject(self): oopsid = "OOPS-abcdef1234" self.factory.makeEmailMessage() MessageSet().fromText("Crash with %s" % oopsid, "body") self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual(set([oopsid]), referenced_oops(now - day, now, "product=1", {})) self.failUnlessEqual( set(), referenced_oops(now + day, now + day, "product=1", {})) def test_oops_in_bug_title(self): oopsid = "OOPS-abcdef1234" bug = self.factory.makeBug() with person_logged_in(bug.owner): bug.title = "Crash with %s" % oopsid self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual(set([oopsid]), referenced_oops(now - day, now, "product=1", {})) self.failUnlessEqual( set(), referenced_oops(now + day, now + day, "product=1", {})) def test_oops_in_bug_description(self): oopsid = "OOPS-abcdef1234" bug = self.factory.makeBug() with person_logged_in(bug.owner): bug.description = "Crash with %s" % oopsid self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual(set([oopsid]), referenced_oops(now - day, now, "product=1", {})) self.failUnlessEqual( set(), referenced_oops(now + day, now + day, "product=1", {})) def test_oops_in_question_title(self): oopsid = "OOPS-abcdef1234" question = self.factory.makeQuestion(title="Crash with %s" % oopsid) self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "product=%(product)s", {'product': question.product.id})) self.failUnlessEqual( set([]), referenced_oops(now + day, now + day, "product=%(product)s", {'product': question.product.id})) def test_oops_in_question_wrong_context(self): oopsid = "OOPS-abcdef1234" question = self.factory.makeQuestion(title="Crash with %s" % oopsid) self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.store.flush() self.failUnlessEqual( set(), referenced_oops(now - day, now, "product=%(product)s", {'product': question.product.id + 1})) def test_oops_in_question_description(self): oopsid = "OOPS-abcdef1234" question = self.factory.makeQuestion(description="Crash with %s" % oopsid) self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "product=%(product)s", {'product': question.product.id})) self.failUnlessEqual( set([]), referenced_oops(now + day, now + day, "product=%(product)s", {'product': question.product.id})) def test_oops_in_question_whiteboard(self): oopsid = "OOPS-abcdef1234" question = self.factory.makeQuestion() with person_logged_in(question.owner): question.whiteboard = "Crash with %s" % oopsid self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "product=%(product)s", {'product': question.product.id})) self.failUnlessEqual( set([]), referenced_oops(now + day, now + day, "product=%(product)s", {'product': question.product.id})) def test_oops_in_question_distribution(self): oopsid = "OOPS-abcdef1234" distro = self.factory.makeDistribution() question = self.factory.makeQuestion(target=distro) with person_logged_in(question.owner): question.whiteboard = "Crash with %s" % oopsid self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual( set([oopsid]), referenced_oops(now - day, now, "distribution=%(distribution)s", {'distribution': distro.id})) self.failUnlessEqual( set([]), referenced_oops(now + day, now + day, "distribution=%(distribution)s", {'distribution': distro.id})) def test_referenced_oops_in_urls_bug_663249(self): # Sometimes OOPS ids appears as part of an URL. These should could as # a reference even though they are not formatted specially - this # requires somewhat special handling in the reference calculation # function. oopsid_old = "OOPS-abcdef1234" oopsid_new = "OOPS-4321" bug_old = self.factory.makeBug() bug_new = self.factory.makeBug() with person_logged_in(bug_old.owner): bug_old.description = ( "foo https://lp-oops.canonical.com/oops.py?oopsid=%s bar" % oopsid_old) with person_logged_in(bug_new.owner): bug_new.description = ( "foo https://oops.canonical.com/oops.py?oopsid=%s bar" % oopsid_new) self.store.flush() now = datetime.now(tz=utc) day = timedelta(days=1) self.failUnlessEqual(set([oopsid_old, oopsid_new]), referenced_oops(now - day, now, "product=1", {})) self.failUnlessEqual( set([]), referenced_oops(now + day, now + day, "product=1", {}))