def test_ajax_message(self): """ Test that messages encode nicely when we package them into an AjaxMessage() """ request_factory = RequestFactory() auth_result = request_factory.login(username='******', password='******') self.failUnlessEqual(auth_result, True, "Assert that our test client can log in.") request = request_factory.request() messages.add_message(request,messages.INFO,'Testing') test_response = AjaxMessage(messages.get_messages(request)) self.failUnlessEqual(str(test_response), """{"type": "Messages", "djangoPayload": true, "payload": [{"type": "MessageItem", "djangoPayload": true, "payload": " <li class=\\"info message-item ui-corner-all\\">\\n\\t<div class=\\"icon\\"></div>Testing\\n</li>"}]}""")
def test_build_response(self): """ Test the buid_response shortcut function, which automatically appends messages and accepts an arguments list of `AjaxContent` as additional parameters. """ request_factory = RequestFactory() auth_result = request_factory.login(username='******', password='******') self.failUnlessEqual(auth_result, True, "Assert that our test client can log in.") request = request_factory.request() messages.add_message(request,messages.INFO,'Testing') test_response = build_response(request) self.failUnlessEqual(str(test_response), """Content-Type: application/json\n\n{"type": "Response", "djangoPayload": true, "payload": [{"type": "Messages", "djangoPayload": true, "payload": [{"type": "MessageItem", "djangoPayload": true, "payload": " <li class=\\"info message-item ui-corner-all\\">\\n\\t<div class=\\"icon\\"></div>Testing\\n</li>"}]}]}""")
def test_build_response_namespace(self): """ Tests that our optional namespace gets captured if it's part of the post variables. """ request_factory = RequestFactory() auth_result = request_factory.login(username='******', password='******') self.failUnlessEqual(auth_result, True, "Assert that our test client can log in.") request = request_factory.post('',{"namespace" : "test-namespace"}) messages.add_message(request,messages.INFO,'Testing') test_response = build_response(request) self.failUnlessEqual(str(test_response), """Content-Type: application/json\n\n{"type": "Response", "namespace": "test-namespace", "djangoPayload": true, "payload": [{"type": "Messages", "djangoPayload": true, "payload": [{"type": "MessageItem", "djangoPayload": true, "payload": " <li class=\\"info message-item ui-corner-all\\">\\n\\t<div class=\\"icon\\"></div>Testing\\n</li>"}]}]}""")