Esempio n. 1
0
    def testImageFileURL(self):
        xml = """\
<image>
  <name>my image</name>
  <files>
    <file>
      <title>image title</title>
      <size>1234</size>
      <sha1>abc</sha1>
      <fileName>file name</fileName>
      <url urlType="0">http://localhost:1234</url>
      <url>http://localhost:12345</url>
      <url urlType="1"/>
    </file>
  </files>
  <imageId>1</imageId>
</image>
"""
        image = converter.fromText("xml", xml, models.Image, None, None)
        self.failUnlessEqual(image.name, "my image")
        self.failUnlessEqual([ x.title for x in image.files.files ],
            ['image title'])
        self.failUnlessEqual([ x.size for x in image.files.files ],
            [1234])
        self.failUnlessEqual([ x.sha1 for x in image.files.files ],
            ['abc'])
        self.failUnlessEqual([ x.fileName for x in image.files.files ],
            ['file name'])
        self.failUnlessEqual(
            [ [ (y.url, y.urlType) for y in x.urls ] for x in image.files.files ],
            [ [
                ('http://localhost:1234', 0),
                ('http://localhost:12345', None),
                (None, 1),
            ] ],
            )

        class Controller(object):
            def url(slf, request, *args, **kwargs):
                return args[0]
        class Request(object):
            def __init__(slf, baseUrl):
                slf.baseUrl = baseUrl

        # Need to set the file ID
        counter = 42
        for f in image.files.files:
            for url in f.urls:
                url.urlType = 0
                url.fileId = counter
                counter += 1
        # Now make sure we can dump the data back in xml, and the url
        # attribute/text field doesn't cause problems.
        newxml = converter.toText("xml", image, Controller(),
            Request("irc://goo/"))

        tmpl = '<url urlType="0">irc://goo/downloadImage?fileId=%s&amp;urlType=0</url>'
        for fileId in [42, 43, 44]:
            self.assertIn(tmpl % fileId, newxml)
Esempio n. 2
0
 def processMethod(self, request, viewMethod, args, kw):
     self.controller.db.setProfiler(request.profile)
     if hasattr(viewMethod, 'model'):
         modelName, model = viewMethod.model
         # Save the body of the request
         # May need it to create a different model later on
         request.body = request.read()
         kw[modelName] = converter.fromText(request.responseType,
                                            request.body,
                                            model, self.controller, request)
Esempio n. 3
0
    def setImageDefinitions(self, request, hostname, version):
        imageDefinitionsData = request.read()
        model = converter.fromText('xml', imageDefinitionsData,
            models.BuildDefinitions, self, None)
        if model.buildDefinitions is None:
            # Should fix this downstream...
            model.buildDefinitions = []

        pd = self.db.setProductVersionBuildDefinitions(hostname, version,
            model)
        buildDefs = pd.getBuildDefinitions()
        extraParams = dict(hostname = hostname, version = version)
        buildDefModels = [ self._makeBuildDefinition(x, pd, extraParams,
            models.BuildDefinition) for x in buildDefs ]
        bdefs = models.BuildDefinitions(buildDefinitions = buildDefModels)
        return bdefs
Esempio n. 4
0
 def fromString(self, cls, text):
     controller = _Controller()
     return converter.fromText('json', text, cls, controller, None)
Esempio n. 5
0
 def testImageListModel(self):
     images = converter.fromText('xml', imageList, models.ImageList, None, 
                                 None)
     assert(images.images[0].imageId == 1)