コード例 #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
    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")