Example #1
0
    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>"}]}""")
Example #2
0
    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>"}]}]}""")
Example #3
0
 def test_complex_payload(self):
     events = []
     events.append(AjaxEvent('CartRemove',
         # See also core/context_processors.py : favorites()
         { 
             'cart_item': { 
                 'pk' : 5 
             }, 
             'cart': { 
                 'total_price' : 9.99, 
                 'total_qty': 3
             } 
         } 
     ))
     
     request_factory = RequestFactory()
     request = request_factory.request()
     build_response(request,*events)