"Fossies" - the Fresh Open Source Software Archive

Member "buildbot-2.3.1/buildbot/test/util/endpoint.py" (23 May 2019, 4180 Bytes) of package /linux/misc/buildbot-2.3.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "endpoint.py": 2.1.0_vs_2.2.0.

    1 # This file is part of Buildbot.  Buildbot is free software: you can
    2 # redistribute it and/or modify it under the terms of the GNU General Public
    3 # License as published by the Free Software Foundation, version 2.
    4 #
    5 # This program is distributed in the hope that it will be useful, but WITHOUT
    6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    7 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    8 # details.
    9 #
   10 # You should have received a copy of the GNU General Public License along with
   11 # this program; if not, write to the Free Software Foundation, Inc., 51
   12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   13 #
   14 # Copyright Buildbot Team Members
   15 
   16 
   17 from twisted.internet import defer
   18 
   19 from buildbot.data import base
   20 from buildbot.data import resultspec
   21 from buildbot.test.fake import fakemaster
   22 from buildbot.test.util import interfaces
   23 from buildbot.test.util import validation
   24 from buildbot.test.util.misc import TestReactorMixin
   25 from buildbot.util import pathmatch
   26 
   27 
   28 class EndpointMixin(TestReactorMixin, interfaces.InterfaceTests):
   29     # test mixin for testing Endpoint subclasses
   30 
   31     # class being tested
   32     endpointClass = None
   33 
   34     # the corresponding resource type - this will be instantiated at
   35     # self.data.rtypes[rtype.type] and self.rtype
   36     resourceTypeClass = None
   37 
   38     def setUpEndpoint(self):
   39         self.setUpTestReactor()
   40         self.master = fakemaster.make_master(self, wantMq=True, wantDb=True,
   41                                              wantData=True)
   42         self.db = self.master.db
   43         self.mq = self.master.mq
   44         self.data = self.master.data
   45         self.matcher = pathmatch.Matcher()
   46 
   47         rtype = self.rtype = self.resourceTypeClass(self.master)
   48         setattr(self.data.rtypes, rtype.name, rtype)
   49 
   50         self.ep = self.endpointClass(rtype, self.master)
   51 
   52         # this usually fails when a single-element pathPattern does not have a
   53         # trailing comma
   54         pathPatterns = self.ep.pathPatterns.split()
   55         for pp in pathPatterns:
   56             if pp == '/':
   57                 continue
   58             if not pp.startswith('/') or pp.endswith('/'):
   59                 raise AssertionError("invalid pattern %r" % (pp,))
   60         pathPatterns = [tuple(pp.split('/')[1:])
   61                         for pp in pathPatterns]
   62         for pp in pathPatterns:
   63             self.matcher[pp] = self.ep
   64 
   65         self.pathArgs = [
   66             {arg.split(':', 1)[1] for arg in pp if ':' in arg}
   67             for pp in pathPatterns if pp is not None]
   68 
   69     def tearDownEndpoint(self):
   70         pass
   71 
   72     def validateData(self, object):
   73         validation.verifyData(self, self.rtype.entityType, {}, object)
   74 
   75     # call methods, with extra checks
   76 
   77     @defer.inlineCallbacks
   78     def callGet(self, path, resultSpec=None):
   79         self.assertIsInstance(path, tuple)
   80         if resultSpec is None:
   81             resultSpec = resultspec.ResultSpec()
   82         endpoint, kwargs = self.matcher[path]
   83         self.assertIdentical(endpoint, self.ep)
   84         rv = yield endpoint.get(resultSpec, kwargs)
   85 
   86         if self.ep.isCollection:
   87             self.assertIsInstance(rv, (list, base.ListResult))
   88         else:
   89             self.assertIsInstance(rv, (dict, type(None)))
   90         return rv
   91 
   92     def callControl(self, action, args, path):
   93         self.assertIsInstance(path, tuple)
   94         endpoint, kwargs = self.matcher[path]
   95         self.assertIdentical(endpoint, self.ep)
   96         d = self.ep.control(action, args, kwargs)
   97         self.assertIsInstance(d, defer.Deferred)
   98         return d
   99 
  100     # interface tests
  101 
  102     def test_get_spec(self):
  103         @self.assertArgSpecMatches(self.ep.get)
  104         def get(self, resultSpec, kwargs):
  105             pass
  106 
  107     def test_control_spec(self):
  108         @self.assertArgSpecMatches(self.ep.control)
  109         def control(self, action, args, kwargs):
  110             pass
  111 
  112     def test_rootLinkName(self):
  113         rootLinkName = self.ep.rootLinkName
  114         if not rootLinkName:
  115             return
  116         try:
  117             self.assertEqual(self.matcher[(rootLinkName,)][0], self.ep)
  118         except KeyError:
  119             self.fail('No match for rootlink: ' + rootLinkName)