示例#1
0
 def test_app_get(self):
     doc = app.Document(base_uri='http://localhost:%i/service' % HTTP_PORT)
     client = app.Client()
     doc.read(reqManager=client)
     svc = doc.root
     self.assertTrue(isinstance(svc, app.Service), "GET /service")
     for ws in svc.Workspace:
         for c in ws.Collection:
             feed_doc = app.Document(base_uri=c.get_feed_url())
             feed_doc.read(reqManager=client)
             feed = feed_doc.root
             self.assertTrue(isinstance(feed, atom.Feed),
                             "Collection not a feed for %s" % c.Title)
示例#2
0
 def test_collection(self):
     s = app.Server("http://localhost/service")
     ws = s.service.add_child(app.Workspace)
     title = ws.add_child(atom.Title)
     title_text = "Collections"
     title.set_value(title_text)
     c1 = ws.add_child(app.Collection)
     c1.add_child(atom.Title).set_value("Collection 1")
     c1.href = "c1"
     c2 = ws.add_child(app.Collection)
     c2.add_child(atom.Title).set_value("Collection 2")
     c2.href = "/etc/c2"
     request = MockRequest('/service')
     request.send(s)
     doc = app.Document(base_uri="http://localhost/service")
     doc.read(request.wfile.getvalue())
     svc = doc.root
     self.assertTrue(
         len(svc.Workspace[0].Collection) == 2, "Server: two collections")
     c2_result = svc.Workspace[0].Collection[1]
     self.assertTrue(c2_result.Title.get_value() == "Collection 2",
                     "Server: two collections title")
     self.assertTrue(
         c2_result.resolve_uri(c2_result.href) == "http://localhost/etc/c2",
         "Server: collection href")
示例#3
0
 def test_workspace(self):
     s = app.Server("http://localhost/service")
     ws = s.service.add_child(app.Workspace)
     title = ws.add_child(atom.Title)
     title_text = "Some work space while others space work"
     title.set_value(title_text)
     request = MockRequest('/service')
     request.send(s)
     doc = app.Document(base_uri="http://localhost/service")
     doc.read(request.wfile.getvalue())
     svc = doc.root
     self.assertTrue(len(svc.Workspace) == 1, "Server: one workspace")
     self.assertTrue(svc.Workspace[0].Title.get_value() == title_text,
                     "Server: one workspace title")
示例#4
0
 def test_constructor(self):
     s = app.Server("http://localhost/service")
     self.assertTrue(isinstance(s.service, app.Service), "Service document")
     request = MockRequest('/service')
     request.send(s)
     self.assertTrue(request.responseCode == 200)
     clen = int(request.responseHeaders['CONTENT-LENGTH'])
     cdata = request.wfile.getvalue()
     self.assertTrue(len(cdata) == clen, "Content-Length mismatch")
     doc = app.Document(base_uri="http://localhost/service")
     doc.read(cdata)
     svc = doc.root
     self.assertTrue(isinstance(svc, app.Service), "Server: GET /service")
     self.assertTrue(len(svc.Workspace) == 0, "Server: no workspaces")
示例#5
0
 def test_read_xml(self):
     doc = app.Document()
     doc.read(src=io.BytesIO(SVC_EXAMPLE_1))
     svc = doc.root
     self.assertTrue(isinstance(svc, app.Service),
                     "Example 1 not a service")
     wspace = svc.Workspace
     self.assertTrue(len(wspace) == 2, "Example 1 has no workspaces")
     ws = wspace[0]
     title = ws.Title
     self.assertTrue(
         isinstance(title, atom.Text) and title.get_value() == "Main Site",
         "Example 1, workspace 1 title")
     collections = ws.Collection
     self.assertTrue(
         len(collections) == 2, "Example 1, workspace 1 has no collections")
     c = collections[0]
     self.assertTrue(
         isinstance(c, app.Collection)
         and c.href == "http://example.org/blog/main",
         "Collection type or href")
     title = c.Title
     self.assertTrue(
         isinstance(title, atom.Text)
         and title.get_value() == "My Blog Entries", "Collection title")
     cats = c.Categories[0]
     self.assertTrue(
         isinstance(cats, app.Categories)
         and cats.href == "http://example.com/cats/forMain.cats",
         "Collection categories")
     accepts = collections[1].Accept
     self.assertTrue(
         len(accepts) == 3 and accepts[0].get_value() == "image/png"
         and accepts[2].get_value() == "image/gif", "Collection accepts")
     cats = wspace[1].Collection[0].Categories[0]
     self.assertTrue(cats.fixed, "Collection categories fixed")
     cat_list = cats.Category
     self.assertTrue(len(cat_list) == 2, "Collection category list")
     cat = cat_list[0]
     self.assertTrue(
         isinstance(cat, atom.Category)
         and cat.scheme == "http://example.org/extra-cats/"
         and cat.term == "joke", "Collection category 1")
     cat = cat_list[1]
     self.assertTrue(
         isinstance(cat, atom.Category)
         and cat.scheme == "http://example.org/extra-cats/"
         and cat.term == "serious", "Collection category 2")