def test_bad_title_link(self): ## none self.assertEquals(interpretation.poot({'title_link':None}), None) self.assertEquals(interpretation.count({'title_link':None}), 0) self.assertEquals(interpretation.list_interpretations({'title_link':None}, 20), []) ## refers to no element self.assertEquals(interpretation.poot({'title_link':'foo-bar-baz'}), None) self.assertEquals(interpretation.count({'title_link':'foo-bar-baz'}), 0) self.assertEquals(interpretation.list_interpretations({'title_link':'foo-bar-baz'}, 20), [])
def test_bad_key(self): ## none self.assertEquals(interpretation.poot({'key_string':None}), None) self.assertEquals(interpretation.count({'key_string':None}), 0) self.assertEquals(interpretation.list_interpretations({'key_string':None}, 20), []) ## does not look like a real key self.assertEquals(interpretation.poot({'key_string':'asdf'}), None) self.assertEquals(interpretation.count({'key_string':'asdf'}), 0) self.assertEquals(interpretation.list_interpretations({'key_string':'asdf'}, 20), []) ## looks like a real key, but refers to no element self.assertEquals(interpretation.poot({'key_string':'aglwb290LXBvb3RyFAsSDkludGVycHJldGF0aW9uGAIM'}), None) self.assertEquals(interpretation.count({'key_string':'aglwb290LXBvb3RyFAsSDkludGVycHJldGF0aW9uGAIM'}), 0) self.assertEquals(interpretation.list_interpretations({'key_string':'aglwb290LXBvb3RyFAsSDkludGVycHJldGF0aW9uGAIM'}, 20), [])
def get(self): """GET handler""" if 'Content-Type' in self.response.headers: del self.response.headers['Content-Type'] self.response.headers.add_header('Content-Type', 'application/rss+xml') self.response.out.write(""" <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel> <atom:link href="%sfeeds/interpretations/" rel="self" type="application/rss+xml"/> <title>poot poot</title> <link>%s</link> <description>poot interpretations</description> """ % (integration.INTEGRATIONS['APP_ROOT_URL'], integration.INTEGRATIONS['APP_ROOT_URL'])) interpretations = interpretation.list_interpretations({}, 1000) interpretations.reverse() for i in interpretations: description = i.title if i.type == interpretation.T_IMAGE: description = "<img src=\"%si/%s\" " % (integration.INTEGRATIONS['APP_ROOT_URL'], i.key()) description += "alt=\"%s\" title=\"%s\">" % (i.title, i.title) self.response.out.write(""" <item> <title>%s</title> <guid>%sinterpretation/%s.html</guid> <link>%sinterpretation/%s.html</link> <description>%s</description> <dc:creator>%s</dc:creator> <pubDate>%s</pubDate> </item> """ % (i.title, integration.INTEGRATIONS['APP_ROOT_URL'], i.title_link, integration.INTEGRATIONS['APP_ROOT_URL'], i.title_link, description, i.author, i.created_at.strftime('%a, %d %b %Y %H:%M:%S GMT'))) self.response.out.write(""" </channel> </rss> """)
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)
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()))
def _data(self): """fetch list of matching interpretations""" if not self.request.get('items'): raise api_request_handler.MalformedRequest() return interpretation.list_interpretations(_get_filter_arguments(self.request), int(self.request.get('items')))