|  | 
|  | 1 | +import mock | 
| 1 | 2 | import pytest | 
| 2 | 3 | 
 | 
| 3 | 4 | from ns1 import NS1 | 
|  | 
| 18 | 19 | from ns1.rest.team import Team | 
| 19 | 20 | from ns1.rest.user import User | 
| 20 | 21 | from ns1.rest.zones import Zones | 
|  | 22 | +from ns1.zones import Zone | 
| 21 | 23 | 
 | 
| 22 | 24 | 
 | 
| 23 | 25 | @pytest.fixture | 
| @@ -67,3 +69,28 @@ def test_rest_interface(ns1_config, method, want): | 
| 67 | 69 |     client = NS1(config=ns1_config) | 
| 68 | 70 |     got = getattr(client, method)() | 
| 69 | 71 |     assert isinstance(got, want) | 
|  | 72 | + | 
|  | 73 | + | 
|  | 74 | +@mock.patch.object(Zone, "load") | 
|  | 75 | +@mock.patch.object(Zones, "list") | 
|  | 76 | +def test_listZones(zones_list, zone_load, ns1_config): | 
|  | 77 | +    zones_list.return_value = [{"zone": "a.com"}, {"zone": "b.com"}] | 
|  | 78 | +    client = NS1(config=ns1_config) | 
|  | 79 | + | 
|  | 80 | +    result = client.listZones() | 
|  | 81 | +    zones_list.assert_called_once_with() | 
|  | 82 | +    zone_load.assert_not_called() | 
|  | 83 | +    assert sorted([x.zone for x in result]) == ["a.com", "b.com"] | 
|  | 84 | + | 
|  | 85 | +    result[0].load() | 
|  | 86 | +    zone_load.assert_called_once_with() | 
|  | 87 | + | 
|  | 88 | + | 
|  | 89 | +@mock.patch.object(Zone, "load") | 
|  | 90 | +def test_loadZone(zone_load, ns1_config): | 
|  | 91 | +    zone_load.return_value = "LOADED_ZONE_OBJECT" | 
|  | 92 | +    client = NS1(config=ns1_config) | 
|  | 93 | + | 
|  | 94 | +    result = client.loadZone("a.com") | 
|  | 95 | +    zone_load.assert_called_once_with(callback=None, errback=None) | 
|  | 96 | +    assert result == "LOADED_ZONE_OBJECT" | 
0 commit comments