Skip to content

Commit

Permalink
Fix tests with no host command
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreea Dima authored Aug 28, 2018
1 parent 26620cd commit d156433
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions dyndns/tests/test_dyndns.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class TestDomainDynDNS(TestCase):
def setUp(self):
self.domain = 'livius.co'
self.expected_settings = {
'domain': 'livius.co',
'provider_name': '1and1',
'url_api': 'https://api.domainconnect.1and1.com'
}
Expand All @@ -23,67 +22,59 @@ def tearDown(self):
if os.path.exists('settings.txt'):
os.remove('settings.txt')

def _setup_domain(self, domain, host, code):
def _setup_domain(self, domain, code):
with patch('builtins.input', side_effect=code):
domain_setup.main(self.domain, host)
domain_setup.main(domain)

def test_setup_one_domain(self):
host = 'host'
code = 'test-code'
self._setup_domain(self.domain, host, [code,])
self._setup_domain(self.domain, [code,])
assert (os.path.exists('settings.txt')), 'Settings file missing'

with open('settings.txt', 'r') as file:
full_name = host + "." + self.domain

context = json.load(file)
assert (full_name in context), 'Domain not found in settings'
assert (self.domain in context), 'Domain not found in settings'

config = context[full_name]
config = context[self.domain]
expected_config = self.expected_settings
expected_config['code'] = code
expected_config['host'] = host

assert (len(config.keys()) == len(expected_config.keys())), 'Config size incorrect'
for key in expected_config.keys():
assert (config[key] == expected_config[key]),\
'Key `{}` found: {} expected: {}'.format(key, config[key], expected_config[key])

def test_setup_two_domains(self):
host_1 = 'host1'
host_2 = 'host2'
domain_1 = 'host1.' + self.domain
domain_2 = 'host2.' + self.domain
code = 'test-code'
self._setup_domain(self.domain, host_1, [code,])
self._setup_domain(self.domain, host_2, [code,])
self._setup_domain(domain_1, [code,])
self._setup_domain(domain_2, [code,])
assert (os.path.exists('settings.txt')), 'Settings file missing'

with open('settings.txt', 'r') as file:
context = json.load(file)
for host in [host_1, host_2]:
full_name = host + "." + self.domain
assert (full_name in context), 'Domain not found in settings'
for domain in [domain_1, domain_2]:
assert (domain in context), 'Domain not found in settings'

config = context[full_name]
config = context[domain]
expected_config = self.expected_settings
expected_config['code'] = code
expected_config['host'] = host

assert (len(config.keys()) == len(expected_config.keys())), 'Config size incorrect'
for key in expected_config.keys():
assert (config[key] == expected_config[key]), \
'Key `{}` found: {} expected: {}'.format(key, config[key], expected_config[key])

def test_setup_max_retries(self):
host = 'host'
self._setup_domain(self.domain, host, ['', '', '', ''])
self._setup_domain(self.domain, ['', '', '', ''])
assert (not os.path.exists('settings.txt')), 'Settings file exists'

@skip
def test_update_domain(self):
host = 'host'
domain_setup.main(self.domain, host)
domain_setup.main(self.domain)
assert (os.path.exists('settings.txt')), 'Settings file missing'
result = domain_update.main(self.domain, host)
result = domain_update.main(self.domain)
assert (result == 'DNS record succesfully updated.'), result


Expand Down

0 comments on commit d156433

Please sign in to comment.