|
30 | 30 | from warehouse.accounts import services
|
31 | 31 | from warehouse.accounts.interfaces import (
|
32 | 32 | BurnedRecoveryCode,
|
| 33 | + IDomainStatusService, |
33 | 34 | IEmailBreachedService,
|
34 | 35 | InvalidRecoveryCode,
|
35 | 36 | IPasswordBreachedService,
|
@@ -1635,3 +1636,79 @@ def test_factory(self):
|
1635 | 1636 |
|
1636 | 1637 | assert isinstance(svc, services.NullEmailBreachedService)
|
1637 | 1638 | assert svc. get_email_breach_count( "[email protected]") == 0
|
| 1639 | + |
| 1640 | + |
| 1641 | +class TestNullDomainStatusService: |
| 1642 | + def test_verify_service(self): |
| 1643 | + assert verifyClass(IDomainStatusService, services.NullDomainStatusService) |
| 1644 | + |
| 1645 | + def test_get_domain_status(self): |
| 1646 | + svc = services.NullDomainStatusService() |
| 1647 | + assert svc.get_domain_status("example.com") == ["active"] |
| 1648 | + |
| 1649 | + def test_factory(self): |
| 1650 | + context = pretend.stub() |
| 1651 | + request = pretend.stub() |
| 1652 | + svc = services.NullDomainStatusService.create_service(context, request) |
| 1653 | + |
| 1654 | + assert isinstance(svc, services.NullDomainStatusService) |
| 1655 | + assert svc.get_domain_status("example.com") == ["active"] |
| 1656 | + |
| 1657 | + |
| 1658 | +class TestDomainrDomainStatusService: |
| 1659 | + def test_verify_service(self): |
| 1660 | + assert verifyClass(IDomainStatusService, services.DomainrDomainStatusService) |
| 1661 | + |
| 1662 | + def test_successful_domain_status_check(self): |
| 1663 | + response = pretend.stub( |
| 1664 | + json=lambda: { |
| 1665 | + "status": [{"domain": "example.com", "status": "undelegated inactive"}] |
| 1666 | + }, |
| 1667 | + raise_for_status=lambda: None, |
| 1668 | + ) |
| 1669 | + session = pretend.stub(get=pretend.call_recorder(lambda *a, **kw: response)) |
| 1670 | + svc = services.DomainrDomainStatusService( |
| 1671 | + session=session, client_id="some_client_id" |
| 1672 | + ) |
| 1673 | + |
| 1674 | + assert svc.get_domain_status("example.com") == ["undelegated", "inactive"] |
| 1675 | + assert session.get.calls == [ |
| 1676 | + pretend.call( |
| 1677 | + "https://api.domainr.com/v2/status", |
| 1678 | + params={"client_id": "some_client_id", "domain": "example.com"}, |
| 1679 | + timeout=5, |
| 1680 | + ) |
| 1681 | + ] |
| 1682 | + |
| 1683 | + def test_domainr_exception_returns_empty(self): |
| 1684 | + class DomainrException(requests.HTTPError): |
| 1685 | + def __init__(self): |
| 1686 | + self.response = pretend.stub(status_code=400) |
| 1687 | + |
| 1688 | + response = pretend.stub(raise_for_status=pretend.raiser(DomainrException)) |
| 1689 | + session = pretend.stub(get=pretend.call_recorder(lambda *a, **kw: response)) |
| 1690 | + svc = services.DomainrDomainStatusService( |
| 1691 | + session=session, client_id="some_client_id" |
| 1692 | + ) |
| 1693 | + |
| 1694 | + assert svc.get_domain_status("example.com") == [] |
| 1695 | + assert session.get.calls == [ |
| 1696 | + pretend.call( |
| 1697 | + "https://api.domainr.com/v2/status", |
| 1698 | + params={"client_id": "some_client_id", "domain": "example.com"}, |
| 1699 | + timeout=5, |
| 1700 | + ) |
| 1701 | + ] |
| 1702 | + |
| 1703 | + def test_factory(self): |
| 1704 | + context = pretend.stub() |
| 1705 | + request = pretend.stub( |
| 1706 | + http=pretend.stub(), |
| 1707 | + registry=pretend.stub( |
| 1708 | + settings={"domain_status.client_id": "some_client_id"} |
| 1709 | + ), |
| 1710 | + ) |
| 1711 | + svc = services.DomainrDomainStatusService.create_service(context, request) |
| 1712 | + |
| 1713 | + assert svc._http is request.http |
| 1714 | + assert svc.client_id == "some_client_id" |
0 commit comments