def get_with_index_calls_list(self):
        ''' Revision(index=-2).get() calls list() and request() with index id '''
        index   = -2
        verbose = True
        rev     = Revision(parent=self.page, index=index)
        run = lambda: rev.get(verbose=verbose)

        # calls Revision.list
        should_call_method(springnote.Revision, 'list', when=run,
            arg=with_(eq(springnote.Revision), eq(self.page), verbose=eq(verbose)),
            method_type=classmethod,
        )
    def get_with_too_large_index_raises_exception(self):
        ''' Revision(index=-10000).get() with no such revision raises error '''
        # save
        o_revision_list = springnote.Revision.list

        page    = self.page
        index   = -10000        # too big!
        id      = 4567
        verbose = True
        
        rev1, rev2 = Revision(parent=page, id=id), Revision(parent=page, id=id+1)
        rev1.date_created, rev2.date_created = 1, 2
        springnote.Revision.list = lambda *args, **kwarg: [rev2, rev1]

        # calls revision.get()
        run = lambda: Revision(parent=page, index=index).get(verbose=verbose)
        should_raise(springnote.SpringnoteError.InvalidOption, when=run)

        # restore
        springnote.Revision.list = o_revision_list
    def should_have_parent_id_and_one_of_index_or_id_and_parent_id(self):
        ''' Revision.get() without parent.id or (id|index) raises exception '''
        # (parent.id, id) is okay
        rev = Revision(self.page, id=3)
        should_call_method(springnote.Revision, 'request', when=lambda: rev.get())

        # (parent.id, index) is okay
        rev = Revision(self.page, index=-3)
        should_call_method(springnote.Revision, 'list', when=lambda: rev.get())

        # (parent.id=None, id or index) is NOT okay
        idless_page = springnote.Page(self.page.auth, None) 
        pageid_less_rev = springnote.Revision(idless_page, id=123)
        should_raise(springnote.SpringnoteError.InvalidOption, 
                    when=lambda: pageid_less_rev.get())

        # (parent.id, id=None, index=None) is NOT okay
        id_less_rev = springnote.Revision(self.page, id=None, index=None)
        should_raise(springnote.SpringnoteError.InvalidOption, 
                    when=lambda: id_less_rev.get())
    def get_with_index_calls_get_with_id_from_list(self):
        ''' Revision(index=-2).get() calls request with -2th id of revisions '''
        # save
        o_revision_list = springnote.Revision.list

        page    = self.page
        index   = -2
        id      = 4567
        verbose = True
        
        rev1 = Revision(parent=page, id=id)
        rev2 = Revision(parent=page, id=id+1)
        rev1.date_created = 1
        rev2.date_created = 2
        springnote.Revision.list = lambda *args, **kwarg: [rev2, rev1]

        # calls revision.get()
        rev = Revision(parent=page, index=index)
        run = lambda: rev.get(verbose=verbose)
        url = "/pages/%d/revisions/%d." % (page.id, id)
        should_call_method(springnote.Revision, 'request', when=run,
            arg=with_at_least(eq(rev), contains_string(url), verbose=eq(verbose)))

        # restore
        springnote.Revision.list = o_revision_list
    def _test_revision_object(self, page):
        # LIST reivisions - count 4 (page create, update, attachment create, update)
        _starting("test revision.list() ..")
        revs = Revision.list(page, verbose=global_verbose)
        assert_that(revs, has_length(4))
        first = min(revs, key=lambda x: x.date_created)
        #assert_that(first.description, 
        #                contains_string('이 페이지를 개설하였습니다'))
        assert_that(first.relation_is_part_of, is_(page.id))
        some_rev = filter(lambda r: r.description == '', revs)[0]
        assert_that(some_rev.source, is_(None))
        _okay()

        # GET revision 
        _starting("test revision.get() ..")
        rev = Revision(page, id=some_rev.id).get(verbose=global_verbose)
        assert_that(rev.source, is_not(None))
        _okay()