import unittest from model import model from config import config from urls.main import urls as app from tests.utils import cleanup try: from xml.etree.ElementTree import fromstring, tostring except: from elementtree.ElementTree import fromstring, tostring from StringIO import StringIO from urllib import urlencode ATOM = "http://www.w3.org/2005/Atom" XHTML = "http://www.w3.org/1999/xhtml" class Feeds(unittest.TestCase): def setUp(self): cleanup() """Add an entry to start.""" # Load the test configuration config.read('tests/test_comments.ini') # Create a new entry entries = model.entry self.id = entries.create(dict(title="Test")) def start_response(self, status, headers): self.status = status self.headers = headers def test_feeds(self): request_body = StringIO(urlencode(dict( name="Joe (http://bitworking.org)", example="Joe (http://bitworking.org)", comment="This is bold" ))) environ = { 'PATH_INFO': '/1/Test', 'REQUEST_METHOD': 'POST', 'REQUEST_URI': '/1/Test', 'wsgi.input': request_body } body = app(environ, self.start_response) self.assertEqual("303 See Other", self.status) headers = dict(self.headers) self.assertTrue('location' in headers) self.assertEqual(headers['location'], '/1/Test;edit_comment_form?key=1d08b9105f889a78fa0936b8e9d1c609d96816e3&comment_id=1#X1') # Now build a WSGI/HTTP request and submit it to the app environ = { 'PATH_INFO': '/feed/', 'REQUEST_METHOD': 'GET', } body = app(environ, self.start_response) # Confirm the template gets filled in properly # and that the response is right body = fromstring("".join(body)) link = body.find(".//{%s}entry/{%s}link" % (ATOM, ATOM)) # TODO Fix this test, actually the code that breaks it. #self.assertEqual("1/Test", link.attrib['href']) self.assertEqual("200 Ok", self.status) self.assertTrue('etag' in dict(self.headers)) # Now do the same for the comments feed environ = { 'PATH_INFO': '/comments/feed/', 'REQUEST_METHOD': 'GET', } body = app(environ, self.start_response) # Confirm the template gets filled in properly # and that the response is right self.assertEqual("200 Ok", self.status) self.assertTrue('etag' in dict(self.headers)) body = fromstring("".join(body)) b = body.find(".//{%s}b" % XHTML) self.assertEqual("This is bold", b.text)