Beispiel #1
0
 def test_output_logged_requests_with_atomic_block_should_not_be_logged_if_exception_is_raised(self):
     responses.add(responses.GET, 'http://test.cz', body='test')
     with assert_raises(TestException):
         with transaction.atomic():
             requests.get('http://test.cz')
             assert_equal(OutputLoggedRequest.objects.count(), 1)
             raise TestException
     assert_equal(OutputLoggedRequest.objects.count(), 0)
Beispiel #2
0
 def test_output_logged_requests_with_atomic_block_should_not_be_logged_if_exception_is_raised(
         self):
     responses.add(responses.GET, 'http://test.cz', body='test')
     with assert_raises(TestException):
         with transaction.atomic():
             requests.get('http://test.cz')
             assert_equal(OutputLoggedRequest.objects.count(), 1)
             raise TestException
     assert_equal(OutputLoggedRequest.objects.count(), 0)
Beispiel #3
0
    def test_every_output_request_has_data_for_stdout_logging(self, func):
        requests.get('http://test.cz')

        assert_true(func.called)
        func_args = func.call_args.args[0] if sys.version_info >= (
            3, 8) else func.call_args_list[0][0][0]  # data
        assert_in('request_timestamp', func_args)
        assert_in('response_timestamp', func_args)
        assert_in('response_time', func_args)
        assert_in('response_code', func_args)
        assert_in('host', func_args)
        assert_in('path', func_args)
        assert_in('method', func_args)
        assert_in('slug', func_args)
Beispiel #4
0
def proxy_view(request):
    return HttpResponse(
        requests.get(
            request.GET.get('url'),
            slug='proxy',
            related_objects=(request.user,) if request.user.is_authenticated else ()
        ).content
    )
Beispiel #5
0
    def test_output_logged_request_should_be_related_with_object_selected_in_decorator(
            self):
        user1 = self.create_user('test1', '*****@*****.**')
        user2 = self.create_user('test2', '*****@*****.**')

        responses.add(responses.GET, 'http://test.cz', body='test')
        assert_equal(log_context_manager.get_output_request_related_objects(),
                     [])
        with atomic_log(output_requests_slug='test1',
                        output_requests_related_objects=[user1]):
            assert_equal(
                set(log_context_manager.get_output_request_related_objects()),
                {user1})

            requests.get('http://test.cz')
            with atomic_log(output_requests_slug='test2',
                            output_requests_related_objects=[user2]):
                assert_equal(
                    set(log_context_manager.get_output_request_related_objects(
                    )), {user1, user2})
                requests.get('http://test.cz')
            assert_equal(
                set(log_context_manager.get_output_request_related_objects()),
                {user1})
            requests.get('http://test.cz')

        assert_equal(OutputLoggedRequest.objects.count(), 3)
        logged_request3, logged_request2, logged_request1 = OutputLoggedRequest.objects.all(
        )

        assert_equal(logged_request1.related_objects.get().object, user1)
        assert_equal(logged_request1.slug, 'test1')

        assert_equal(
            {
                related_object.object
                for related_object in logged_request2.related_objects.all()
            }, {user1, user2})
        assert_equal(logged_request2.slug, 'test2')

        assert_equal(logged_request3.related_objects.get().object, user1)
        assert_equal(logged_request3.slug, 'test1')
        assert_equal(log_context_manager.get_output_request_related_objects(),
                     [])
        assert_is_none(log_context_manager.get_output_request_slug())