Skip to content

Commit

Permalink
Change FakeChangesComponent to store changes as dicts
Browse files Browse the repository at this point in the history
Based on 902002c from nine.
  • Loading branch information
pepsiman committed Nov 6, 2013
1 parent f9fa86b commit bee5bdc
Showing 1 changed file with 22 additions and 34 deletions.
56 changes: 22 additions & 34 deletions master/buildbot/test/fake/fakedb.py
Expand Up @@ -19,6 +19,7 @@
the real connector components.
"""

import copy
import base64
from buildbot.util import json, datetime2epoch
from twisted.internet import defer, reactor
Expand Down Expand Up @@ -121,8 +122,6 @@ class Change(Row):
repository = 'repo',
codebase = '',
project = 'proj',
properties = dict(),
files = []
)

lists = ('files',)
Expand Down Expand Up @@ -343,21 +342,25 @@ def setUp(self):
def insertTestData(self, rows):
for row in rows:
if isinstance(row, Change):
self.changes[row.changeid] = row
# copy this since we'll be modifying it (e.g., adding files)
ch = self.changes[row.changeid] = copy.deepcopy(row.values)
ch['files'] = []
ch['properties'] = {}
ch['uids'] = []

elif isinstance(row, ChangeFile):
ch = self.changes[row.changeid]
ch.files.append(row.filename)
ch['files'].append(row.filename)

elif isinstance(row, ChangeProperty):
ch = self.changes[row.changeid]
n, vs = row.property_name, row.property_value
v, s = json.loads(vs)
ch.properties.setProperty(n, v, s)
ch['properties'][n] = (v, s)

elif isinstance(row, ChangeUser):
ch = self.changes[row.changeid]
ch.uid = row.uid
ch['uids'].append(row.uid)

# component methods

Expand All @@ -370,7 +373,7 @@ def addChange(self, author=None, files=None, comments=None, is_dir=0,
else:
changeid = 500

self.changes[changeid] = ch = Change(
self.changes[changeid] = dict(
changeid=changeid,
author=author,
comments=comments,
Expand All @@ -382,9 +385,9 @@ def addChange(self, author=None, files=None, comments=None, is_dir=0,
revlink=revlink,
repository=repository,
project=project,
codebase=codebase)
ch.files = files
ch.properties = properties
codebase=codebase,
files=files,
properties=properties)

return defer.succeed(changeid)

Expand All @@ -399,27 +402,11 @@ def getChange(self, changeid):
except KeyError:
return defer.succeed(None)

chdict = dict(
changeid=row.changeid,
author=row.author,
files=row.files,
comments=row.comments,
is_dir=row.is_dir,
revision=row.revision,
when_timestamp=_mkdt(row.when_timestamp),
branch=row.branch,
category=row.category,
revlink=row.revlink,
properties=row.properties,
repository=row.repository,
codebase=row.codebase,
project=row.project)

return defer.succeed(chdict)
return defer.succeed(self._chdict(row))

def getChangeUids(self, changeid):
try:
ch_uids = [self.changes[changeid].uid]
ch_uids = self.changes[changeid]['uids']
except KeyError:
ch_uids = []
return defer.succeed(ch_uids)
Expand Down Expand Up @@ -466,7 +453,7 @@ def fakeAddChangeInstance(self, change):
changeid = change.number

# make a row from the change
row = Change(
row = dict(
changeid=changeid,
author=change.who,
files=change.files,
Expand All @@ -480,7 +467,8 @@ def fakeAddChangeInstance(self, change):
properties=change.properties,
repository=change.repository,
codebase=change.codebase,
project=change.project)
project=change.project,
uids=[])
self.changes[changeid] = row

class FakeSchedulersComponent(FakeDBComponent):
Expand Down Expand Up @@ -522,25 +510,25 @@ def getChangeClassifications(self, objectid, branch=-1, repository=-1,
# filter out the classifications for the requested branch
classifications = dict(
(k,v) for (k,v) in classifications.iteritems()
if self.db.changes.changes.get(k, sentinel).branch == branch )
if self.db.changes.changes.get(k, sentinel)['branch'] == branch )

if repository != -1:
# filter out the classifications for the requested branch
classifications = dict(
(k,v) for (k,v) in classifications.iteritems()
if self.db.changes.changes.get(k, sentinel).repository == repository )
if self.db.changes.changes.get(k, sentinel)['repository'] == repository )

if project != -1:
# filter out the classifications for the requested branch
classifications = dict(
(k,v) for (k,v) in classifications.iteritems()
if self.db.changes.changes.get(k, sentinel).project == project )
if self.db.changes.changes.get(k, sentinel)['project'] == project )

if codebase != -1:
# filter out the classifications for the requested branch
classifications = dict(
(k,v) for (k,v) in classifications.iteritems()
if self.db.changes.changes.get(k, sentinel).codebase == codebase )
if self.db.changes.changes.get(k, sentinel)['codebase'] == codebase )

return defer.succeed(classifications)

Expand Down

0 comments on commit bee5bdc

Please sign in to comment.