Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Greenhost
isitup
Commits
16874b9a
Commit
16874b9a
authored
Jan 21, 2021
by
Chris
Browse files
DNS 100% coverage
parent
7a7f2673
Pipeline
#5983
passed with stage
in 39 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/test_dns.py
View file @
16874b9a
...
...
@@ -7,6 +7,7 @@ import dns
import
dns.resolver
import
isitup.dns
@
pytest
.
fixture
def
mock_dns_query_response
():
def
wrapped_mock_query_response
(
*
args
,
**
kwargs
):
...
...
@@ -17,8 +18,10 @@ def mock_dns_query_response():
return
[
response
,
]
return
wrapped_mock_query_response
class
TestDnsChecks
:
@
pytest
.
mark
.
asyncio
async
def
test_post_empty
(
self
,
api
:
AsyncClient
)
->
None
:
...
...
@@ -60,7 +63,9 @@ class TestDnsChecks:
assert
"No A record found for nonexistentdomain.tld"
in
res
.
json
()[
"detail"
]
@
pytest
.
mark
.
asyncio
async
def
test_post_no_nameserver
(
self
,
api
:
AsyncClient
,
base_url
:
str
,
mocker
:
MockerFixture
)
->
None
:
async
def
test_post_no_nameserver
(
self
,
api
:
AsyncClient
,
base_url
:
str
,
mocker
:
MockerFixture
)
->
None
:
mocker
.
patch
(
"isitup.dns.LOG.fatal"
)
with
mock
.
patch
(
"dns.resolver.query"
)
as
query
:
query
.
side_effect
=
dns
.
resolver
.
NoNameservers
()
...
...
@@ -92,13 +97,29 @@ class TestDnsChecks:
assert
res
.
json
()[
"record_type"
]
==
"a"
assert
res
.
json
()[
"value"
][
0
][
"address"
]
==
"127.0.0.1"
@
pytest
.
mark
.
asyncio
async
def
test_post_mocked_bad_url
(
self
,
api
:
AsyncClient
,
base_url
:
str
,
mock_dns_query_response
:
callable
)
->
None
:
with
mock
.
patch
(
"dns.resolver.query"
)
as
query
:
query
.
side_effect
=
mock_dns_query_response
res
=
await
api
.
post
(
"/check/dns/a/"
,
json
=
{
"domain"
:
"https://"
})
query
.
assert_not_called
assert
res
.
status_code
==
status
.
HTTP_422_UNPROCESSABLE_ENTITY
assert
(
"Invalid format for domain name or URL"
in
res
.
json
()[
"detail"
][
0
][
"msg"
]
)
@
pytest
.
mark
.
asyncio
async
def
test_post_mocked_existing_url
(
self
,
api
:
AsyncClient
,
base_url
:
str
,
mock_dns_query_response
:
callable
)
->
None
:
with
mock
.
patch
(
"dns.resolver.query"
)
as
query
:
query
.
side_effect
=
mock_dns_query_response
res
=
await
api
.
post
(
"/check/dns/a/"
,
json
=
{
"domain"
:
"https://existingdomain.tld"
})
res
=
await
api
.
post
(
"/check/dns/a/"
,
json
=
{
"domain"
:
"https://existingdomain.tld"
}
)
query
.
assert_called_once_with
(
"existingdomain.tld"
,
"A"
)
assert
res
.
status_code
==
status
.
HTTP_200_OK
assert
res
.
json
()[
"record_type"
]
==
"a"
...
...
Robert Smith
@robertsmith
·
Jun 07, 2021
Amazing_Hacks_to_Learn_Synthesis_Essay_Writing.pdf
[Amazing_Hacks_to_Learn_Synthesis_Essay_Writing.pdf](/uploads/7cd3890541552bd2d1b499c44bc2c977/Amazing_Hacks_to_Learn_Synthesis_Essay_Writing.pdf)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment