1""" 2 :codeauthor: Jayesh Kariya <jayeshk@saltstack.com> 3""" 4 5import pytest 6import salt.states.ddns as ddns 7from tests.support.mock import MagicMock, patch 8 9 10@pytest.fixture 11def configure_loader_modules(): 12 return {ddns: {}} 13 14 15def test_present(): 16 """ 17 Test to ensures that the named DNS record is present with the given ttl. 18 """ 19 name = "webserver" 20 zone = "example.com" 21 ttl = "60" 22 data = "111.222.333.444" 23 24 ret = {"name": name, "result": None, "comment": "", "changes": {}} 25 26 with patch.dict(ddns.__opts__, {"test": True}): 27 comt = 'A record "{}" will be updated'.format(name) 28 ret.update({"comment": comt}) 29 assert ddns.present(name, zone, ttl, data) == ret 30 31 with patch.dict(ddns.__opts__, {"test": False}): 32 mock = MagicMock(return_value=None) 33 with patch.dict(ddns.__salt__, {"ddns.update": mock}): 34 comt = 'A record "{}" already present with ttl of {}'.format(name, ttl) 35 ret.update({"comment": comt, "result": True}) 36 assert ddns.present(name, zone, ttl, data) == ret 37 38 39def test_absent(): 40 """ 41 Test to ensures that the named DNS record is absent. 42 """ 43 name = "webserver" 44 zone = "example.com" 45 data = "111.222.333.444" 46 47 ret = {"name": name, "result": None, "comment": "", "changes": {}} 48 49 with patch.dict(ddns.__opts__, {"test": True}): 50 comt = 'None record "{}" will be deleted'.format(name) 51 ret.update({"comment": comt}) 52 assert ddns.absent(name, zone, data) == ret 53 54 with patch.dict(ddns.__opts__, {"test": False}): 55 mock = MagicMock(return_value=None) 56 with patch.dict(ddns.__salt__, {"ddns.delete": mock}): 57 comt = "No matching DNS record(s) present" 58 ret.update({"comment": comt, "result": True}) 59 assert ddns.absent(name, zone, data) == ret 60