def test_render_public_consent(self): """You can observe the terms form without specifying a user""" resource = consent_resource.ConsentResource(self.hs) request, channel = self.make_request("GET", "/consent?v=1", shorthand=False) render(request, resource, self.reactor) self.assertEqual(channel.code, 200)
def test_accept_consent(self): """ A user can use the consent form to accept the terms. """ uri_builder = ConsentURIBuilder(self.hs.config) resource = consent_resource.ConsentResource(self.hs) # Register a user user_id = self.register_user("user", "pass") access_token = self.login("user", "pass") # Fetch the consent page, to get the consent version consent_uri = ( uri_builder.build_user_consent_uri(user_id).replace("_matrix/", "") + "&u=user" ) channel = make_request( self.reactor, FakeSite(resource, self.reactor), "GET", consent_uri, access_token=access_token, shorthand=False, ) self.assertEqual(channel.code, 200) # Get the version from the body, and whether we've consented version, consented = channel.result["body"].decode("ascii").split(",") self.assertEqual(consented, "False") # POST to the consent page, saying we've agreed channel = make_request( self.reactor, FakeSite(resource, self.reactor), "POST", consent_uri + "&v=" + version, access_token=access_token, shorthand=False, ) self.assertEqual(channel.code, 200) # Fetch the consent page, to get the consent version -- it should have # changed channel = make_request( self.reactor, FakeSite(resource, self.reactor), "GET", consent_uri, access_token=access_token, shorthand=False, ) self.assertEqual(channel.code, 200) # Get the version from the body, and check that it's the version we # agreed to, and that we've consented to it. version, consented = channel.result["body"].decode("ascii").split(",") self.assertEqual(consented, "True") self.assertEqual(version, "1")
def test_render_public_consent(self) -> None: """You can observe the terms form without specifying a user""" resource = consent_resource.ConsentResource(self.hs) channel = make_request( self.reactor, FakeSite(resource, self.reactor), "GET", "/consent?v=1", shorthand=False, ) self.assertEqual(channel.code, HTTPStatus.OK)