Commit 4e315e81 authored by Romain Courteaud's avatar Romain Courteaud

Lint

parent b8bd2d34
import unittest import unittest
from urlchecker_db import LogDB from urlchecker_db import LogDB
import peewee
class UrlCheckerDBTestCase(unittest.TestCase): class UrlCheckerDBTestCase(unittest.TestCase):
......
...@@ -43,7 +43,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -43,7 +43,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
rdtype = "foo" rdtype = "foo"
answer_list = ["4.3.2.1", "1.2.3.4"] answer_list = ["4.3.2.1", "1.2.3.4"]
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
result = logDnsQuery( logDnsQuery(
self.db, status_id, resolver_ip, domain, rdtype, answer_list self.db, status_id, resolver_ip, domain, rdtype, answer_list
) )
answer_list.extend("127.0.0.1") answer_list.extend("127.0.0.1")
...@@ -165,7 +165,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -165,7 +165,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
rdtype_2 = rdtype + "bar" rdtype_2 = rdtype + "bar"
answer_list = ["4.3.2.1", "1.2.3.4"] answer_list = ["4.3.2.1", "1.2.3.4"]
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
result = logDnsQuery( logDnsQuery(
self.db, status_id, resolver_ip, domain, rdtype, answer_list self.db, status_id, resolver_ip, domain, rdtype, answer_list
) )
logDnsQuery( logDnsQuery(
......
...@@ -29,21 +29,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -29,21 +29,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
################################################ ################################################
# getUserAgent # getUserAgent
################################################ ################################################
def test_getUserAgent_default(self): def test_getUserAgent_version(self):
result = getUserAgent()
assert (
result
== "URLCHECKER/0 (+https://lab.nexedi.com/romain/url-checker)"
)
def test_getUserAgent_default(self):
result = getUserAgent(None)
assert (
result
== "URLCHECKER/0 (+https://lab.nexedi.com/romain/url-checker)"
)
def test_getUserAgent_default(self):
result = getUserAgent("0.0.3") result = getUserAgent("0.0.3")
assert ( assert (
result result
...@@ -56,7 +42,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -56,7 +42,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
def test_request_arguments(self): def test_request_arguments(self):
url_to_proxy = "http://example.org/" url_to_proxy = "http://example.org/"
with mock.patch("urlchecker_http.requests.request") as mock_request: with mock.patch("urlchecker_http.requests.request") as mock_request:
response = request(url_to_proxy) request(url_to_proxy)
assert mock_request.call_count == 1 assert mock_request.call_count == 1
mock_request.assert_called_with( mock_request.assert_called_with(
"GET", "GET",
...@@ -178,6 +164,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -178,6 +164,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
assert self.db.HttpCodeChange.get().url == url assert self.db.HttpCodeChange.get().url == url
assert self.db.HttpCodeChange.get().status_code == status_code assert self.db.HttpCodeChange.get().status_code == status_code
assert self.db.HttpCodeChange.get().status_id == status_id assert self.db.HttpCodeChange.get().status_id == status_id
assert result == status_id
def test_logHttpStatus_insertOnlyOnePerStatusIdIPUrl(self): def test_logHttpStatus_insertOnlyOnePerStatusIdIPUrl(self):
ip = "127.0.0.1" ip = "127.0.0.1"
...@@ -189,7 +176,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -189,7 +176,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
logHttpStatus(self.db, ip, url, status_code + 1, status_id) logHttpStatus(self.db, ip, url, status_code + 1, status_id)
except peewee.IntegrityError: except peewee.IntegrityError:
assert self.db.HttpCodeChange.select().count() == 1 assert self.db.HttpCodeChange.select().count() == 1
assert self.db.HttpCodeChange.get().status == result assert self.db.HttpCodeChange.get().status_id == result
else: else:
raise NotImplementedError("Expected IntegrityError") raise NotImplementedError("Expected IntegrityError")
...@@ -263,10 +250,10 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -263,10 +250,10 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
url_2 = url + "2" url_2 = url + "2"
status_code = 200 status_code = 200
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
result = logHttpStatus(self.db, ip, url, status_code, status_id) logHttpStatus(self.db, ip, url, status_code, status_id)
result_2 = logHttpStatus(self.db, ip_2, url, status_code, status_id) logHttpStatus(self.db, ip_2, url, status_code, status_id)
result_3 = logHttpStatus(self.db, ip, url_2, status_code, status_id) logHttpStatus(self.db, ip, url_2, status_code, status_id)
result_4 = logHttpStatus(self.db, ip_2, url_2, status_code, status_id) logHttpStatus(self.db, ip_2, url_2, status_code, status_id)
assert self.db.HttpCodeChange.select().count() == 4 assert self.db.HttpCodeChange.select().count() == 4
################################################ ################################################
......
...@@ -29,6 +29,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase): ...@@ -29,6 +29,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
assert self.db.NetworkChange.get().transport == transport assert self.db.NetworkChange.get().transport == transport
assert self.db.NetworkChange.get().state == state assert self.db.NetworkChange.get().state == state
assert self.db.NetworkChange.get().status_id == status_id assert self.db.NetworkChange.get().status_id == status_id
assert result == status_id
def test_logNetwork_insertOnlyOnePerStatusIdIPPortTransport(self): def test_logNetwork_insertOnlyOnePerStatusIdIPPortTransport(self):
ip = "127.0.0.1" ip = "127.0.0.1"
...@@ -37,7 +38,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase): ...@@ -37,7 +38,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
state = "bar" state = "bar"
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
result = logNetwork(self.db, ip, transport, port, state, status_id) logNetwork(self.db, ip, transport, port, state, status_id)
try: try:
logNetwork(self.db, ip, transport, port, state + ".", status_id) logNetwork(self.db, ip, transport, port, state + ".", status_id)
except peewee.IntegrityError: except peewee.IntegrityError:
......
...@@ -58,7 +58,7 @@ def queryDNS(db, status_id, resolver_ip, resolver, domain_text, rdtype): ...@@ -58,7 +58,7 @@ def queryDNS(db, status_id, resolver_ip, resolver, domain_text, rdtype):
): ):
answer_list = [] answer_list = []
logDNSQuery(db, status_id, resolver_ip, domain_text, rdtype, answer_list) logDnsQuery(db, status_id, resolver_ip, domain_text, rdtype, answer_list)
return answer_list return answer_list
......
import requests import requests
from urllib.parse import urlparse, urlunsplit from urllib.parse import urlparse, urlunsplit
import sys
import traceback
from forcediphttpsadapter.adapters import ForcedIPHTTPSAdapter from forcediphttpsadapter.adapters import ForcedIPHTTPSAdapter
...@@ -79,7 +77,7 @@ def logHttpStatus(db, ip, url, code, status_id): ...@@ -79,7 +77,7 @@ def logHttpStatus(db, ip, url, code, status_id):
previous_entry = db.HttpCodeChange.create( previous_entry = db.HttpCodeChange.create(
status=status_id, ip=ip, url=url, status_code=code status=status_id, ip=ip, url=url, status_code=code
) )
return previous_entry.status return previous_entry.status_id
def checkHttpStatus(db, status_id, url, ip, bot_version): def checkHttpStatus(db, status_id, url, ip, bot_version):
......
...@@ -30,7 +30,7 @@ def logNetwork(db, ip, transport, port, state, status_id): ...@@ -30,7 +30,7 @@ def logNetwork(db, ip, transport, port, state, status_id):
port=port, port=port,
state=state, state=state,
) )
return previous_entry.status return previous_entry.status_id
def isTcpPortOpen(db, ip, port, status_id): def isTcpPortOpen(db, ip, port, status_id):
......
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