コード例 #1
0
    def testBasic_Entry_Manipulation(self):
        """Add and remove three entries to the collection"""
        info("Service Document: %s" % self.collection.context().collection)
        info("Count the entries in the collection")
        num_entries = len(list(self.collection.iter()))
        body = get_test_data("i18n.atom").encode("utf-8")

        # Add in a slug and category if allowed.
        slugs = []
        for i in range(3):
          info("Create new entry #%d" % (i+1))
          slugs.append("".join([random.choice("abcdefghijkl") for x in range(10)]))
          h, b = self.collection.create(headers = {
            'content-type': 'application/atom+xml',
            'slug': slugs[i]
            },
            body = body % (i+1, repr(time.time())))
          check_create_response(h, b)
          if i < 2:
            time.sleep(1.1)
            
        info("Count the entries in the collection after adding three.")
        entries = list(self.collection.iter())
        num_entries_after = len(entries)
        if num_entries_after != num_entries + 3:
          warning(msg.CREATE_APPEAR_COLLECTION, "All three entries did not appear in the collection.")
          return
        else:
          success("Added three entries.")

        # Confirm the order
        check_order_of_entries(entries, [3,2,1])
        
        # Retrieve an entry
        entry = Entry(entries[1])
        e = entry.etree()
        if e == None:
          raise StopTest

        # Check the slug and links
        check_entry_slug(e, slugs[1])
        check_entry_links(e, ismedia=False)
        
        
        e.find(atompubbase.model.ATOM_TITLE).text = "Internationalization - 2"
        info("Update entry #2 and write back to the collection")
        h, b = entry.put(headers={'content-type': 'application/atom+xml'}, body = tostring(e))
        check_update_response(h, b, "Entry #2")

        # Confirm new order
        check_order_of_entries(self.collection.iter(), [2,3,1])

        # Remove Entries
        for context in entries[0:3]:
          info("Remove entry")
          h, b = Entry(context).delete()
          check_remove_response(h, b)

        success("Removed three entries.")
コード例 #2
0
ファイル: appclienttest.py プロジェクト: myblup/atompubbase
def get_entry_id(context, h, b):
  entry_id = None
  if 'location' in h:
    entry_context = copy.copy(context)
    entry_context.entry = h['location']
    e = Entry(entry_context)
    idelement = e.etree().find("{%s}id" % atompubbase.model.ATOM)
    if None != idelement:
      entry_id = idelement.text
  if None == entry_id:
    info("Atom entry did not contain the required atom:id, can't continue with test.")
    raise StopTest
  return (entry_id, e)
コード例 #3
0
ファイル: appclienttest.py プロジェクト: myblup/atompubbase
def remove_entries_by_id(entries, ids):
  num_entries = len(ids)
  for econtext in entries:
    e = Entry(econtext)
    idelement = e.etree().find("{%s}id" % atompubbase.model.ATOM)
    if None != idelement and idelement.text in ids:
      info("Remove entry")
      h, b = e.delete()
      check_remove_response(h, b)
      num_entries -= 1
    if num_entries == 0:
      break
  if num_entries == 0:
    success("Removed all entries that we're previously added.")
コード例 #4
0
    def testBasic_Media_Manipulation(self):
        """Add and remove an image in the collection"""
        info("Service Document: %s" % self.collection.context().collection)
        info("Count the entries in the collection")
        num_entries = len(list(self.collection.iter()))
        
        body = get_test_data_raw("success.gif")
        
        info("Create new media entry")
        slug = "".join([random.choice("abcdefghijkl") for x in range(10)])
        h, b = self.collection.create(headers = {
          'content-type': 'image/gif',
          'slug': slug
          },
          body = body)
        check_create_response(h, b)        

        info("Count the entries in the collection after adding three.")
        entries = list(self.collection.iter())
        num_entries_after = len(entries)
        if num_entries_after != num_entries + 1:
          warning(msg.CREATE_APPEAR_COLLECTION, "New media entry did not appear in the collection.")
          return
        else:
          success("Added Media Entry")

        entry = Entry(entries[0])
        e = entry.etree()
        if e == None:
          raise StopTest

        # Check the slug
        check_entry_slug(e, slug)
        check_entry_links(e, ismedia=True)
        
        e.find(atompubbase.model.ATOM_TITLE).text = "Success"
        info("Update Media Link Entry and write back to the collection")
        h, b = entry.put(headers={'content-type': 'application/atom+xml'}, body = tostring(e))
        check_update_response(h, b, "Media Link Entry")
        
        # Remove Entry
        info("Remove entry")
        h, b = entry.delete()
        check_remove_response(h, b)
        success("Removed Media Entry")