def test_can_determine_the_ip_address_with_the_http_x_forwarded_for_header(self):
     # Setup
     request = self.factory.get('/')
     parameters = request.META.copy()
     parameters['HTTP_X_FORWARDED_FOR'] = faker.ipv4()
     request.META = parameters
     # Run
     ip_address = get_client_ip(request)
     # Check
     assert ip_address == parameters['HTTP_X_FORWARDED_FOR']
 def test_can_determine_the_ip_address_with_the_remote_addr_header(self):
     # Setup
     request = self.factory.get('/')
     parameters = request.META.copy()
     parameters['HTTP_X_FORWARDED_FOR'] = None
     parameters['REMOTE_ADDR'] = faker.ipv4()
     request.META = parameters
     # Run
     ip_address = get_client_ip(request)
     # Check
     assert ip_address == parameters['REMOTE_ADDR']
Exemple #3
0
    def get_post_form_kwargs(self):
        """
        Returns the keyword arguments for instantiating the post form.
        """
        kwargs = {
            'user': self.request.user,
            'user_ip': get_client_ip(self.request),
            'forum': self.get_forum(),
            'topic': self.get_topic(),
        }

        post = self.get_post()
        if post:
            kwargs.update({'instance': post})

        if self.request.method in ('POST', 'PUT'):
            kwargs.update({
                'data': self.request.POST,
                'files': self.request.FILES,
            })
        return kwargs
Exemple #4
0
    def get_post_form_kwargs(self):
        """
        Returns the keyword arguments for instantiating the post form.
        """
        kwargs = {
            'user': self.request.user,
            'user_ip': get_client_ip(self.request),
            'forum': self.get_forum(),
            'topic': self.get_topic(),
        }

        post = self.get_post()
        if post:
            kwargs.update({'instance': post})

        if self.request.method in ('POST', 'PUT'):
            kwargs.update({
                'data': self.request.POST,
                'files': self.request.FILES,
            })
        return kwargs