Exemple #1
0
 def test_get_service_url_ignore_ticket(self):
     """
     Ensures ticket is ignored if present as query parameter
     """
     request = self.factory.get("/origin/", secure=True,
             data={"foo": "bar", "next": "/next-page/?cat=dog",
                     "ticket": "FAKE-ticket-456"})
     result = get_service_url(request)
     expected = ("https://testserver/origin/?foo=bar"
             "&next=%2Fnext-page%2F%3Fcat%3Ddog")
     assert_urls_equivalent(result, expected, self.assertEqual)
Exemple #2
0
    def test_get_service_url_query_parameters(self):
        """
        Ensure method preserves query parameters
        """
        request = self.factory.get("/origin/?foo=bar", secure=True)
        result = get_service_url(request, "/target/")
        expected = "https://testserver/origin/?foo=bar&next=%2Ftarget%2F"
        assert_urls_equivalent(result, expected, self.assertEqual)

        request = self.factory.get("/origin/", secure=True,
                data={"foo": "bar", "next": "/next-page/?cat=dog"})
        result = get_service_url(request)
        expected = ("https://testserver/origin/?foo=bar"
                "&next=%2Fnext-page%2F%3Fcat%3Ddog")
        assert_urls_equivalent(result, expected, self.assertEqual)
 def test_get_global_context_correct(self):
     """
     Ensure method returns the expected template context
     """
     request = self.factory.get("/accounts/login/",
                                data={
                                    "foo": "bar",
                                    "next": "/next-page/"
                                })
     result = _get_global_context(request)
     result["institutions"].sort(key=lambda x: x[0])
     expected_institutions = [
         ("Other Inst", "other-inst", "/accounts/cas-login/other-inst/",
          "/accounts/link-from-profile/other-inst/"),
         ("Test Uni", "test-uni", "/accounts/cas-login/test-uni/",
          "/accounts/link-from-profile/test-uni/"),
     ]
     expected_params = "?foo=bar&next=%2Fnext-page%2F"
     self.assertEqual(sorted(list(result.keys())),
                      ["institutions", "query_params"])
     self.assertEqual(result["institutions"], expected_institutions)
     assert_urls_equivalent(result["query_params"], expected_params,
                            self.assertEqual)
 def _run_test(self, username, params_dict, expected_url):
     user = User.objects.create(username=username)
     request = self.factory.get("/test/page/", data=params_dict)
     result = _login_success(request, user, "/next-page/")
     self.assertEqual(type(result), HttpResponseRedirect)
     assert_urls_equivalent(result.url, expected_url, self.assertEqual)