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

Lint

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