diff --git a/octodns/record.py b/octodns/record.py index 0388911..03ce675 100644 --- a/octodns/record.py +++ b/octodns/record.py @@ -424,8 +424,14 @@ class MxValue(object): @classmethod def _validate_value(cls, value): reasons = [] - if 'preference' not in value and 'priority' not in value: + try: + # seperate lines to have preference set in the ValueError case + preference = value.get('preference', None) or value['priority'] + int(preference) + except KeyError: reasons.append('missing preference') + except ValueError: + reasons.append('invalid preference "{}"'.format(preference)) exchange = None try: exchange = value.get('exchange', None) or value['value'] diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index cb87c70..0230e2c 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -898,7 +898,7 @@ class TestRecordValidation(TestCase): } }) - # missing priority + # missing preference with self.assertRaises(ValidationError) as ctx: Record.new(self.zone, '', { 'type': 'MX', @@ -909,7 +909,19 @@ class TestRecordValidation(TestCase): }) self.assertEquals(['missing preference'], ctx.exception.reasons) - # missing value + # invalid preference + with self.assertRaises(ValidationError) as ctx: + Record.new(self.zone, '', { + 'type': 'MX', + 'ttl': 600, + 'value': { + 'preference': 'nope', + 'exchange': 'foo.bar.com.' + } + }) + self.assertEquals(['invalid preference "nope"'], ctx.exception.reasons) + + # missing exchange with self.assertRaises(ValidationError) as ctx: Record.new(self.zone, '', { 'type': 'MX',