def test_handle_challenge(self): px_blocker = PXBlocker() vid = 'bf619be8-94be-458a-b6b1-ee81f154c282' px_uuid = '8712cef7-bcfa-4bb6-ae99-868025e1908a' builder = EnvironBuilder(headers=self.headers, path='/fake_app_id/init.js') env = builder.get_environ() request = Request(env) context = PxContext(request, self.config) context.vid = vid context.uuid = px_uuid context.block_action = 'j' context.block_action_data = 'Bla' message, _, _ = px_blocker.handle_blocking(context, self.config) blocking_message = 'Bla' self.assertEqual(message, blocking_message)
def test_handle_ratelimit(self): px_blocker = PXBlocker() vid = 'bf619be8-94be-458a-b6b1-ee81f154c282' px_uuid = '8712cef7-bcfa-4bb6-ae99-868025e1908a' config = PxConfig({'app_id': 'PXfake_app_id'}) builder = EnvironBuilder(headers=self.headers, path='/fake_app_id/init.js') env = builder.get_environ() request = Request(env) context = PxContext(request, self.config) context.vid = vid context.uuid = px_uuid context.block_action = 'r' message, _, _ = px_blocker.handle_blocking(context, config) blocking_message = None working_dir = os.path.dirname(os.path.realpath(__file__)) with open(working_dir + '/px_blocking_messages/ratelimit.txt', 'r') as myfile: blocking_message = myfile.read() self.assertEqual(message, blocking_message)