Skip to content

Commit

Permalink
Fix some loopholes in unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
funilrys committed Oct 3, 2024
1 parent 42e572a commit 95db003
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 10 deletions.
1 change: 1 addition & 0 deletions PyFunceble/query/whois/query_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ def get_whois_server(

return self.iana_dataset.get_whois_server(extension)

@update_lookup_record
def get_lookup_record(
self,
) -> Optional[WhoisQueryToolRecord]:
Expand Down
12 changes: 6 additions & 6 deletions tests/query/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ def test_set_token_through_init_environment_variable_not_given(self) -> None:
In this test we test the case that nothing is given or declared.
"""

if "PYFUNCEBLE_COLLECTION_API_TOKEN" in os.environ:
if "PYFUNCEBLE_COLLECTION_API_TOKEN" in os.environ: # pragma: no cover
del os.environ["PYFUNCEBLE_COLLECTION_API_TOKEN"]

if "PYFUNCEBLE_PLATFORM_API_TOKEN" in os.environ:
if "PYFUNCEBLE_PLATFORM_API_TOKEN" in os.environ: # pragma: no cover
del os.environ["PYFUNCEBLE_PLATFORM_API_TOKEN"]

expected = ""
Expand Down Expand Up @@ -1098,10 +1098,10 @@ def test_push_with_whois_token_not_given(self) -> None:
response_dict["subject"] = "example.net"
self.availability_status_dataset["expiration_date"] = "23-nov-2090"

if "PYFUNCEBLE_COLLECTION_API_TOKEN" in os.environ:
if "PYFUNCEBLE_COLLECTION_API_TOKEN" in os.environ: # pragma: no cover
del os.environ["PYFUNCEBLE_COLLECTION_API_TOKEN"]

if "PYFUNCEBLE_PLATFORM_API_TOKEN" in os.environ:
if "PYFUNCEBLE_PLATFORM_API_TOKEN" in os.environ: # pragma: no cover
del os.environ["PYFUNCEBLE_PLATFORM_API_TOKEN"]

self.query_tool.token = ""
Expand Down Expand Up @@ -1200,10 +1200,10 @@ def test_push_token_not_given(self) -> None:
In this test, we test the case that no token is given.
"""

if "PYFUNCEBLE_COLLECTION_API_TOKEN" in os.environ:
if "PYFUNCEBLE_COLLECTION_API_TOKEN" in os.environ: # pragma: no cover
del os.environ["PYFUNCEBLE_COLLECTION_API_TOKEN"]

if "PYFUNCEBLE_PLATFORM_API_TOKEN" in os.environ:
if "PYFUNCEBLE_PLATFORM_API_TOKEN" in os.environ: # pragma: no cover
del os.environ["PYFUNCEBLE_PLATFORM_API_TOKEN"]

self.query_tool.token = ""
Expand Down
80 changes: 76 additions & 4 deletions tests/query/whois/test_query_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
limitations under the License.
"""

# pylint: disable=protected-access

import unittest
import unittest.mock

Expand Down Expand Up @@ -293,28 +295,98 @@ def test_set_query_timeout_through_init(self) -> None:

self.assertEqual(expected, actual)

def test_read_expiration_date(self) -> None:
"""
Tests the method which let us get the expiration date.
"""

self.query_tool.query_timeout = 10000.0
self.query_tool.server = "whois.example.org"
self.query_tool.subject = "example.org"
self.query_tool._expiration_date = ""

expected = ""
self.assertEqual(expected, self.query_tool.expiration_date)

self.query_tool._expiration_date = "2021-01-01 00:00:00"

expected = "2021-01-01 00:00:00"
self.assertEqual(expected, self.query_tool.expiration_date)

self.query_tool._expiration_date = None
self.query_tool.lookup_record.record = "expires: 2021-01-01 00:00:00"

expected = "01-jan-2021"
self.assertEqual(expected, self.query_tool.expiration_date)

def test_read_registrar(self) -> None:
"""
Tests the method which let us get the registrar.
"""

self.query_tool.query_timeout = 10000.0
self.query_tool.server = "whois.example.org"
self.query_tool.subject = "example.org"
self.query_tool._registrar = ""

expected = ""
self.assertEqual(expected, self.query_tool.registrar)

self.query_tool._registrar = "Example Registrar"

expected = "Example Registrar"
self.assertEqual(expected, self.query_tool.registrar)

self.query_tool._registrar = None
self.query_tool.lookup_record.record = "registrar: Example Registrar"

expected = "Example Registrar"
self.assertEqual(expected, self.query_tool.registrar)

def test_read_record(self) -> None:
"""
Tests the method which let us get the record.
"""

self.query_tool.query_timeout = 10000.0
self.query_tool.server = "whois.example.org"
self.query_tool.subject = "example.org"
self.query_tool.lookup_record.record = "Hello, World!"

expected = "Hello, World!"
self.assertEqual(expected, self.query_tool.record)

def test_get_lookup_record(self) -> None:
"""
Tests the method which let us get the lookup record.
"""

self.query_tool.server = "whois.example.org"
self.query_tool.query_timeout = 10000.0
self.query_tool.server = "whois.example.org"
self.query_tool.subject = "example.org"

self.query_tool._expiration_date = "2021-01-01 00:00:00"
self.query_tool._registrar = "Example Registrar"

actual = self.query_tool.get_lookup_record()

self.assertIsInstance(actual, WhoisQueryToolRecord)

expected = "example.org"
self.assertEqual(expected, actual.subject)

expected = 10000.0
self.assertEqual(expected, actual.query_timeout)

expected = "whois.example.org"
self.assertEqual(expected, actual.server)

expected = "2021-01-01 00:00:00"
self.assertEqual(expected, actual.expiration_date)

expected = "Example Registrar"
self.assertEqual(expected, actual.registrar)

expected = 10000.0
self.assertEqual(expected, actual.query_timeout)


if __name__ == "__main__":
unittest.main()

0 comments on commit 95db003

Please sign in to comment.