Skip to content

Commit

Permalink
Reuse code
Browse files Browse the repository at this point in the history
  • Loading branch information
rajgoesout committed Jul 17, 2019
1 parent 66f0f5e commit d941c7d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
16 changes: 1 addition & 15 deletions master/buildbot/db/builds.py
Expand Up @@ -25,10 +25,6 @@
from buildbot.util import epoch2datetime


class BuildDict(dict):
pass


class BuildsConnectorComponent(base.DBConnectorComponent):
# Documentation is in developer/db.rst

Expand Down Expand Up @@ -124,21 +120,11 @@ def thd(conn):
q = sa.select([builds_tbl]).select_from(
from_clause).where(changes_tbl.c.changeid == changeid)
res = conn.execute(q)
return [self._rowToBuildsdict_thd(conn, row)
return [self._builddictFromRow(row)
for row in res.fetchall()]

return self.db.pool.do(thd)

def _rowToBuildsdict_thd(self, conn, row):
buildid = row.id
builddict = BuildDict(buildid=buildid, number=row.number, builderid=row.builderid,
buildrequestid=row.buildrequestid, workerid=row.workerid,
masterid=row.masterid, started_at=row.started_at,
complete_at=row.complete_at, state_string=row.state_string,
results=row.results)

return builddict

# returns a Deferred that returns a value
def getBuilds(self, builderid=None, buildrequestid=None, workerid=None, complete=None, resultSpec=None):
def thd(conn):
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/test/fake/fakedb.py
Expand Up @@ -1978,12 +1978,12 @@ def getBuildsForChange(self, changeid):
for build in builds:
for result in results:
if result['buildrequestid'] == build['buildrequestid']:
result['buildid'] = build['id']
result['id'] = build['id']
result['number'] = build['number']
result['builderid'] = build['builderid']
result['workerid'] = build['workerid']
result['masterid'] = build['masterid']
result['started_at'] = 1304262222
result['started_at'] = epoch2datetime(1304262222)
result['complete_at'] = build['complete_at']
result['state_string'] = build['state_string']
result['results'] = build['results']
Expand Down
11 changes: 3 additions & 8 deletions master/buildbot/test/unit/test_db_builds.py
Expand Up @@ -33,10 +33,6 @@
CREATED_AT = 927845299


def buildKey(build):
return (build['buildid'], build['state_string'])


class Tests(interfaces.InterfaceTests):

# common sample data
Expand Down Expand Up @@ -201,8 +197,7 @@ def do_test_getBuildsForChange(self, rows, changeid, expected):

builds = yield self.db.builds.getBuildsForChange(changeid)

self.assertEqual(sorted(builds, key=buildKey),
sorted(expected, key=buildKey))
self.assertEqual(sorted(builds), sorted(expected))

def test_getBuildsForChange_OneCodebase(self):
rows = [fakedb.Master(id=88, name="bar"),
Expand All @@ -222,13 +217,13 @@ def test_getBuildsForChange_OneCodebase(self):
started_at=1304262222, results=1), ]

expected = [{
'buildid': 50,
'id': 50,
'number': 5,
'builderid': 77,
'buildrequestid': 19,
'workerid': 13,
'masterid': 88,
'started_at': 1304262222,
'started_at': epoch2datetime(1304262222),
'complete_at': None,
'state_string': 'test',
'results': 1}]
Expand Down

0 comments on commit d941c7d

Please sign in to comment.