def test_fromSsdict_patch(self): master = mock.Mock() master.db = fakedb.FakeDBConnector(self) master.db.insertTestData([ fakedb.Patch(id=99, subdir='/foo', patchlevel=3, patch_base64='LS0gKys='), fakedb.SourceStamp(id=234, branch='trunk', revision='9284', repository='svn://...', project='world-domination', patchid=99), ]) # use getSourceStamp to minimize the risk from changes to the format of # the ssdict d = master.db.sourcestamps.getSourceStamp(234) d.addCallback( lambda ssdict: sourcestamp.SourceStamp.fromSsdict(master, ssdict)) def check(ss): self.assertEqual(ss.ssid, 234) self.assertEqual(ss.branch, 'trunk') self.assertEqual(ss.revision, '9284') self.assertEqual(ss.patch, (3, '-- ++')) self.assertEqual(ss.changes, ()) self.assertEqual(ss.project, 'world-domination') self.assertEqual(ss.repository, 'svn://...') d.addCallback(check) return d
def test_getSourceStamp_patch(self): d = self.insertTestData([ fakedb.Patch(id=99, patch_base64='aGVsbG8sIHdvcmxk', patch_author='bar', patch_comment='foo', subdir='/foo', patchlevel=3), fakedb.SourceStamp(id=234, patchid=99), ]) d.addCallback(lambda _: self.db.sourcestamps.getSourceStamp(234)) def check(ssdict): validation.verifyDbDict(self, 'ssdict', ssdict) self.assertEqual( dict((k, v) for k, v in iteritems(ssdict) if k.startswith('patch_')), dict(patch_body='hello, world', patch_level=3, patch_author='bar', patch_comment='foo', patch_subdir='/foo')) d.addCallback(check) return d
def test_getSourceStamps(self): yield self.insertTestData([ fakedb.Patch(id=99, patch_base64='aGVsbG8sIHdvcmxk', patch_author='bar', patch_comment='foo', subdir='/foo', patchlevel=3), fakedb.SourceStamp(id=234, revision='r', project='p', codebase='c', repository='rep', branch='b', patchid=99, created_at=CREATED_AT), fakedb.SourceStamp(id=235, revision='r2', project='p2', codebase='c2', repository='rep2', branch='b2', patchid=None, created_at=CREATED_AT + 10), ]) sourcestamps = yield self.db.sourcestamps.getSourceStamps() self.assertEqual( sorted(sourcestamps, key=sourceStampKey), sorted([{ 'branch': 'b', 'codebase': 'c', 'patch_author': 'bar', 'patchid': 99, 'patch_body': b'hello, world', 'patch_comment': 'foo', 'patch_level': 3, 'patch_subdir': '/foo', 'project': 'p', 'repository': 'rep', 'revision': 'r', 'created_at': epoch2datetime(CREATED_AT), 'ssid': 234, }, { 'branch': 'b2', 'codebase': 'c2', 'patchid': None, 'patch_author': None, 'patch_body': None, 'patch_comment': None, 'patch_level': None, 'patch_subdir': None, 'project': 'p2', 'repository': 'rep2', 'revision': 'r2', 'created_at': epoch2datetime(CREATED_AT + 10), 'ssid': 235, }], key=sourceStampKey))
def setUp(self): self.setUpEndpoint() self.db.insertTestData([ fakedb.SourceStamp(id=13, branch=u'oak'), fakedb.Patch(id=99, patch_base64='aGVsbG8sIHdvcmxk', patch_author='bar', patch_comment='foo', subdir='/foo', patchlevel=3), fakedb.SourceStamp(id=14, patchid=99, branch=u'poplar'), ])
def setupBuildResults(self, results, wantPreviousBuild=False): # this testsuite always goes through setupBuildResults so that # the data is sure to be the real data schema known coming from data # api self.db = self.master.db self.db.insertTestData([ fakedb.Master(id=92), fakedb.Worker(id=13, name='wrk'), fakedb.Buildset(id=98, results=results, reason="testReason1"), fakedb.Builder(id=80, name='Builder1'), fakedb.BuildRequest(id=11, buildsetid=98, builderid=80), fakedb.Build(id=20, number=0, builderid=80, buildrequestid=11, workerid=13, masterid=92, results=results), fakedb.Step(id=50, buildid=20, number=5, name='make'), fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234), fakedb.SourceStamp(id=234, patchid=99), fakedb.Change(changeid=13, branch=u'trunk', revision=u'9283', author='me@foo', repository=u'svn://...', codebase=u'cbsvn', project=u'world-domination', sourcestampid=234), fakedb.Log(id=60, stepid=50, name='stdio', slug='stdio', type='s', num_lines=7), fakedb.LogChunk(logid=60, first_line=0, last_line=1, compressed=0, content=u'Unicode log with non-ascii (\u00E5\u00E4\u00F6).'), fakedb.Patch(id=99, patch_base64='aGVsbG8sIHdvcmxk', patch_author='him@foo', patch_comment='foo', subdir='/foo', patchlevel=3), ]) for _id in (20,): self.db.insertTestData([ fakedb.BuildProperty( buildid=_id, name="workername", value="wrk"), fakedb.BuildProperty( buildid=_id, name="reason", value="because"), fakedb.BuildProperty( buildid=_id, name="scheduler", value="checkin"), fakedb.BuildProperty( buildid=_id, name="branch", value="master"), ]) res = yield utils.getDetailsForBuildset(self.master, 98, wantProperties=True, wantPreviousBuild=wantPreviousBuild) builds = res['builds'] buildset = res['buildset'] @defer.inlineCallbacks def getChangesForBuild(buildid): assert buildid == 20 ch = yield self.master.db.changes.getChange(13) defer.returnValue([ch]) self.master.db.changes.getChangesForBuild = getChangesForBuild defer.returnValue((buildset, builds))
def setupDb(self): self.db = self.master.db self.db.insertTestData([ fakedb.Master(id=92), fakedb.Worker(id=13, name='wrk'), fakedb.Buildset(id=98, results=SUCCESS, reason="testReason1"), fakedb.Builder(id=80, name='Builder1'), fakedb.BuildRequest(id=9, buildsetid=97, builderid=80), fakedb.BuildRequest(id=10, buildsetid=97, builderid=80), fakedb.BuildRequest(id=11, buildsetid=98, builderid=80), fakedb.BuildRequest(id=12, buildsetid=98, builderid=80), fakedb.Build(id=18, number=0, builderid=80, buildrequestid=9, workerid=13, masterid=92, results=FAILURE), fakedb.Build(id=19, number=1, builderid=80, buildrequestid=10, workerid=13, masterid=92, results=RETRY), fakedb.Build(id=20, number=2, builderid=80, buildrequestid=11, workerid=13, masterid=92, results=SUCCESS), fakedb.Build(id=21, number=3, builderid=80, buildrequestid=12, workerid=13, masterid=92, results=SUCCESS), fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234), fakedb.SourceStamp(id=234), fakedb.Change(changeid=13, branch=u'trunk', revision=u'9283', author='me@foo', repository=u'svn://...', codebase=u'cbsvn', project=u'world-domination', sourcestampid=234), fakedb.Patch(id=99, patch_base64='aGVsbG8sIHdvcmxk', patch_author='him@foo', patch_comment='foo', subdir='/foo', patchlevel=3), fakedb.SourceStamp(id=235, patchid=99), ]) for _id in (20, 21): self.db.insertTestData([ fakedb.BuildProperty( buildid=_id, name="workername", value="wrk"), fakedb.BuildProperty( buildid=_id, name="reason", value="because"), fakedb.BuildProperty( buildid=_id, name="owner", value="him"), fakedb.Step(id=100 + _id, buildid=_id, name="step1"), fakedb.Step(id=200 + _id, buildid=_id, name="step2"), fakedb.Log(id=60 + _id, stepid=100 + _id, name='stdio', slug='stdio', type='s', num_lines=2), fakedb.LogChunk(logid=60 + _id, first_line=0, last_line=1, compressed=0, content=self.LOGCONTENT), ]) @defer.inlineCallbacks def getChangesForBuild(buildid): assert buildid == 20 ch = yield self.master.db.changes.getChange(13) defer.returnValue([ch]) self.master.db.changes.getChangesForBuild = getChangesForBuild
def makeBuildRequestRows(self, brid, bsid, changeid, ssid, codebase, branch=None, project=None, repository=None, patchid=None, revision=None): rows = [ fakedb.SourceStamp(id=ssid, codebase=codebase, branch=branch, project=project, repository=repository, patchid=patchid, revision=revision), fakedb.Buildset(id=bsid, reason='foo', submitted_at=1300305712, results=-1), fakedb.BuildsetSourceStamp(sourcestampid=ssid, buildsetid=bsid), fakedb.BuildRequest(id=brid, buildsetid=bsid, builderid=77, priority=13, submitted_at=1300305712, results=-1), ] if changeid: rows.append( fakedb.Change(changeid=changeid, branch='trunk', revision='9283', repository='svn://...', project='world-domination', sourcestampid=ssid)) if patchid: rows.append( fakedb.Patch(id=patchid, patch_base64='aGVsbG8sIHdvcmxk', patch_author='bar', patch_comment='foo', subdir='/foo', patchlevel=3)) return rows
def test_getSourceStamps(self): d = self.insertTestData([ fakedb.Patch(id=99, patch_base64='aGVsbG8sIHdvcmxk', patch_author='bar', patch_comment='foo', subdir='/foo', patchlevel=3), fakedb.SourceStamp(id=234, revision='r', project='p', codebase='c', repository='rep', branch='b', patchid=99, created_at=CREATED_AT), fakedb.SourceStamp(id=235, revision='r2', project='p2', codebase='c2', repository='rep2', branch='b2', patchid=None, created_at=CREATED_AT + 10), ]) d.addCallback(lambda _: self.db.sourcestamps.getSourceStamps()) @d.addCallback def check(sourcestamps): self.assertEqual(sorted(sourcestamps), sorted([{ 'branch': u'b', 'codebase': u'c', 'patch_author': u'bar', 'patchid': 99, 'patch_body': 'hello, world', 'patch_comment': u'foo', 'patch_level': 3, 'patch_subdir': u'/foo', 'project': u'p', 'repository': u'rep', 'revision': u'r', 'created_at': epoch2datetime(CREATED_AT), 'ssid': 234, }, { 'branch': u'b2', 'codebase': u'c2', 'patchid': None, 'patch_author': None, 'patch_body': None, 'patch_comment': None, 'patch_level': None, 'patch_subdir': None, 'project': u'p2', 'repository': u'rep2', 'revision': u'r2', 'created_at': epoch2datetime(CREATED_AT + 10), 'ssid': 235, }])) return d
def test_getSourceStamp_patch(self): yield self.insertTestData([ fakedb.Patch(id=99, patch_base64=u'aGVsbG8sIHdvcmxk', patch_author='bar', patch_comment='foo', subdir='/foo', patchlevel=3), fakedb.SourceStamp(id=234, patchid=99), ]) ssdict = yield self.db.sourcestamps.getSourceStamp(234) validation.verifyDbDict(self, 'ssdict', ssdict) self.assertEqual(dict((k, v) for k, v in ssdict.items() if k.startswith('patch_')), dict(patch_body=b'hello, world', patch_level=3, patch_author='bar', patch_comment='foo', patch_subdir='/foo'))