Exemplo n.º 1
0
 def _data(self):
     """fetch and approve by key"""
     i = interpretation.poot(
         { 'key_string': self.request.get('key_string') })
     if i != None:
         interpretation.approve(i, self.request.get('owner_baton'))
     return i
Exemplo n.º 2
0
    def test_basic_pagination(self):
        actual_count = 21
        for id in range(1, actual_count):
            i = _stc(interpretation.T_TEXT, str(id))
            interpretation.approve(i, i.owner_baton)

        for page_size in [1, 2, 3, 4, 5, 10, 20, 25]:
            looking_for = set(range(1, actual_count))
            pages = interpretation.list_pages({}, page_size)
            logging.info(repr(pages))

            for page in pages:
                logging.info('page %d of %d (size %d)' % (page['page_number'], len(pages), page_size))
                self.assert_(page['page_number'] > 0)
                l = interpretation.list_interpretations({'offset_key_string': page['offset_key_string']}, page_size)
                self.assert_(len(l) <= page_size)

                ## this will blow up if we get a duplicate during page-walking
                for i in l:
                    looking_for.remove(int(i.content))

            ## make sure we found every single interpretation
            self.assertEquals(len(looking_for), 0)
Exemplo n.º 3
0
    def test_submit_approve(self):
        ## submitting an interpretation should create an inactive one
        i = interpretation.submit(
                           title=u'Test',
                           author='Anonymous',
                           type=interpretation.T_TEXT,
                           content='fnord')
        self.assertFalse(i.is_active)

        ## fetching it is possible if specific key is provided
        self.assertEquals(interpretation.count({'key_string': str(i.key())}), 1)
        for j in [interpretation.poot({'key_string': str(i.key())}), interpretation.list_interpretations({'key_string': str(i.key())}, 20)[0]]:
            ## and the fetched interpretation should be identical
            self.assertEquals(i.title_link, j.title_link)
            self.assertEquals(i.title, j.title)
            self.assertEquals(i.type, j.type)
            self.assertEquals(i.content_type, j.content_type)
            self.assertEquals(i.content, j.content)
            self.assertEquals(i.is_active, j.is_active)
            self.assertEquals(i.author, j.author)

        ## even with a title_link (unique) fetch, can't see it yet:
        self.assertEquals(interpretation.count({'title_link': i.title_link}), 0)
        self.assertEquals(interpretation.list_interpretations({'title_link': i.title_link}, 20), [])
        self.assertEquals(interpretation.list_pages({'title_link': i.title_link}, 20), [])
        self.assertEquals(interpretation.poot({'title_link': i.title_link}), None)

        ## with an author fetch, can't see it yet:
        self.assertEquals(interpretation.count({'author': i.author}), 0)
        self.assertEquals(interpretation.list_interpretations({'author': i.author}, 20), [])
        self.assertEquals(interpretation.list_pages({'author': i.author}, 20), [])
        self.assertEquals(interpretation.poot({'author': i.author}), None)

        ## with a type fetch, can't see it yet:
        self.assertEquals(interpretation.count({'type': i.type}), 0)
        self.assertEquals(interpretation.list_interpretations({'type': i.type}, 20), [])
        self.assertEquals(interpretation.list_pages({'type': i.type}, 20), [])
        self.assertEquals(interpretation.poot({'type': i.type}), None)

        ## but fetching without a key should return nothing
        self.assertEquals(interpretation.count({}), 0)
        self.assertEquals(interpretation.list_interpretations({}, 20), [])
        self.assertEquals(interpretation.list_pages({}, 20), [])
        self.assertEquals(interpretation.poot({}), None)

        ## attempting to approve with no owner_baton or bunk owner_baton should fail
        self.assertRaises(interpretation.BadOwnerBaton, interpretation.approve, i, None)
        self.assertRaises(interpretation.BadOwnerBaton, interpretation.approve, i, "blah blah blah")

        ## approving it should activate it; should now be able to see it via title_link fetches
        interpretation.approve(i, i.owner_baton)
        self.assertTrue(i.is_active)
        self.assertEquals(interpretation.count({'title_link': i.title_link}), 1)
        self.assertEquals(interpretation.count({'author': i.author}), 1)
        for j in [interpretation.poot({'key_string': str(i.key())}), interpretation.list_interpretations({'key_string': str(i.key())}, 20)[0], interpretation.poot({'title_link': i.title_link}), interpretation.list_interpretations({'title_link': i.title_link}, 20)[0], interpretation.poot({'author': i.author}), interpretation.list_interpretations({'author': i.author}, 20)[0], interpretation.poot({'type': i.type}), interpretation.list_interpretations({'type': i.type}, 20)[0]]:
            self.assertEquals(i.is_active, j.is_active)

        ## now fetching without a key should bring it up
        self.assertEquals(interpretation.count({}), 1)
        k = interpretation.poot({})
        self.assertEquals(str(i.key()), str(k.key()))
        l = interpretation.list_interpretations({}, 20)
        self.assertEquals(str(i.key()), str(l[0].key()))
        lp = interpretation.list_pages({}, 20)
        self.assertEquals(lp[0]['page_number'], 1)
        self.assertEquals(lp[0]['offset_key_string'], str(i.key()))