Esempio n. 1
0
 def tornado_call(
     self,
     view_func: Callable[[HttpRequest, UserProfile], HttpResponse],
     user_profile: UserProfile,
     post_data: Dict[str, Any],
 ) -> HttpResponse:
     request = POSTRequestMock(post_data, user_profile)
     return view_func(request, user_profile)
Esempio n. 2
0
    def test_tornado_endpoint(self) -> None:

        # This test is mostly intended to get minimal coverage on
        # the /notify_tornado endpoint, so we can have 100% URL coverage,
        # but it does exercise a little bit of the codepath.
        post_data = dict(
            data=orjson.dumps(
                dict(
                    event=dict(
                        type="other",
                    ),
                    users=[self.example_user("hamlet").id],
                ),
            ).decode(),
        )
        req = POSTRequestMock(post_data, user_profile=None)
        req.META["REMOTE_ADDR"] = "127.0.0.1"
        result = self.client_post_request("/notify_tornado", req)
        self.assert_json_error(result, "Access denied", status_code=403)

        post_data["secret"] = settings.SHARED_SECRET
        req = POSTRequestMock(post_data, user_profile=None)
        req.META["REMOTE_ADDR"] = "127.0.0.1"
        result = self.client_post_request("/notify_tornado", req)
        self.assert_json_success(result)
Esempio n. 3
0
 def tornado_call(view_func, user_profile, post_data):
     # type: (Callable[[HttpRequest, UserProfile], HttpResponse], UserProfile, Dict[str, Any]) -> HttpResponse
     request = POSTRequestMock(post_data, user_profile)
     return view_func(request, user_profile)
Esempio n. 4
0
 def tornado_call(self, view_func, user_profile, post_data,
                  callback=None):
     request = POSTRequestMock(post_data, user_profile, callback)
     return view_func(request, user_profile)