def test_createUserObject_unrecognized_src(self): d = users.createUserObject(self.master, "Tyler Durden", 'blah') def check(_): self.assertEqual(self.db.users.users, {}) self.assertEqual(self.db.users.users_info, {}) d.addCallback(check) return d
def test_createUserObject_bzr(self): yield users.createUserObject(self.master, "Tyler Durden", 'bzr') self.assertEqual(self.db.users.users, {1: dict(identifier='Tyler Durden', bb_username=None, bb_password=None)}) self.assertEqual(self.db.users.users_info, {1: [dict(attr_type="bzr", attr_data="Tyler Durden")]})
def test_createUserObject_cvs(self): d = users.createUserObject(self.master, "tdurden", "cvs") def check(_): self.assertEqual(self.db.users.users, {1: dict(identifier="tdurden", bb_username=None, bb_password=None)}) self.assertEqual(self.db.users.users_info, {1: [dict(attr_type="cvs", attr_data="tdurden")]}) d.addCallback(check) return d
def test_createUserObject_cvs(self): yield users.createUserObject(self.master, "tdurden", 'cvs') self.assertEqual(self.db.users.users, {1: dict(identifier='tdurden', bb_username=None, bb_password=None)}) self.assertEqual(self.db.users.users_info, {1: [dict(attr_type="cvs", attr_data="tdurden")]})
def test_createUserObject_darcs(self): yield users.createUserObject(self.master, "*****@*****.**", 'darcs') self.assertEqual(self.db.users.users, {1: dict(identifier='*****@*****.**', bb_username=None, bb_password=None)}) self.assertEqual(self.db.users.users_info, {1: [dict(attr_type="darcs", attr_data="*****@*****.**")]})
def test_createUserObject_darcs(self): d = users.createUserObject(self.master, "*****@*****.**", 'darcs') def check(_): self.assertEqual(self.db.users.users, { 1: dict(identifier='*****@*****.**') }) self.assertEqual(self.db.users.users_info, { 1: [dict(attr_type="darcs", attr_data="*****@*****.**")]}) d.addCallback(check) return d
def test_createUserObject_cvs(self): d = users.createUserObject(self.master, "tdurden", 'cvs') def check(_): self.assertEqual(self.db.users.users, { 1: dict(identifier='tdurden') }) self.assertEqual(self.db.users.users_info, { 1: [dict(attr_type="cvs", attr_data="tdurden")]}) d.addCallback(check) return d
def test_createUserObject_bzr(self): d = users.createUserObject(self.master, "Tyler Durden", 'bzr') def check(_): self.assertEqual(self.db.users.users, { 1: dict(identifier='Tyler Durden') }) self.assertEqual(self.db.users.users_info, { 1: [dict(attr_type="bzr", attr_data="Tyler Durden")]}) d.addCallback(check) return d
def test_createUserObject_hg(self): yield users.createUserObject(self.master, "Tyler Durden <*****@*****.**>", 'hg') self.assertEqual(self.db.users.users, {1: dict(identifier='Tyler Durden <*****@*****.**>', bb_username=None, bb_password=None)}) self.assertEqual(self.db.users.users_info, {1: [dict(attr_type="hg", attr_data="Tyler Durden <*****@*****.**>")]})
def test_createUserObject_hg(self): d = users.createUserObject(self.master, "Tyler Durden <*****@*****.**>", 'hg') def check(_): self.assertEqual(self.db.users.users, { 1: dict(identifier='Tyler Durden <*****@*****.**>') }) self.assertEqual(self.db.users.users_info, { 1: [dict(attr_type="hg", attr_data="Tyler Durden <*****@*****.**>")]}) d.addCallback(check) return d
def test_createUserObject_cvs(self): d = users.createUserObject(self.master, "tdurden", 'cvs') def check(_): self.assertEqual(self.db.users.users, {1: dict(identifier='tdurden', bb_username=None, bb_password=None)}) self.assertEqual(self.db.users.users_info, {1: [dict(attr_type="cvs", attr_data="tdurden")]}) d.addCallback(check) return d
def test_createUserObject_darcs(self): d = users.createUserObject(self.master, "*****@*****.**", 'darcs') def check(_): self.assertEqual(self.db.users.users, {1: dict(identifier='*****@*****.**', bb_username=None, bb_password=None)}) self.assertEqual(self.db.users.users_info, {1: [dict(attr_type="darcs", attr_data="*****@*****.**")]}) d.addCallback(check) return d
def test_createUserObject_git(self): d = users.createUserObject(self.master, "Tyler Durden <*****@*****.**>", 'git') def check(_): self.assertEqual(self.db.users.users, { 1: dict(identifier='Tyler Durden <*****@*****.**>', bb_username=None, bb_password=None) }) self.assertEqual(self.db.users.users_info, { 1: [dict(attr_type="git", attr_data="Tyler Durden <*****@*****.**>")]}) d.addCallback(check) return d
def test_createUserObject_hg(self): d = users.createUserObject(self.master, "Tyler Durden <*****@*****.**>", 'hg') def check(_): self.assertEqual(self.db.users.users, {1: dict(identifier='Tyler Durden <*****@*****.**>', bb_username=None, bb_password=None)}) self.assertEqual(self.db.users.users_info, {1: [dict(attr_type="hg", attr_data="Tyler Durden <*****@*****.**>")]}) d.addCallback(check) return d
def test_createUserObject_no_src(self): yield users.createUserObject(self.master, "Tyler Durden", None) self.assertEqual(self.db.users.users, {}) self.assertEqual(self.db.users.users_info, {})
def test_createUserObject_unrecognized_src(self): yield users.createUserObject(self.master, "Tyler Durden", 'blah') self.assertEqual(self.db.users.users, {}) self.assertEqual(self.db.users.users_info, {})
def addChange(self, files=None, comments=None, author=None, revision=None, when_timestamp=None, branch=None, category=None, revlink=u'', properties=None, repository=u'', codebase=None, project=u'', src=None, _reactor=reactor): metrics.MetricCountEvent.log("added_changes", 1) if properties is None: properties = {} # add the source to the properties for k in properties: properties[k] = (properties[k], u'Change') # get a user id if src: # create user object, returning a corresponding uid uid = yield users.createUserObject(self.master, author, src) else: uid = None if not revlink and revision and repository and callable(self.master.config.revlink): # generate revlink from revision and repository using the configured callable revlink = self.master.config.revlink(revision, repository) or u'' if callable(category): pre_change = self.master.config.preChangeGenerator(author=author, files=files, comments=comments, revision=revision, when_timestamp=when_timestamp, branch=branch, revlink=revlink, properties=properties, repository=repository, project=project) category = category(pre_change) # set the codebase, either the default, supplied, or generated if codebase is None \ and self.master.config.codebaseGenerator is not None: pre_change = self.master.config.preChangeGenerator(author=author, files=files, comments=comments, revision=revision, when_timestamp=when_timestamp, branch=branch, category=category, revlink=revlink, properties=properties, repository=repository, project=project) codebase = self.master.config.codebaseGenerator(pre_change) codebase = text_type(codebase) else: codebase = codebase or u'' # add the Change to the database changeid = yield self.master.db.changes.addChange( author=author, files=files, comments=comments, revision=revision, when_timestamp=epoch2datetime(when_timestamp), branch=branch, category=category, revlink=revlink, properties=properties, repository=repository, codebase=codebase, project=project, uid=uid, _reactor=_reactor) # get the change and munge the result for the notification change = yield self.master.data.get(('changes', str(changeid))) change = copy.deepcopy(change) self.produceEvent(change, 'new') # log, being careful to handle funny characters msg = u"added change with revision %s to database" % (revision,) log.msg(msg.encode('utf-8', 'replace')) defer.returnValue(changeid)
def addChange( self, files=None, comments=None, author=None, revision=None, when_timestamp=None, branch=None, category=None, revlink=u"", properties={}, repository=u"", codebase=None, project=u"", src=None, _reactor=reactor, ): metrics.MetricCountEvent.log("added_changes", 1) # add the source to the properties for k in properties: properties[k] = (properties[k], u"Change") # get a user id if src: # create user object, returning a corresponding uid uid = yield users.createUserObject(self.master, author, src) else: uid = None # set the codebase, either the default, supplied, or generated if codebase is None and self.master.config.codebaseGenerator is not None: pre_change = { "author": author, "files": files, "comments": comments, "revision": revision, "when_timestamp": when_timestamp, "branch": branch, "category": category, "revlink": revlink, "properties": properties, "repository": repository, "project": project, "codebase": None, # 'uid': uid, -- not in data API yet? } codebase = self.master.config.codebaseGenerator(pre_change) codebase = unicode(codebase) else: codebase = codebase or u"" # add the Change to the database changeid = yield self.master.db.changes.addChange( author=author, files=files, comments=comments, revision=revision, when_timestamp=epoch2datetime(when_timestamp), branch=branch, category=category, revlink=revlink, properties=properties, repository=repository, codebase=codebase, project=project, uid=uid, _reactor=_reactor, ) # get the change and munge the result for the notification change = yield self.master.data.get(("changes", str(changeid))) change = copy.deepcopy(change) self.produceEvent(change, "new") # log, being careful to handle funny characters msg = u"added change with revision %s to database" % (revision,) log.msg(msg.encode("utf-8", "replace")) defer.returnValue(changeid)
def addChange(self, files=None, comments=None, author=None, revision=None, when_timestamp=None, branch=None, category=None, revlink=u'', properties={}, repository=u'', codebase=None, project=u'', src=None, _reactor=reactor): metrics.MetricCountEvent.log("added_changes", 1) # add the source to the properties for k in properties: properties[k] = (properties[k], u'Change') # get a user id if src: # create user object, returning a corresponding uid uid = yield users.createUserObject(self.master, author, src) else: uid = None # set the codebase, either the default, supplied, or generated if codebase is None \ and self.master.config.codebaseGenerator is not None: pre_change = { 'author': author, 'files': files, 'comments': comments, 'revision': revision, 'when_timestamp': when_timestamp, 'branch': branch, 'category': category, 'revlink': revlink, 'properties': properties, 'repository': repository, 'project': project, 'codebase': None, # 'uid': uid, -- not in data API yet? } codebase = self.master.config.codebaseGenerator(pre_change) codebase = unicode(codebase) else: codebase = codebase or u'' # add the Change to the database changeid = yield self.master.db.changes.addChange( author=author, files=files, comments=comments, revision=revision, when_timestamp=epoch2datetime(when_timestamp), branch=branch, category=category, revlink=revlink, properties=properties, repository=repository, codebase=codebase, project=project, uid=uid, _reactor=_reactor) # get the change and munge the result for the notification change = yield self.master.data.get(('changes', str(changeid))) change = copy.deepcopy(change) self.produceEvent(change, 'new') # log, being careful to handle funny characters msg = u"added change with revision %s to database" % (revision,) log.msg(msg.encode('utf-8', 'replace')) defer.returnValue(changeid)
def addChange(self, who=None, files=None, comments=None, author=None, isdir=None, is_dir=None, revision=None, when=None, when_timestamp=None, branch=None, category=None, revlink='', properties={}, repository='', project='', src=None): """ Add a change to the buildmaster and act on it. This is a wrapper around L{ChangesConnectorComponent.addChange} which also acts on the resulting change and returns a L{Change} instance. Note that all parameters are keyword arguments, although C{who}, C{files}, and C{comments} can be specified positionally for backward-compatibility. @param author: the author of this change @type author: unicode string @param who: deprecated name for C{author} @param files: a list of filenames that were changed @type branch: list of unicode strings @param comments: user comments on the change @type branch: unicode string @param is_dir: deprecated @param isdir: deprecated name for C{is_dir} @param revision: the revision identifier for this change @type revision: unicode string @param when_timestamp: when this change occurred, or the current time if None @type when_timestamp: datetime instance or None @param when: deprecated name and type for C{when_timestamp} @type when: integer (UNIX epoch time) or None @param branch: the branch on which this change took place @type branch: unicode string @param category: category for this change (arbitrary use by Buildbot users) @type category: unicode string @param revlink: link to a web view of this revision @type revlink: unicode string @param properties: properties to set on this change @type properties: dictionary with string keys and simple values (JSON-able). Note that the property source is I{not} included in this dictionary. @param repository: the repository in which this change took place @type repository: unicode string @param project: the project this change is a part of @type project: unicode string @param src: source of the change (vcs or other) @type src: string @returns: L{Change} instance via Deferred """ metrics.MetricCountEvent.log("added_changes", 1) # handle translating deprecated names into new names for db.changes def handle_deprec(oldname, old, newname, new, default=None, converter = lambda x:x): if old is not None: if new is None: log.msg("WARNING: change source is using deprecated " "addChange parameter '%s'" % oldname) return converter(old) raise TypeError("Cannot provide '%s' and '%s' to addChange" % (oldname, newname)) if new is None: new = default return new author = handle_deprec("who", who, "author", author) is_dir = handle_deprec("isdir", isdir, "is_dir", is_dir, default=0) when_timestamp = handle_deprec("when", when, "when_timestamp", when_timestamp, converter=epoch2datetime) # add a source to each property for n in properties: properties[n] = (properties[n], 'Change') d = defer.succeed(None) if src: # create user object, returning a corresponding uid d.addCallback(lambda _ : users.createUserObject(self, author, src)) # add the Change to the database d.addCallback(lambda uid : self.db.changes.addChange(author=author, files=files, comments=comments, is_dir=is_dir, revision=revision, when_timestamp=when_timestamp, branch=branch, category=category, revlink=revlink, properties=properties, repository=repository, project=project, uid=uid)) # convert the changeid to a Change instance d.addCallback(lambda changeid : self.db.changes.getChange(changeid)) d.addCallback(lambda chdict : changes.Change.fromChdict(self, chdict)) def notify(change): msg = u"added change %s to database" % change log.msg(msg.encode('utf-8', 'replace')) # only deliver messages immediately if we're not polling if not self.config.db['db_poll_interval']: self._change_subs.deliver(change) return change d.addCallback(notify) return d