mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 10:46:06 +02:00
added TestDomainAvailable to test_models_domain.py
This commit is contained in:
parent
a3c0ba77f7
commit
ffcc77de4e
2 changed files with 113 additions and 1 deletions
|
@ -45,6 +45,7 @@ try:
|
||||||
from .client import CLIENT, commands
|
from .client import CLIENT, commands
|
||||||
from .errors import RegistryError, ErrorCode
|
from .errors import RegistryError, ErrorCode
|
||||||
from epplib.models import common
|
from epplib.models import common
|
||||||
|
from epplib import responses
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -52,6 +53,7 @@ __all__ = [
|
||||||
"CLIENT",
|
"CLIENT",
|
||||||
"commands",
|
"commands",
|
||||||
"common",
|
"common",
|
||||||
|
"responses",
|
||||||
"ErrorCode",
|
"ErrorCode",
|
||||||
"RegistryError",
|
"RegistryError",
|
||||||
]
|
]
|
||||||
|
|
|
@ -5,7 +5,7 @@ This file tests the various ways in which the registrar interacts with the regis
|
||||||
"""
|
"""
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.db.utils import IntegrityError
|
from django.db.utils import IntegrityError
|
||||||
from unittest.mock import patch, call
|
from unittest.mock import MagicMock, patch, call
|
||||||
import datetime
|
import datetime
|
||||||
from registrar.models import Domain
|
from registrar.models import Domain
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ from .common import MockEppLib
|
||||||
from epplibwrapper import (
|
from epplibwrapper import (
|
||||||
commands,
|
commands,
|
||||||
common,
|
common,
|
||||||
|
responses,
|
||||||
RegistryError,
|
RegistryError,
|
||||||
ErrorCode,
|
ErrorCode,
|
||||||
)
|
)
|
||||||
|
@ -263,6 +264,115 @@ class TestDomainStatuses(MockEppLib):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
|
||||||
|
class TestDomainAvailable(MockEppLib):
|
||||||
|
"""Test Domain.available"""
|
||||||
|
|
||||||
|
# No SetUp or tearDown necessary for these tests
|
||||||
|
|
||||||
|
def test_domain_available(self):
|
||||||
|
"""
|
||||||
|
Scenario: Testing whether an available domain is available
|
||||||
|
Should return True
|
||||||
|
|
||||||
|
Mock response to mimic EPP Response
|
||||||
|
Validate CheckDomain command is called
|
||||||
|
Validate response given mock
|
||||||
|
"""
|
||||||
|
def side_effect(_request, cleaned):
|
||||||
|
return MagicMock(
|
||||||
|
res_data=[
|
||||||
|
responses.check.CheckDomainResultData(name='available.gov', avail=True, reason=None)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
patcher = patch("registrar.models.domain.registry.send")
|
||||||
|
mocked_send = patcher.start()
|
||||||
|
mocked_send.side_effect = side_effect
|
||||||
|
|
||||||
|
available = Domain.available("available.gov")
|
||||||
|
mocked_send.assert_has_calls(
|
||||||
|
[
|
||||||
|
call(
|
||||||
|
commands.CheckDomain(
|
||||||
|
[
|
||||||
|
"available.gov"
|
||||||
|
],
|
||||||
|
),
|
||||||
|
cleaned=True,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.assertTrue(available)
|
||||||
|
patcher.stop()
|
||||||
|
|
||||||
|
def test_domain_unavailable(self):
|
||||||
|
"""
|
||||||
|
Scenario: Testing whether an unavailable domain is available
|
||||||
|
Should return False
|
||||||
|
|
||||||
|
Mock response to mimic EPP Response
|
||||||
|
Validate CheckDomain command is called
|
||||||
|
Validate response given mock
|
||||||
|
"""
|
||||||
|
def side_effect(_request, cleaned):
|
||||||
|
return MagicMock(
|
||||||
|
res_data=[
|
||||||
|
responses.check.CheckDomainResultData(
|
||||||
|
name='unavailable.gov',
|
||||||
|
avail=False,
|
||||||
|
reason="In Use"
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
patcher = patch("registrar.models.domain.registry.send")
|
||||||
|
mocked_send = patcher.start()
|
||||||
|
mocked_send.side_effect = side_effect
|
||||||
|
|
||||||
|
available = Domain.available("unavailable.gov")
|
||||||
|
mocked_send.assert_has_calls(
|
||||||
|
[
|
||||||
|
call(
|
||||||
|
commands.CheckDomain(
|
||||||
|
[
|
||||||
|
"unavailable.gov"
|
||||||
|
],
|
||||||
|
),
|
||||||
|
cleaned=True,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.assertFalse(available)
|
||||||
|
patcher.stop()
|
||||||
|
|
||||||
|
def test_domain_available_with_value_error(self):
|
||||||
|
"""
|
||||||
|
Scenario: Testing whether an invalid domain is available
|
||||||
|
Should throw ValueError
|
||||||
|
|
||||||
|
Validate ValueError is raised
|
||||||
|
"""
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
Domain.available("invalid-string")
|
||||||
|
|
||||||
|
def test_domain_available_unsuccessful(self):
|
||||||
|
"""
|
||||||
|
Scenario: Testing behavior when registry raises a RegistryError
|
||||||
|
|
||||||
|
Validate RegistryError is raised
|
||||||
|
"""
|
||||||
|
def side_effect(_request, cleaned):
|
||||||
|
raise RegistryError(code=ErrorCode.COMMAND_SYNTAX_ERROR)
|
||||||
|
|
||||||
|
patcher = patch("registrar.models.domain.registry.send")
|
||||||
|
mocked_send = patcher.start()
|
||||||
|
mocked_send.side_effect = side_effect
|
||||||
|
|
||||||
|
with self.assertRaises(RegistryError) as err:
|
||||||
|
Domain.available("raises-error.gov")
|
||||||
|
patcher.stop()
|
||||||
|
|
||||||
|
|
||||||
class TestRegistrantContacts(MockEppLib):
|
class TestRegistrantContacts(MockEppLib):
|
||||||
"""Rule: Registrants may modify their WHOIS data"""
|
"""Rule: Registrants may modify their WHOIS data"""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue