Пример #1
0
    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>"}]}]}""")
Пример #2
0
 def test_urlpattern_reverse(self):
     for name, expected, args, kwargs in test_data:
         # Prepare our data by jsonifying it - this is how javascript clients should be transmitting information.
         args_json = json.dumps(args)
         kwargs_json = json.dumps(kwargs)
         # Simulate a request with our json-encoded parameters - note: we don't actually post to the url specified.
         # Instead, we pass the request directly to the view.
         rf = RequestFactory()
         post_request = rf.post('', {'djangoajax_args': args_json, 'djangoajax_kwargs': kwargs_json })
         
         response = url_reverse(post_request, name)
         # If there is no reverse match, we return an HttpResponseNotFound
         if expected is NoReverseMatch: 
             self.assertEquals(HttpResponseNotFound, type(response))
         else:
             self.assertEqual(expected, response.content)