Commit 0412be9e authored by Jens Langhammer's avatar Jens Langhammer

pyazo: more tests

parent 014a29d3
Pipeline #3201 passed with stages
in 2 minutes and 58 seconds
"""test utils"""
from django.shortcuts import reverse
from django.test import TestCase
from django.test.client import RequestFactory
from pyazo.utils import get_remote_ip, get_reverse_dns
class UtilsTest(TestCase):
"""Test utils"""
def setUp(self):
self.factory = RequestFactory()
def test_remote_ip(self):
"""test get_remote_ip"""
self.assertEqual(get_remote_ip(None), '0.0.0.0')
request = self.factory.get(reverse('index'))
request.META['HTTP_X_FORWARDED_FOR'] = 'aa'
self.assertEqual(get_remote_ip(request), 'aa')
def test_reverse_dns(self):
"""Test get_reverse_dns"""
self.assertEqual(get_reverse_dns('erqwer'), '')
......@@ -18,6 +18,6 @@ def get_reverse_dns(ipaddress: str) -> str:
rev = socket.gethostbyaddr(ipaddress)
if rev:
return rev[0]
return ''
return '' # noqa
except (socket.herror, socket.gaierror, TypeError, IndexError):
return ''
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment